에이전트 운영Agent operations

claude-code-session-cost

Claude Code 프로젝트가 얼마 들었는지 세션 로그에서 추정합니다. 서브에이전트를 합치고 캐시 TTL 두 가정을 함께 보여 줍니다.

GitHub에서 보기View on GitHub

어떤 문제를 푸나The problem

비용은 대체로 컨텍스트 크기에 턴 수를 곱한 값에 가깝고 출력이 차지하는 비중은 작습니다. 정말 알고 싶은 것은 '이 프로젝트에 얼마 들었나'인데, 서브에이전트 로그는 세션 폴더 옆에 따로 쌓입니다.

키워드가 충분히 자주 나오는 세션을 찾아 메인과 서브에이전트를 나누어 합산하고, 스트리밍으로 중복 기록된 메시지는 한 번만 셉니다.

이런 분께 맞습니다Who it is for

Claude Code를 오래 돌리면서 프로젝트 단위 비용을 추정하고 싶은 사람.

무엇을 하나What it does

  • 키워드가 --min-hits회 이상 나오는 세션만 그 프로젝트의 것으로 봅니다.
  • 메시지 id로 중복을 제거하고 서브에이전트 로그를 따로 세어 합칩니다.
  • 캐시 TTL 5분과 1시간 두 가정의 가격 범위를 함께 출력합니다.
  • 단가는 가정값이며 --prices로 덮어쓸 수 있습니다. 잘못된 가격 파일은 종료 코드 2입니다.
  • 맞는 세션이 없으면 0원이 아니라 '측정 불가'(종료 코드 3)입니다.

직접 돌려 본 출력Real output

저장소의 examples 폴더를 실행한 결과입니다.

$ bash examples/demo.sh
# Cost of every session whose log mentions MYGAME (synthetic logs; your real root is ~/.claude/projects)
$ python3 scripts/session_cost.py MYGAME --root examples/fake-projects
main sessions: 1 logs, 30 calls, avg context 110k tokens
  cost $3.75 (5-min cache TTL) .. $4.88 (1-hour TTL)   [prices ASSUMED, see --prices]
  share: cache_write 50%, cache_read 40%, output 10%, input 0%
sub-agents: 1 logs, 10 calls, avg context 21k tokens
  cost $0.04 (5-min cache TTL) .. $0.05 (1-hour TTL)   [prices ASSUMED, see --prices]
  share: cache_read 47%, cache_write 29%, output 23%, input 0%

Reading it: cost ~ context size x number of turns; output is usually ~10%. Cheap = small context, not 'delegation' per se.
[exit 0]

# A keyword that matches nothing is 'unmeasured' (exit 3), not 'free'
$ python3 scripts/session_cost.py NOSUCHKEYWORD --root examples/fake-projects
UNMEASURED: no session mentions 'NOSUCHKEYWORD' >= 20 times
[exit 3]

알아둘 한계Limits

  • 로컬 로그 기반의 추정치라서 실제 청구서가 정답입니다.
  • 내장 단가는 자리표시자이며 시간이 지나면 낡습니다.

받아서 쓰기Get it

# 저장소를 받습니다
git clone https://github.com/Kein-chronicle/claude-code-session-cost.git

# Claude Code 스킬로 쓰려면 이 폴더 이름으로 받습니다
git clone https://github.com/Kein-chronicle/claude-code-session-cost.git ~/.claude/skills/claude-session-cost

정보Info

분류Category
에이전트 운영Agent operations
형태Type
명령줄 도구Command-line tool
라이선스License
MIT
필요한 것Requires
Python 3.10 이상
저장소Repository
claude-code-session-cost
토픽Topics
claude-code claude-skills agent-skills cost-tracking tokens llm-cost observability

2026-10-18 기준: 저장소의 테스트를 로컬에서 실행해 통과했고, 예제 출력은 저장소의 examples 폴더를 실제로 실행한 결과입니다.

공유하기Share

문자Message 네이버 블로그Naver Blog X Facebook