by inevolin
Coming back after the Claude Code cache expires costs about 10x a new chat. 1 hour on a Pro, Max or Ultra plan, 5 minutes on an API key. Fix: /compact before a break, /clear plus 3 lines after.
# Add to your Claude Code skills
git clone https://github.com/inevolin/claude-code-usage-analysisGuides for using api integration skills like claude-code-usage-analysis.
claude-code-usage-analysis is an open-source api integration skill for AI coding assistants such as Claude Code, Codex CLI, and ChatGPT, built by inevolin. Coming back after the Claude Code cache expires costs about 10x a new chat. 1 hour on a Pro, Max or Ultra plan, 5 minutes on an API key. Fix: /compact before a break, /clear plus 3 lines after. It has 171 GitHub stars.
claude-code-usage-analysis's catalog security scan is still queued. You can run an instant dependency and prompt-injection check now with the "Scan for vulnerabilities" button above.
Clone the repository with "git clone https://github.com/inevolin/claude-code-usage-analysis" and add it to your Claude Code skills directory (see the Installation section above).
claude-code-usage-analysis is primarily written in Python. It is open-source under inevolin on GitHub, so you can review or fork the full source.
Yes. AgentsLLM lists many other API Integration skills you can browse and compare side by side. Open the API Integration category from the badge at the top of this page, or use the Related Skills and comparison links further down to weigh claude-code-usage-analysis against similar tools.
No comments yet. Be the first to share your thoughts!
Top skills in this category by stars
Unlocks once the catalog security scan passes (runs nightly).
The deep catalog scan for this skill is still queued. Run an instant dependency check now instead.
Claude rereads your whole chat on every message. To keep that cheap, it saves a short-term copy called the cache: 1 hour on a Pro, Max or Ultra plan, and 5 minutes on an API key. Every message restarts that timer.
Come back after the timer ends, and Claude has to save the whole chat again. Your next message costs about 10x a new session. That is 9.83x measured on 13 live API-key runs, and an estimated 11.0x past the 1-hour plan cache at the same 97,000-token chat size (not measured live).
| ✅ Do | ❌ Don't | Measured usage |
|---|---|---|
/compact before a break longer than your cache |
Leave, then continue later | 2.5x vs about 10x, 3 runs (details) |
Back from a break: /clear, then 3 lines: goal, done, next |
/compact after the break |
about 1x vs 9.7x, 3 runs, 2 for /compact (details) |
| Stay in one session for small related fixes in a row | /clear between them |
28% less, 1 run, small chat (details) |
Keep tool output short, or pipe logs through tail -50 |
Leave long logs in the chat | +15% to +64% over that turn and the next 5, 2 runs each (details) |
| Pick tools and model at the start | Turn off a tool or switch models mid-task | 22x a normal turn, 2 runs; model switch from docs (details) |
| Use the Claude Code CLI | Use the Desktop Code tab | Desktop at least 1.80x, T3 Code 1.19x the CLI, 1 run. We did not test the Claude chat app. (details) |
"x" means times the usage of the same task in a new session.
Copy and use these two commands:
# Before a break longer than your cache (1 hour on a plan, 5 minutes on an API key)
/compact Keep: the open issue, files touched, test command
# Already back after a break
/clear
Goal: fix the currency rounding in invoices.
Done: tests in tests/test_invoice.py reproduce it.
Next: patch money.py, run the suite.
On a Pro, Max or Ultra plan, your main cache lasts 1 hour while you stay within plan limits (5 minutes on an API key, or if you go over limits and pay with usage credits). Live tests used the 5-minute API cache (9.83x). A 1-hour cache write costs 2 times a plain input, not 1.25 times, so the adjusted calculation puts a miss past 1 hour at 11.0x on the same 97,000-token chat (not measured live). Lower CLAUDE_CODE_IDLE_COMPACT_MIN_TOKENS to 100000 and keep the window open. Letting the laptop sleep instead is estimated at +76% over a workday (estimate), not tested live. A long lunch, a meeting, or a sleeping laptop can cross that hour, and idle compact does not run if the process is not alive. Check the timer with /usage.
See how often your own cache expires. This runs on your computer, on metadata in ~/.claude/projects (timestamps and token counts). The tool never reads or uploads your chat text. You can inspect src/cc_usage_study/analyze.py first.
Option A: run the local tool yourself
CLONE=$(mktemp -d)
git clone --depth 1 https://github.com/inevolin/claude-code-usage-analysis "$CLONE"
python3 -m pip install -e "$CLONE"
OUT=$(mktemp -d)
python3 -m cc_usage_study.analyze ~/.claude/projects --summary --sessions --calls -o "$OUT/report.json"
Keep the report file outside git. The tool never copies the text of your prompts. The report lists your top habits as percentages and multipliers, how often you continued after the cache expired, and which client you used. It does not include money amounts.
Option B: install the skill, then type /claude-code-usage-check in a new Claude Code session
CLONE=$(mktemp -d)
git clone --depth 1 https://github.com/inevolin/claude-code-usage-analysis "$CLONE"
mkdir -p ~/.claude/skills
cp -R "$CLONE/skills/claude-code-usage-check" ~/.claude/skills/
Everyone uses Claude Code differently. The best settings for you depend on your own logs. Paste the text below into Claude Code to check your habits once. The prompt tells Claude to use summary numbers and timestamps, not the raw text of your chats. The only thing that leaves your machine is the normal Claude Code conversation. That conversation will include those summary numbers.
Everyone uses Claude Code differently. Recommend settings that fit MY logs, not general advice.
1. Clone https://github.com/inevolin/claude-code-usage-analysis into a temp folder, then run:
python3 -m pip install -e .
OUT=$(mktemp -d)
python3 -m cc_usage_study.analyze ~/.claude/projects --summary --sessions --calls -o "$OUT/report.json"
Keep that report file outside any git repo. Use only that file: summary numbers, timestamps, token counts, entrypoints, and compact_boundary fields. Do not read, paste, or upload the raw text of my chats. Do not report money amounts. Use % and multipliers.
2. Score my habits with my own numbers:
- Continuing a session after the cache expired: use cache_rebuilds_main.ttl_expired_rebuild (a gap over 5 minutes if cache_creation_5m_tokens are most of the writes, or over 1 hour if cache_creation_1h_tokens are).
- /compact after a break, or before: compare boundary_rows timestamps and trigger with gaps in call_rows.
- Many short sessions close together (a rough sign of /clear between related work) instead of one continued session.
- sdk-cli (claude -p) sessions continued across gaps, instead of a new session each run.
- Which app I used, from by_entrypoint: cli = Claude Code CLI, sdk-cli = claude -p, t3-code = T3 Code, claude-desktop-3p = Desktop Code tab. Prefer the CLI, or T3 Code. Desktop's Code tab used at least 1.80 times the CLI in this study. The Claude chat app was not measured.
- Sessions where one request reaches 300,000 tokens: use one call's prompt_tokens or compact pre_tokens. Do not use the session-sum of prompt_tokens.
3. Write a short report:
(a) the 3 habits costing me the most, with my % or multipliers;
(b) changes that fit my pattern, only from this list: /compact before breaks, /clear plus a 3-line reminder when I am already back, a new `claude -p` session each scheduled run, prefer the CLI or T3 Code over Desktop's Code tab. Mention `--autocompact` only as an unproven idea, and only if my sessions actually get that large;
(c) what you could not tell. If a field is missing, compute it from timestamps and compact_boundary metadata only, or say you cannot tell.
CLAUDE.md, adding an MCP server, or changing effort did not break the cache. The next turn stayed near a normal turn (0.95x to 1.08x, 3 runs each, Claude Code 2.1.325). Turning off one built-in tool broke the cache and cost 22x (2 runs). (details)--autocompact 180000 did not beat the default in a live 270,000-token session. The model estimated about 43% less. The live run tied the default (n=1, no long pauses). The long-session compact model failed live checks. (details)claude -p --resume across gaps longer than the cache is estimated at about 3x vs a new session each run (not tested live). (details)claude -p session every run and pass state in through a notes file, instead of resuming an old session.# Cron and CI: start a new session every run, and keep notes in a file
claude -p "$(cat .agent/handoff.md) Continue the nightly triage." --output-format json
Careful with CLAUDE_AUTOCOMPACT_PCT_OVERRIDE. On a 1M-context model, 25 fires at about 245,000 tokens, which is reasonable. On a 200k-context model it fires at 45,000, below what a summary leaves behind, and the session thrashes (+239% in our model). In T3 Code it stacks with "Auto-compact after", so set only one of the two. (details)
T3 Code can compact before a break for you. Its idle-thread setting has three modes: "When you return" (the default, onReturn), "Before the cache expires" (beta, `beforeCa