Claude Code token usage per session: the session-cost skill
Dmitriy Solodukha, Caprock's developer · Published
Tested on Claude Code and Codex
See Claude Code token usage per session and what drove it. The session-cost skill reads Caprock, /usage or local logs, and never invents a price.
To see Claude Code token usage for this session and the recent ones, and why it was high, ask the agent with the session-cost skill installed. It reads the numbers from a source that holds them (Caprock's cost tool, the agent's own usage command, or the local session logs through a small script), names the one or two biggest causes, and gives dollars only from a named source.
Install the session-cost skill
One command per agent. The skill is a single SKILL.md plus the script scripts/session_tokens.py, which the commands install with it; nothing runs on install.
All nine skills as a plugin. Type these inside Claude Code:
Or this skill alone, from your project's folder in a terminal:
Add -g to install it for every project.
From your project's folder, in a terminal:
Add -g to install it for every project.
From your project's folder, in a terminal:
Add -g to install it for every project. Not tested on OpenCode yet: the skill is plain instructions in the open format, but no run on OpenCode has checked it.
From your project's folder, in a terminal:
Add -g to install it for every project. Not tested on Cursor yet: the skill is plain instructions in the open format, but no run on Cursor has checked it.
Prompts that use the session-cost skill
The agent picks the skill when your words match its description; naming it makes sure. Click a prompt to copy it.
What the session-cost skill reads for Claude Code token usage
- Caprock's
costtool, when connected: tokens and dollars per day and per model, for one repository or all. Its dollars are API list prices, so on a flat plan they are what the same usage would cost on the API, not what you were billed; the skill says so. - The agent's own command, which you type:
/usagein Claude Code (/costand/statsare aliases,/contextshows what fills the window),/statusand/usagein Codex. - The local logs, through
scripts/session_tokens.py(standard-library Python, offline): Claude Code transcripts under~/.claude/projects/, subagents included, and Codex rollouts under~/.codex/sessions/, for the current folder. Tokens only; it prices nothing.
Then the skill names what drove the figure: cache reads from a large context read on every call, many calls (often a polling loop), subagents each starting their own context, long output, or a costlier model on routine work, each with one concrete next step.
What we ran, and what the agents did
Each skill was run on 2026-11-29 in a throwaway repository made for it, with the skill installed as a project skill. A throwaway repository with calc.py, after one short Claude Code session that added a function to it, so there was real usage to read. The Codex run came later, after a short Codex session in the same folder and the Claude Code cost run, so it counted three sessions.
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.
Loaded the skill, called Caprock's cost and recent_sessions, then ran the log script. It gave the dollar figure from Caprock (about $0.17 to $0.18 for the project's two sessions, at API list prices, with Caprock's pricing version), said that on a flat plan this is not what was billed, and named cache reads (82% of the tokens) as the driver. It also pointed out that the two per-session figures added up to more than the project total and said it had not found why.
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.
Read the skill, used Caprock's cost and the log script: $0.23 and 338,504 tokens, cache reads 85% of them, with the same flat-plan caveat.
Agents it was tested on
- Claude Code: tested on 2026-11-29 with
claude -p --model sonnet, the skill installed as a project skill in.claude/skills/. - Codex: tested on 2026-11-29 with Codex 0.163.0 (
codex exec), the skill in.agents/skills/. - OpenCode and Cursor: not tested. The skill is plain instructions in the open Agent Skills format, but no run on either has checked it.
Limits
- The path without Caprock (the usage command, then the script alone) was not run live in the tests.
- Usage commands for OpenCode and Cursor are left out: none was verified.
- The script counts tokens; it never turns them into dollars. Dollars need Caprock,
/usage, or rates you give. - An agent cannot type a slash command itself: for
/usageor/status, it tells you which one to type.
With Caprock, and without it
When the Caprock MCP server is connected, the skill calls cost (tokens and dollars per day and model, at API list prices) and recent_sessions to name the sessions behind a day. Without it, it falls back to the agent's own command and the log script. Caprock is the free, open-source app that records every coding-agent session on your computer.
The full SKILL.md
The file as it is in dspv/skills at revision dfce799. To install it by hand, save it as .claude/skills/session-cost/SKILL.md for Claude Code or .agents/skills/session-cost/SKILL.md for Codex, in your project.
---
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.
Questions about the session-cost skill
- How do I check Claude Code token usage for one session?
- Type `/usage` in Claude Code (`/cost` is an alias), or ask an agent with the session-cost skill, which reads Caprock or the local transcripts and breaks the total into input, cache write, cache read and output.
- Why is my Claude Code token usage so high?
- In long sessions it is usually cache reads: every call re-reads the whole context, so cost grows with context size times the number of calls. The skill shows the share and suggests compacting or a fresh session with a handoff.
- Does the session cost skill show what I was billed?
- Not on a flat plan. Caprock and the session figure in Claude Code price usage at API list rates; on Pro or Max that is what the same usage would cost on the API. The skill says which it is.
- Does it send my logs anywhere?
- No. The script reads local files with the Python standard library and makes no network call, and the skill does not fetch a pricing page unless you ask.