Claude Code: understanding and mastering your tokens
Clarification on how text is split into tokens: Claude generally counts more tokens than OpenAI for the same text (about 1.5× in English), and Anthropic changed tokenizer with Opus 4.7. The "1.3 tokens per word" rule of thumb therefore applies to OpenAI, not to Claude. Sources added at the end of the article.
A lot has changed since the first version of this article: context windows have grown to 1M tokens, caching has become far more important, token usage has been optimized, and several tools I used to recommend no longer belong here. This version has been rewritten accordingly.
Under the hood of Claude Code
What's a token?
A token is the unit LLMs use to read and generate text. It isn't specific to Claude Code: GPT and the others use it too.
When you write text, or have Claude read text or code, it splits the input into tokens. OpenAI lets you see how your prompts get split into tokens with their tokenizer.
=>, !=, ::) each get their own token where natural text would compress them. The result: for the same number of characters, a code file consistently consumes more tokens than a sentence of prose. And the gap with OpenAI is even sharper on code: an analysis of a TypeScript file finds between 1.5× and 1.7× more tokens with Claude depending on the language.
Input / output tokens
Claude and the other LLMs split tokens into 2 categories:
- Input tokens: the tokens used to read your prompt or the code being analyzed, for example
- Output tokens: the tokens used to generate the response (the code, for example)
These 2 categories usually have different prices: input tokens cost less than output tokens per million tokens. On current models the ratio is about 1:5: Sonnet 5.5 is billed $2 per million input tokens and $10 per million output tokens, Opus 5.5 $4 and $20. An output token therefore costs five times more than an input token. That's because producing text or code takes far more resources than reading it. These prices are the API prices, which is what sits behind subscription quotas. And there is a mechanism that completely changes the game on the input side: the cache. We'll get to it in a moment.
Context window
We've seen what tokens are and what they're for. Now let's look at how Claude and the other LLMs handle their "memory", and their memory is the context window. The context window is the set of tokens Claude can keep in memory during a session. In Claude Code, Sonnet 5.5 and Opus 5.5 have a 1M-token window on paid plans (if you go through a gateway with a custom ANTHROPIC_BASE_URL, Claude Code can't verify the 1M and falls back to 200K). This limit covers both input AND output tokens. And 1M Claude tokens hold less text than 1M tokens on a model with a more compact tokenizer: compare windows in volume of text, not in tokens.
And this window fills up faster than you'd think: the more Claude has to read your codebase and use tools, and the longer you stay in the same session, the more your context grows. All the more so because on every turn, Claude sends back the whole previous context.
For example, you write a 200-token prompt, Claude uses 2,000 tokens to answer (tool use + response generation), and your context now holds 2,200 tokens. You're not satisfied, so you write a new 800-token prompt → Claude sends back the previous 2,200 plus the tokens for the new answer, and so on.
A big window is not a useful window
With 1M tokens, you might think the problem is solved. Not really. The size of the window tells you how far Claude can go, not how far it stays good. In the community, people talk about the smart zone and the dumb zone: at the start of a session, the agent is precise and remembers what you said. As the context grows, it becomes more approximate, forgets instructions, and makes mistakes it wasn't making at the beginning. The expression "dumb zone" is attributed to Dex Horthy (HumanLayer) and was popularized notably by Matt Pocock. Same model, same tool, just more context. From what point, you'll ask? It depends on the model and the task, and no fixed value exists. The orders of magnitude you come across range from about 100,000 to 150,000 tokens. Take it as an estimate, not an official threshold: a slope rather than a cliff. Above all, remember this: you can be deep in the dumb zone with most of the window still free. The window limit only tells you where the machine refuses to go on, not where it works well. Once the window is full, Claude Code doesn't silently drop the oldest tokens: it compacts the conversation, meaning it replaces the history with a summary. And that summary has its flaws. A context window is limited to the current session. As soon as you quit Claude and relaunch it, the context window goes back to zero and Claude remembers nothing. There are two partial exceptions, and in both cases it isn't memory in the strict sense, just persistent context loaded from the very first prompt:
- your
CLAUDE.mdfiles (and other memory files), which you write yourself; - the auto memory (
MEMORY.md), notes Claude writes itself over your sessions, enabled by default in recent versions. I come back to it below.
The cache: why re-reading 200,000 tokens doesn't cost 200,000 tokens
If Claude sends back the whole history on every turn, your bill (and your quota) should explode with each message. It explodes much less, thanks to prompt caching. It's THE mechanism to understand if you want to understand your quotas.
The principle: a prefix
On every message, Claude Code makes a new request to the API. The model remembers nothing between two requests, so Claude Code sends everything again: system prompt, project context, all the previous messages and tool results, and your new message. But since new content is always added at the end, the beginning of each request is identical to the previous one. The API recognizes this beginning (the prefix), reads it back from its cache, and only bills full price for what's new. The match is exact: if anything changes in the prefix, everything after it is recomputed. There is no per-file or per-chunk cache. Claude Code therefore organizes each request from the most stable to the most changing:
| Layer | Content | Changes when |
|---|---|---|
| System prompt | Base instructions, tool definitions | The set of loaded tools changes |
| Project context | CLAUDE.md, auto memory | At session start, or after /clear or /compact |
| Conversation | Your messages, the responses, tool results | On every turn |
| A change in the conversation leaves the first two layers cached. A change in the system prompt invalidates everything. | ||
So what does that change?
On the API price grid, reading a cached prefix costs a fraction of the input price, while writing to the cache costs a bit more than sending the text normally:
| Per million tokens | Sonnet 5.5 | Opus 5.5 | Fable / Mythos |
|---|---|---|---|
| Input | $2 | $4 | $10 |
| Cache read | $0.10 (0.05×) | $0.20 (0.05×) | $0.25 (0.025×) |
| Write, 5-min cache (1.25×) | $2.50 | $5 | $12.50 |
| Write, 1-hour cache (2×) | $4 | $8 | $20 |
| Output | $10 | $20 | $50 |
| (Prices from the official page at the time of writing; Fable and Mythos: prices of the 5.1 generation.) | |||
| In other words, re-reading cached context is 20 times cheaper than sending it normally on Sonnet 5.5 and Opus 5.5, and up to 40 times on Fable and Mythos (the "standard" case is 10×). | |||
| A concrete example on Sonnet 5.5, with a 20,000-token context and a new 500-token message: | |||
- without cache: 20,500 tokens at $2 per million, so about 4.1 cents;
- with cache: 20,000 tokens re-read at $0.10 + 500 tokens at $2, so about 0.3 cent.
That turn is about 14 times cheaper. And it repeats on every turn of a session.
Don't jump to conclusions. These ratios come from the API price grid. I couldn't find an official document explaining how cache reads count toward subscription quotas. So I'm not promising you "20 times less quota": only that understanding the cache is the key to not breaking it for nothing (by switching models mid-task, for example).
The lifetime of the cache
A cache doesn't last forever. It expires after a period of inactivity, and every read resets the counter, at no extra cost: as long as you keep working, it stays warm. The API offers two lifetimes, 5 minutes or 1 hour (the second costs more to write, hence the 1.25× and the 2× in the table). Claude Code chooses the lifetime request by request:
| Request | Subscription (within plan quota) | API key, credits, cloud provider |
|---|---|---|
| Main conversation | 1 hour | 5 minutes |
| Sub-agents, compaction, etc. | 5 minutes | 5 minutes |
| One small detail: once your plan quota is exceeded and you start dipping into your usage credits, the main conversation drops back to 5 minutes. | ||
If you're on an API key and often step away, you can force 1 hour with the promptCacheTtl setting in settings.json (or the CLAUDE_CODE_PROMPT_CACHE_TTL environment variable), and subagentPromptCacheTtl for sub-agents. You need a recent enough version of Claude Code (v2.1.242 or later). | ||
| What happens after a pause longer than the lifetime? All your context is re-read without cache, and rewritten into the cache at the write price. The heavier your context, the more expensive and the slower this resumption is. A light context makes resuming cheap. | ||
Don't break your cache
Many harmless-looking actions invalidate the prefix and make you pay for a "cold" turn (slower and more expensive) before the new prefix gets cached.
| Breaks the cache | Doesn't break the cache |
|---|---|
Switching models with /model | Editing files in your repo |
opusplan: every plan-mode toggle | Changing the permission mode |
| Changing the effort (except on Opus 5.5, Sonnet 5.5 and Fable 5.1 with an API key or subscription) | Changing the output style |
| Enabling fast mode (the first time) | Invoking a skill or a command |
| Plugging in or removing an MCP server if tool search is disabled | /recap |
| Enabling or disabling a plugin that provides an MCP | /rewind |
| Denying a whole tool (if tool search is disabled) | Launching a sub-agent |
/compact (by construction: it replaces the history) | Editing CLAUDE.md mid-session (but see below) |
| Accumulating lots of images | |
| Updating Claude Code | |
| A few details worth knowing: | |
CLAUDE.mdmodified mid-session: it doesn't break the cache, but it doesn't apply either. The file is read at startup, and the new version is only loaded at the next/clear,/compactor restart./rewindrather than/compactto abandon a lead:/rewindgoes back to a point in the conversation whose prefix is already cached./compact, on the other hand, rebuilds a new cache.- Sub-agents have their own system prompt and their own tools: their first call doesn't read the parent's cache, they warm up a cache of their own (5 minutes by default, even on a subscription).
- Scope: the cache is tied to a machine and a directory. Two parallel sessions in the same directory share the same prefix.
Measuring your cache
Type /usage: after the first response, you'll find a Prompt cache (main) line with the session's hit rate, the number of misses, and whether the cache is warm right now. It even gives the likely cause of the last miss when it can be identified (for example "tool definitions changed"). A statusline script can read the same figures (cache_read_input_tokens and cache_creation_input_tokens). Lots of reads for few creations: the cache is doing its job. High creations turn after turn: something is moving in your prefix.
Five practical rules
- Choose model and effort at the start of the session, and keep
/compactfor the natural boundaries between two tasks. - Avoid
/modelmid-task. To adjust reasoning, change the effort instead: on Sonnet 5.5 and Opus 5.5, it keeps the cache. - Don't plug in an MCP or an MCP plugin mid-task (especially if tool search is disabled).
- To abandon a lead,
/rewindrather than/compact. - Before a long break,
/clearif the task is done: resuming will be light. Conversely, a/compactright after a long break is the worst case, because it has to re-read the whole context without cache to produce its summary.
What Claude silently injects
We've covered tokens, the context window, the cache. We saw that the context window can grow very fast depending on the size of the prompt, the codebase, etc. But behind your prompt, Claude uses a whole bunch of tokens without showing you. And you can see those tokens with the /context command. Give it a try: type the command in a fresh Claude session. Here's mine:
- Your
CLAUDE.mdand other memory files (plus the auto memory) - The tool definitions: about forty native tools, plus those of your MCPs
- Plugins
- The custom agents defined in your project
- The name and description of your skills
- Claude Code's own system prompt
Good news for MCPs: with tool search, enabled by default on the models that support it, Claude Code no longer loads all the MCP tool schemas at startup. It only loads the names, and fetches the full definition on demand. A recently published measurement shows a first call going from 27,184 to 9,722 tokens with 5 servers and 65 MCP tools (−64%). Be careful: if tool search is disabled (custom gateway, some cloud providers), you fall back to the old behavior and each MCP server adds its definitions to every session.
These silent injections benefit greatly from the cache: they aren't recomputed on every prompt. But they take up room in your smart zone, and no cache changes that.
Since every prompt sends back the previous context, your first prompt will already consume at least 18k tokens (in my example). Then, with each request, Claude will inject the files it needs on top, consume extra tokens if it has to load other tools, use MCPs, run commands, etc.
What you'll also see in /context is an Autocompact buffer line: a space Claude Code sets aside exclusively for the compaction process. It isn't usable for your work. On my setup it weighed about 33K tokens. Since it's a fixed amount, it represented 16% of a 200K window, but only about 3% of a 1M window.
To limit the damage, Claude has a tool.
Autocompact
Claude Code doesn't wait until it hits the limit to act. When the context approaches a threshold, it automatically triggers compaction: it compresses the context and generates a summary of the session, more compact, that uses fewer tokens. And it's this summary that will be sent on each prompt instead of the entire previous context. This threshold is no longer a fixed percentage: it depends on the model and the window size. On a 1M window, it triggers by default around 967K tokens, according to published observations. You can move it:
- the
/autocompact 300kcommand - the
autoCompactWindowsetting insettings.json(from 100,000 to 1,000,000) - the
CLAUDE_CODE_AUTO_COMPACT_WINDOWenvironment variable, which takes precedence over the rest
That does reduce the tokens sent each time, but it remains a summary generated by Claude, with the problems that implies: not everything is in it, and that's where Claude starts going off in all directions. It may forget it has already handled certain things, ask again a question you already answered, contradict itself, adopt a different coding style mid-phase, etc.
For me, automatic compaction is an alarm signal: if it triggers, it means I waited too long to decide for myself what to keep. I lose two things: the thread of the session, and control over the intent of the summary, because Claude alone decides what matters.
There's also a /compact command you can trigger manually to do this compaction. And in recent versions, an idleCompaction setting lets Claude Code compact a conversation left idle just before a 1-hour cache expires (you can set it to false to disable it).
And to deal with this growth problem, Claude has another tool.
Sub-agents
Rather than gorging on context, Claude can use sub-agents. These are sub-sessions specialized in a task, with their own context. When you ask for a feature, Claude will typically be able to create various specialized sub-agents, each using the tools it needs, rather than doing everything in the main session:
⏺ 6 Agents finished (ctrl+o to expand)
├─ Explore backend codebase · 23 tool uses · 104.5k tokens
│ ⎿ Done
├─ Explore frontend codebase · 28 tool uses · 108.0k tokens
│ ⎿ Done
├─ Write backend part · 4 tool uses · 20.0k tokens
│ ⎿ Done
├─ Write frontend part · 1 tool uses · 18.6k tokens
│ ⎿ Done
├─ Write unit tests · 7 tool uses · 64.0k tokens
│ ⎿ Done
└─ Write documentation · 24 tool uses · 52.7k tokens
⎿ Done
The advantage is that no matter how many tokens each sub-agent consumes, your main session only receives a summary. If your agents each consume 150K tokens, they won't fill up the context of your main session and will only send back a summary of a few tokens. That way you protect your smart zone. And Ctrl+O lets you see what each sub-agent consumed.
The downside... is that it can blow through your quota fast. Each sub-agent has its own system prompt and its own tools, so it doesn't benefit from the main session's cache: it builds its own (with a 5-minute lifetime by default) and consumes tokens on its own account. A small test to try: ask the same code-exploration question with and without sub-agents, then compare /context in the main session.
Saving your tokens
We've seen how easy it is to blow up your token consumption, and with it your quota. Even if this is less of a concern on MAX plans, not everyone can afford those plans, so you need to be careful with your tokens.
CLAUDE.md: push or point
CLAUDE.md is the file that gives Claude the information it needs to generate code the way you want it: your project's architecture, your git naming/branching strategy, how to write and run tests, etc. Well maintained, it will save you a lot of input tokens (Claude will have less need to "guess" what it should do by analyzing your codebase) and output tokens (since it's guided by CLAUDE.md, there will be fewer back-and-forths).
But beware: everything in your CLAUDE.md is pushed on every request. Every token in it will be injected and re-read at the start of each session. A 5,000-token CLAUDE.md means 5,000 input tokens consumed before you've even written a prompt. AND that's multiplied by the number of sessions in your day. Above all, it's attention: Claude doesn't know when a given rule applies, it has them all in front of it permanently. The longer the file, the less each rule weighs.
(A small note: if you use an AGENTS.md file, Claude Code reads it when there's no CLAUDE.md. Everything that follows applies to both.)
The rule I follow: point by default. Rather than writing out all the detail, you put in one line that says where to look:
- scripts/seed.ts : definition of the initial data. Any schema change must also be reflected there.
A navigation pointer like this is almost free: the detail is only read when it's useful, and it spares Claude a file-by-file exploration. The @file we'll discuss further down does the same thing, but for a single turn. A skill is a packaged pointer: only its name and description are always loaded, the rest is only read when it's needed.
Careful, pointers age silently: move a file, and the pointer lies. Check them after every change to your structure.
To keep a CLAUDE.md short, I ask myself three questions about each line:
- Single source: does this information live elsewhere? Information lives in one place, no duplicates.
- Sediments: was this line once true, but no longer is?
- No-op: does this instruction have any effect? If I remove it and nothing changes, it goes.
A line that fails any of the three tests is deleted, or placed behind a pointer.
And auto memory?
Claude Code can also write its own notes (MEMORY.md), loaded at startup along with your CLAUDE.md. It's enabled by default. My opinion, against the grain of the default: I disable it, with /memory or autoMemoryEnabled: false in settings.json. My arguments:
- it lives outside the repo, on your machine: nothing in git, nothing reviewed, nothing shared with the team;
- it accumulates sediments that nobody systematically re-reads: a note that has become false stays false until someone corrects it;
- Claude decides what to remember, per user: memory differs from one developer to another, whereas with information that lives in the project, it's unique.
My principle: my codebase is my memory system. The counter-argument: when working solo, a memory that spares you from re-explaining your preferences from one session to the next can be very useful. It's up to you to judge.
Managing the size of your sessions
Claude systematically sends back the previous context on every turn. Rather than waiting for autocompact to decide for you, you make the decision yourself, at the end of each phase. Here are the options, in the order I consider them:
| # | Option | When to choose it |
|---|---|---|
| 1 | Continue | There's still smart zone left |
| 2 | Clear (/clear) | The context is disposable |
| 3 | Hand off | Another agent, another repo, a colleague, or a side task |
| 4 | Sub-agent | A task that can be done without you (an automated review, for example) |
| 5 | Compact (/compact) | By default, only if none of the other four fits |
| A bit more detail on each: | ||
/clearresets the context to zero. Claude remembers nothing. Use it when you switch feature, or when what's in the context is no longer useful.- Hand off: ask the agent to write a handoff document (what was done, what remains, the decisions and their reasons) in a temporary file, run
/clear, then give that file to the new agent with@. Also handy for passing work to a colleague or another tool. /compactcompresses the history into a summary. The thread of the session is kept, Claude knows what was done, but with loss. You can pass it an instruction to guide the summary:/compact retain the architecture decisions. That intent phrase steers the summary, but it remains a secondary source: the code is the primary source./rewindgoes back in the conversation. Perfect for abandoning a bad lead, and as we've seen, it preserves the cache where/compactrebuilds it.
Order matters: compacting is a last resort, not a reflex. On the same large context, continuing keeps everything but leaves you in the dumb zone; clearing brings you back to almost zero but loses all the "why"; compacting leaves a summary of intermediate size, with loss.
To keep track of all this, type /usage: it shows your session's consumption, and the cache line we discussed above. Handy for seeing in real time how much a slightly too chatty session has cost you.
Guiding Claude
Claude Code doesn't read your whole codebase on every request. It uses search tools to find the files it needs. Those tool calls are what consume tokens: locating a file, reading its content, looking for another one... On a big codebase, this exploration can represent several thousand tokens, sometimes just to find one file.
With @path/to/file, you skip this exploration: Claude receives the files directly without having to look for them. For a feature or a bugfix, identify up front the files to modify and the ones that will serve as a reference.
Excluding what's useless: permissions.deny
My old version of this article advised you to create a .claudeignore file, like a .gitignore. Don't do it: Claude Code doesn't support this file. It's ignored without a single error message. (A January 2026 article from The Register even showed Claude reading a .env despite an entry in .claudeignore.)
The right way is permissions.deny in .claude/settings.json (shared with the team) or .claude/settings.local.json (personal). For example, it's generally a good idea to exclude node_modules from your front-end projects, .nuxt, or vendor and var from your Symfony projects:
{
"permissions": {
"deny": [
"Read(./node_modules/**)",
"Read(./.nuxt/**)",
"Read(./var/**)",
"Read(./.env)"
]
}
}
Two clarifications. First, don't take it as an absolute security guarantee: cases where a deny rule wasn't honored have been reported in the past, so for real secrets, don't rely on it alone. For our topic (saving tokens, avoiding pointless exploration), it's more than enough. Second, a deny rule on a whole tool name (for example NotebookEdit) removes the tool from the system prompt altogether, whereas a targeted rule like Read(./x) changes nothing in the prompt.
Plan your developments
Planning is very useful for your big features. Have Claude analyze the code before developing, plan the development steps, leave no room for doubt. The goal is to clearly detail the path to build the feature: what absolutely must be done, what must not be done, the important files to read, etc. A plan will often break down as follows:
- Discovery phase
- The important files Claude needs to know about
- The anti-patterns
- The external APIs to use
- Phases 1 to X
- Development split into phases (phase 1 back end, 2 front end, 3 tests) with the implementation details for each
And conveniently, Claude Code has a native tool for this: plan mode, enabled with the /plan command (or Shift+Tab twice). It's a read-only mode where Claude can read your files, analyze your codebase, and ask questions, but it can neither modify files nor run commands. It produces a plan that you review, refine, then approve. Only after your approval does it exit plan mode and execute.
Even if generating a big plan may seem counter-intuitive, the token savings are real: a failed implementation costs the tokens of the initial exploration, those of the incorrect implementation, those to detect the error, and those to fix it. Plan mode lets you anticipate all that.
Mixing models
It's tempting to let the best model do everything. You pick Opus, and do everything with it. In my opinion, that's unnecessary in the vast majority of cases, and above all it consumes enormously.
A logic you can adopt: Opus to plan, Sonnet to execute. You let the most advanced model plan the task, and Sonnet will be more than enough to execute the plan.
The price difference is significant: Sonnet 5.5 costs half as much as Opus 5.5, for both input and output ($2 / $10 versus $4 / $20 per million tokens). And since the majority of tokens in a development session are consumed during execution, the gain is substantial compared to a full session on Opus.
Claude Code integrates this pattern natively with the /model command and the opusplan option:
/model opusplan
With this option enabled, Claude Code automatically routes planning tasks to Opus and execution tasks to Sonnet within the same session. You don't have to switch models manually or manage two separate contexts. In practice, that gives:
- You describe your feature → Opus analyzes, reasons, produces the plan
- You approve the plan → Sonnet takes over for the implementation
But with the cache in mind, there's a downside: every plan-mode toggle is a model switch, hence a cold cache each time. A session that enters and exits plan mode several times pays the price of uncached context several times. If your context is light, no big deal. If it's heavy, you may be better off staying on a single model and adjusting the effort: on Sonnet 5.5 and Opus 5.5, changing the effort mid-session keeps the cache. A plan costs a few hundred tokens. An incorrect 400-line diff that you cancel and regenerate costs thousands, twice, plus the turns spent explaining what was wrong. And remember that you can go a long way with a single model: Sonnet 5.5 at medium effort is enough for many tasks.
Stop chatting
It's not the craziest trick for saving tokens, but stop talking to Claude Code as if it were your colleague! Be less verbose in your prompts. I still see a lot of colleagues write their prompt like they'd write a bug ticket.
Clean up before you start
We've seen that Claude consumes tokens before your very first prompt. So clean up, and measure. The principle: run /context in a fresh session and note the total; lighten what's loaded at startup; relaunch, compare.
Among the levers:
- disable what you never use, for example workflows (
disableWorkflows) or the skills shipped by default (disableBundledSkills) in~/.claude/settings.json(test on your side, some settings are documented later than others); - deny the tools you don't want used with
permissions.denyon the tool name, which removes it from the system prompt; - keep only the MCPs and plugins you really need.
The goal isn't only a lower bill: it's a bigger smart zone, because fewer useless tools take up the beginning of the context.
A few handy tools
You can't optimize what you don't measure. Before installing anything, start with what Claude Code already provides:
/context: what fills your window, right now;/usage: the session's consumption, and the cache line;- the statusline: a script can continuously display the context used and the cache figures.
On the API side, Anthropic's count_tokens endpoint lets you count before sending, using the tokenizer of the model you choose (the result remains an estimate). In any case, don't size a Claude budget with OpenAI's tokenizer.
Then, if you want to see your trends across several days and several projects:
CodeBurn, the precise breakdown of your spending
/usage gives you the current session, but nothing about your trends over the week or the month. CodeBurn lets you see precisely where your tokens go, down to the task level.
It reads the session transcripts stored locally in ~/.claude/projects/ and classifies each exchange by activity type based on tool-usage patterns: coding, debugging, exploration, brainstorming, and above all conversation, the exchanges where Claude answers without using any tool. That's where the surprise comes in: for the tool's creator, who was spending $200/day on Claude Code with no visibility, more than half the budget went to pure conversation, not code generation.
npx codeburn
RTK (Rust Token Killer)
RTK tackles the problem at a spot nobody had addressed: the command outputs Claude injects into the context.
The idea is simple: most CLI outputs sent to the LLM are noise: passing tests, verbose logs, progress bars, etc. RTK is a CLI proxy that filters and compresses these outputs before they reach the context window.
The figures published by the author are quite impressive: cargo test goes from 155 lines to 3 lines (98% reduction), git status from 119 to 28 characters (76%). With heavy usage it pays off very quickly.
git status becomes rtk git status). Claude never sees the rewrite, it simply receives a compact output. It supports more than 100 commands: git, pytest, cargo, docker, kubectl, eslint, tsc…
Three important clarifications:
- The hook only applies to Bash calls. Claude Code's native tools (Read, Grep, Glob) don't go through it: the gain concerns command outputs, not your whole context.
- The percentages are reliable, but the absolute token numbers are estimates (RTK doesn't include a tokenizer, it counts roughly one token per 4 bytes).
- Watch out for the name: another project, "Rust Type Kit", also uses the name
rtkon crates.io. Ifrtk gaindoesn't display any savings statistics, you installed the wrong package.
brew install rtk # or: curl -fsSL https://raw.githubusercontent.com/rtk-ai/rtk/master/install.sh | sh
rtk init -g # installs the Claude Code hook
rtk gain # shows the tokens saved
RTK also offers integrations for other tools (Cursor, GitHub Copilot, Cline, OpenCode...), which is consistent with the philosophy of this article: the principles apply to all LLM-based tools.
To wrap up
There you have it: you now know more about how Claude works, what tokens are, how the cache works, where they go, and how to save them well. If I had to keep only three things: a big window is not a useful window, the cache is fragile and we break it more often than we think, and every end of phase is a decision (continue, clear, hand off, delegate, compact) rather than a reflex. Of course, if you're on MAX plans, token consumption probably isn't your priority; and even then, with the new models, even MAX plans are starting to show their limits. But on lower plans, you now have a few tools to get more out of your quota. Feel free to check the sources in the appendix to go further. Claude Code is much more complex when you really want to dig into the details!
Updated November 24, 2026
I help teams with this kind of split — short audits or longer engagements.
Let’s talk