Claude Code 세션별 토큰 사용량: session-cost 스킬
Dmitriy Solodukha, Caprock 개발자 · 게시일
Claude Code와 Codex에서 테스트
Claude Code의 세션별 토큰 사용량과 그 원인을 확인합니다. session-cost 스킬은 Caprock, /usage, 로컬 로그를 읽으며 가격을 지어내지 않습니다.
현재 세션과 최근 세션의 Claude Code 토큰 사용량 및 사용량이 높았던 이유를 확인하려면 session-cost 스킬을 설치한 에이전트에 요청합니다. 수치가 있는 출처(Caprock의 cost 도구, 에이전트 자체 사용량 명령, 작은 스크립트로 읽는 로컬 세션 로그)에서 값을 읽고, 가장 큰 원인 한두 가지를 짚습니다. 달러 금액은 출처를 명시할 수 있을 때만 제공합니다.
session-cost 스킬 설치
에이전트마다 명령 하나입니다. 스킬은 SKILL.md 하나와 스크립트 scripts/session_tokens.py로 구성되며, 명령이 둘을 함께 설치합니다. 설치 시에는 아무것도 실행되지 않습니다.
스킬 아홉 가지 전체를 플러그인으로 설치합니다. Claude Code 안에서 다음을 입력합니다:
이 스킬만 설치하려면 터미널에서 프로젝트 폴더로 이동한 뒤 다음을 실행합니다:
추가 옵션: -g 모든 프로젝트에 설치하려면 앞의 옵션을 추가합니다.
터미널에서 프로젝트 폴더로 이동한 뒤 다음을 실행합니다:
추가 옵션: -g 모든 프로젝트에 설치하려면 앞의 옵션을 추가합니다.
터미널에서 프로젝트 폴더로 이동한 뒤 다음을 실행합니다:
추가 옵션: -g 모든 프로젝트에 설치하려면 앞의 옵션을 추가합니다. 아직 OpenCode에서 테스트하지 않았습니다. 이 스킬은 개방형 형식의 일반 지침이지만, OpenCode에서 실행해 검증한 적은 없습니다.
터미널에서 프로젝트 폴더로 이동한 뒤 다음을 실행합니다:
추가 옵션: -g 모든 프로젝트에 설치하려면 앞의 옵션을 추가합니다. 아직 Cursor에서 테스트하지 않았습니다. 이 스킬은 개방형 형식의 일반 지침이지만, Cursor에서 실행해 검증한 적은 없습니다.
session-cost 스킬을 사용하는 프롬프트
요청이 스킬 설명과 일치하면 에이전트가 해당 스킬을 선택합니다. 이름을 명시하면 확실하게 선택할 수 있습니다. 프롬프트를 클릭하면 복사됩니다.
session-cost 스킬이 Claude Code 토큰 사용량 확인을 위해 읽는 내용
- Caprock의
cost도구 연결 시: 저장소 하나 또는 전체를 대상으로 일별·모델별 토큰과 달러 비용을 보여 줍니다. 달러 금액은 API 정가 기준이므로, 정액 요금제에서는 실제 청구액이 아니라 같은 사용량을 API로 사용했을 때의 비용이며, 스킬에서도 이를 명시합니다. - 직접 입력하는 에이전트 자체 명령: Claude Code에서는
/usage(/cost와/stats는 별칭이며,/context는 구간을 채우는 내용을 표시), Codex에서는/status와/usage. - 로컬 로그:
scripts/session_tokens.py(Python 표준 라이브러리 사용, 오프라인)을 통해 현재 폴더의 기록을 읽습니다.~/.claude/projects/아래의 Claude Code 대화 기록(하위 에이전트 포함)과~/.codex/sessions/아래의 Codex rollout을 읽습니다. 토큰만 집계하며 비용은 계산하지 않습니다.
그런 다음 스킬은 해당 수치의 원인을 제시합니다. 호출할 때마다 큰 컨텍스트를 읽어 발생하는 캐시 읽기, 많은 호출(흔히 폴링 루프), 각자 컨텍스트를 새로 시작하는 서브에이전트, 긴 출력, 일상적인 작업에 사용한 더 비싼 모델 등이 원인일 수 있으며, 각 원인에 구체적인 다음 단계 하나를 제시합니다.
실행한 내용과 에이전트의 수행 결과
각 스킬은 2026년 11월 29일에 전용으로 만든 임시 저장소에서 프로젝트 스킬로 설치하여 실행했습니다. calc.py가 있는 임시 저장소에서 짧은 Claude Code 세션으로 함수를 하나 추가한 뒤 실행하여, 읽을 실제 사용량이 있었습니다. Codex 실행은 같은 폴더에서 짧은 Codex 세션과 Claude Code 비용 측정을 진행한 뒤에 이루어져 세션 세 개를 집계했습니다.
Claude Code (claude -p --model sonnet)
How much have my Claude Code sessions in this project cost so far? Show the token usage and what drove it.
스킬을 로드하고 Caprock의 cost와 recent_sessions를 호출한 다음 로그 스크립트를 실행했습니다. Caprock의 달러 금액을 제시했습니다(프로젝트의 세션 두 개에 대해 약 $0.17~$0.18, API 정가 기준, Caprock의 가격 버전 포함). 정액 요금제에서는 실제 청구액이 아니라고 설명하고, 캐시 읽기(토큰의 82%)를 비용의 주된 원인으로 지목했습니다. 세션별 금액 두 개의 합이 프로젝트 총액보다 크다는 점도 짚었으며, 그 이유는 찾지 못했다고 밝혔습니다.
Codex (0.163.0, codex exec)
How much have my coding-agent sessions in this project cost so far? Show the token usage and what drove it.
스킬을 읽고 Caprock의 cost와 로그 스크립트를 사용했습니다. $0.23, 338,504토큰이며 그중 캐시 읽기가 85%였습니다. 정액 요금제에 관한 동일한 주의 사항도 덧붙였습니다.
테스트한 에이전트
- Claude Code:
.claude/skills/에 프로젝트 스킬로 설치한 상태에서 2026년 11월 29일에claude -p --model sonnet으로 테스트했습니다. - Codex: 2026년 11월 29일에 Codex 0.163.0(
codex exec)로 테스트했으며, 스킬은.agents/skills/에 설치했습니다. - OpenCode와 Cursor: 테스트하지 않았습니다. 스킬은 공개 Agent Skills 형식의 일반 지침이지만, 어느 쪽에서도 실행하여 확인하지 않았습니다.
한도
- Caprock을 사용하지 않는 경로(사용량 명령을 실행한 뒤 스크립트만 사용)는 테스트에서 실제로 실행하지 않았습니다.
- 검증한 명령이 없어 OpenCode와 Cursor의 사용량 명령은 제외했습니다.
- 스크립트는 토큰을 세며, 달러 금액으로 환산하지 않습니다. 달러 금액을 계산하려면 Caprock,
/usage또는 직접 제공한 요율이 필요합니다. - 에이전트는 슬래시 명령을 직접 입력할 수 없습니다.
/usage또는/status가 필요하면 무엇을 입력해야 하는지 알려줍니다.
Caprock을 사용할 때와 사용하지 않을 때
Caprock MCP 서버가 연결되어 있으면 스킬은 cost(API 정가 기준 일별·모델별 토큰과 달러 비용)와 recent_sessions를 호출해 특정 날짜의 수치에 해당하는 세션을 식별합니다. 연결되어 있지 않으면 에이전트 자체 명령어와 로그 스크립트를 사용합니다. Caprock은 컴퓨터의 모든 코딩 에이전트 세션을 기록하는 무료 오픈 소스 앱입니다.
SKILL.md 전문
dspv/skills의 리비전 dfce799에 있는 파일 그대로입니다. 수동으로 설치하려면 프로젝트 안에 Claude Code용은 .claude/skills/session-cost/SKILL.md, Codex용은 .agents/skills/session-cost/SKILL.md로 저장합니다.
---
name: session-cost
description: >-
Tells you what the current coding-agent session, and recent ones, cost in tokens and
(when a real price source exists) dollars, and what drove it: cache reads from a large
context, many tool calls, subagents. Use when you ask "how much did this session cost",
"claude code token usage", "how many tokens have I used", "why is this session so
expensive" or "cost per session". Reads Caprock's cost tool when present, otherwise the
agent's own usage command and local session logs; never invents a price.
license: Apache-2.0
---
# Session cost
Answer "what did this cost and why" from a source that holds the numbers. Never estimate a
figure from memory, never invent a price per token.
## Pick the source, best first
1. **Caprock `cost` tool** (MCP server `caprock`). If it is in your tool list, call it:
`cost` with `days` (1 for today, default 7, at most 90), optional `repo` (a directory in
the repository) or `all_repos: true`. It returns tokens and `cost_usd` per day and per
model. Its own note says it prices at API list rates from Caprock's model table, so on a
flat plan the dollars are what the same usage would cost on the API, not what was
billed. Say that. If `recent_sessions` is also there, use it to name the sessions behind a
day. (Caprock, https://caprock.dev, is free, open source and runs locally; it is what
provides these tools.)
2. **The agent's own command.** You cannot run a slash command yourself; tell the user which
one to type:
- Claude Code: `/usage` ("Show session cost, plan usage limits, and activity stats";
`/cost` and `/stats` are aliases). `/context` shows what fills the context window.
Source: https://code.claude.com/docs/en/commands, read 2026-11-29. On Pro, Max and other
plans the docs say the session cost figure "isn't relevant for billing purposes"
(https://code.claude.com/docs/en/costs).
- Codex: `/status` ("Display session configuration and token usage") and `/usage` ("View
account token usage"). Source: https://learn.chatgpt.com/docs/developer-commands, read
2026-11-29.
- Other agents: only a command you found in their docs or `--help`. If none, skip.
3. **Local session logs**, read with the script beside this file (offline, standard library,
prices nothing):
```bash
python3 <this skill's folder>/scripts/session_tokens.py # 5 newest, this dir
python3 <this skill's folder>/scripts/session_tokens.py --session ID # one, with drivers
python3 <this skill's folder>/scripts/session_tokens.py --json --last 10
```
It reads Claude Code transcripts (`~/.claude/projects/<cwd as slug>/*.jsonl`, subagents
under `<session>/subagents/`) and Codex rollouts (`~/.codex/sessions/**/rollout-*.jsonl`)
whose working directory is `--cwd` (default: the current one). If the logs are missing
or unreadable, say so; do not guess. The current session is usually the newest row; in
Claude Code its id is also the transcript file name.
Use the first source that works. Use a second one only to cross-check or to explain.
## Dollars: only from a named source
- Caprock `cost` and Claude Code `/usage` give dollars: quote them with their source.
- From the log script you get tokens only. Turn them into dollars only with rates the user
gives you or a provider pricing page already read in this session; then name the page or
the user's rates and the date, and price each kind separately (input, cache write, cache
read, output differ). Otherwise answer in tokens and say why there is no dollar figure.
- Do not fetch a pricing page unless the user asks you to go online.
## What drove it
Read the numbers, then name the one or two biggest causes, with the figure behind each:
- **Cache reads dominate** (usual for long Claude Code sessions): every call re-reads the
whole context, so cost grows with context size times number of calls. Signs: cache read
far above everything else, large calls near the context limit. Remedy: compact or start a
fresh session with a handoff note.
- **Many calls**: a high `api calls` count with a long tool-call list (often a shell loop or
polling). Remedy: batch commands, stop polling.
- **Subagents**: the subagent line of the script, or a model split in Caprock `cost`. Each
subagent starts its own context. Remedy: fewer, narrower subagents.
- **Output** heavy: long generated files or reasoning. Usually the smallest share.
- **Model mix**: a costlier model on routine work (`by_model` in Caprock, `models` in the
script).
Note the counting difference: in Codex logs `input_tokens` include cached tokens (the script
splits them out); in Claude Code logs they do not.
## Output
```
Session <id or "current"> (<agent>, <model>), <start> to <end>
Tokens: <total> (input <n>, cache write <n>, cache read <n>, output <n>; subagents <n>)
Cost: $<x> from <source, date> | Cost: tokens only (<why no price>)
Recent: <one line per session or day: date, tokens, $ if sourced>
Drivers: 1. <cause, with its number> 2. <cause>
Next: <one concrete step, or "nothing to change">
```
Stop when every figure has a source. If no source works, say which ones you tried and what
the user can run (`/usage`, `/status`) to see it.
session-cost 스킬 관련 질문
- Claude Code의 특정 세션 토큰 사용량은 어떻게 확인하나요?
- Claude Code에서 `/usage`를 입력하거나(`/cost`는 별칭), session-cost 스킬이 있는 에이전트에 요청합니다. 이 스킬은 Caprock이나 로컬 대화 기록을 읽고 합계를 입력, 캐시 쓰기, 캐시 읽기, 출력으로 나눕니다.
- Claude Code 토큰 사용량이 왜 이렇게 높은가요?
- 긴 세션에서는 보통 캐시 읽기가 주요 비용 요인입니다. 호출할 때마다 전체 컨텍스트를 다시 읽으므로, 컨텍스트 크기와 호출 횟수의 곱에 따라 비용이 늘어납니다. 스킬은 그 비중을 보여 주고, 압축하거나 핸드오프 후 새 세션을 시작하도록 제안합니다.
- session cost 스킬은 실제 청구액을 보여 주나요?
- 정액 요금제에서는 그렇지 않습니다. Caprock과 Claude Code의 세션 수치는 API 정가로 사용량을 계산합니다. Pro나 Max에서는 같은 사용량을 API로 사용했을 때의 비용에 해당합니다. 스킬이 어떤 경우인지 설명합니다.
- 로그를 다른 곳으로 보내나요?
- 아니요. 스크립트는 Python 표준 라이브러리로 로컬 파일을 읽으며 네트워크 호출을 하지 않습니다. 스킬도 요청하지 않으면 가격 페이지를 가져오지 않습니다.