Token management is the practice of tracking, controlling, and optimizing the tokens that Claude Code consumes during every coding session. Because each prompt, file read, and tool call draws from a finite 200,000-token context window and a metered API budget, understanding where your tokens go is the single highest-leverage skill for keeping costs predictable. This guide walks through the /usage dashboard, context economics, real cost benchmarks, rate limits, and concrete optimization tactics.

Token management: What You’ll Learn
Effective token management means you can ship features faster without watching your bill balloon unexpectedly. You will learn how to read the /usage output, how the 200K context window fills up, what real developers actually spend, and how to cut waste with subagents, compaction, and model selection. By the end you will have a repeatable workflow for keeping every session lean.
This tutorial assumes you have already installed Claude Code and run a few sessions. If you are brand new, start with the getting-started guide, then return here to tighten your token management habits once you have a baseline to optimize.
What Is Token Management in Claude Code?
Every interaction with Claude Code costs tokens. A token is roughly four characters of English text, so a typical line of code is about 10 to 15 tokens. When you send a prompt, Claude Code assembles a payload that includes your message, the system prompt, memory files, tool definitions, and relevant file contents. The model reads that entire payload, generates a response, and often reads additional files through tool calls. Token management is the discipline of controlling the size and frequency of those payloads.
Tokens matter for two reasons. First, the context window is finite: once you exceed 200,000 tokens of accumulated conversation, Claude Code must compact or truncate older messages. Second, on usage-based billing plans, tokens translate directly into dollars. Even on subscription plans where you do not pay per token, heavy usage consumes your plan’s allowance faster and can trigger rate limits.
Good token management is not about using Claude less. It is about using it more efficiently. A well-managed session accomplishes the same work with fewer tokens by loading only relevant context, choosing the right model for each task, and delegating verbose operations to subagents that return compact summaries. The result is faster responses, fewer compaction events, and lower costs.
The /usage Command: Your Cost Dashboard
The /usage command is your primary window into token consumption. Type it at any point during a session and Claude Code prints a summary of cumulative cost, duration, and code changes. The output looks like this:
Total cost: $0.55
Total duration (API): 6m 19.7s
Total duration (wall): 6h 33m 10.2s
Total code changes: 0 lines added, 0 lines removedSeveral details deserve attention. The cost figure is a local estimate calculated from token counts multiplied by current model pricing. It is a useful relative gauge for comparing sessions, but it may differ from the amount on your actual invoice. For authoritative billing data, always check the Claude Console usage page, which reflects the final metered totals after any plan discounts or adjustments. See the official Claude Code costs documentation for the full pricing and token usage reference.
/usage Is the Current Command
You may see references to a /cost command in older documentation or community posts. /cost was an earlier command name; /usage is the current documented command for checking token spend, and the official costs documentation references it exclusively. Build the habit of typing /usage, and use that name in any scripts or internal docs you write about token management.
Subscription vs API Billing
What the cost number means depends on your plan. On a usage-based API plan, the estimate approximates real spending and you should monitor it closely. On subscription plans such as Pro, Max, Team, or Enterprise, the dollar figure is informational only. Your billing is the flat plan rate, not the per-session estimate. What matters for subscribers is the usage bar showing how much of your plan allowance you have consumed.
For subscription users, /usage displays plan usage bars, activity statistics, and a breakdown by component. You can see how much context was consumed by skills, subagents, plugins, and MCP servers. Press the d key to view the last 24 hours or w for the last 7 days. In the VS Code extension, the same breakdown appears in the Account and Usage dialog (version 2.1.174 and later).
Understanding the 200K Context Window
Claude Code operates within a 200,000-token context window. This is the total budget for everything the model can see in a single turn: system instructions, memory, conversation history, tool results, and your latest prompt. When the window fills, Claude Code must compact older conversation into a summary, which means some detail is lost. Understanding what loads into the window helps you manage it proactively rather than reacting to compaction events.
The Always-On Baseline
Before you type a single character, a baseline of tokens already occupies the context window. The system prompt consumes approximately 4,200 tokens. Environment information such as your operating system, working directory, and shell details adds another 280. MCP tool definitions, which are loaded as deferred name-only entries, contribute about 120 tokens. Skill descriptions add roughly 450 tokens, and these are not reloaded after a compaction event, so they effectively remain for the session lifetime.
Memory files are another persistent cost. Your global ~/.claude/CLAUDE.md adds about 320 tokens at session start. A project-level CLAUDE.md can add 1,800 tokens or more, which is why the best practice is to keep it under 200 lines. Auto-loaded memory from MEMORY.md contributes about 680 tokens, representing the first 200 lines or 25 kilobytes of accumulated context.
On-Demand Token Consumers
Beyond the baseline, tokens accumulate as you work. Every file Claude reads costs between 1,000 and 2,400 tokens depending on file length. Path-scoped rules trigger when a matching file is accessed, adding about 300 tokens each. Hook output from tool events contributes 100 to 120 tokens per invocation. The biggest variable cost is conversation history: every turn adds the full text of your prompt, the model’s response, and any tool results.
When you run /compact, the conversation is summarized and the summary replaces the full history. The compacted result consumes only a modest fraction of the tokens in the summarized portion, a substantial reduction in token count. This is a dramatic reduction, but it comes at the cost of detail. The art of compaction is instructing Claude on what to preserve, which we cover in the optimization section.
What Consumes Tokens During a Session
Breaking down token consumption by source reveals where optimization effort pays off. The table below shows the major consumers and when they activate. Use it as a mental model when deciding whether to read another file, load another MCP server, or start a fresh session.
| Consumer | Approximate Tokens | When It Loads |
|---|---|---|
| System prompt | ~4,200 | Always |
| Auto memory (MEMORY.md) | ~680 | Session start |
| Environment info | ~280 | Session start |
| MCP tools (deferred) | ~120 | Session start |
| Skill descriptions | ~450 | Session start |
| Global CLAUDE.md | ~320 | Session start |
| Project CLAUDE.md | ~1,800 | Session start |
| Per file read | ~1,000-2,400 | On demand |
| Path-scoped rules | ~300 each | On matching access |
| Hook output | ~100-120 | On tool events |
| /compact result | Modest fraction of summarized tokens | On compaction |
Notice that the always-on baseline is already over 7,000 tokens before you do anything. This means your effective working budget is closer to 190,000 tokens for active conversation and file reads. In practice, most sessions hit compaction between 80,000 and 150,000 tokens of conversation, because file reads and tool results accumulate quickly.
Background Token Usage
Even when you are not actively prompting, Claude Code uses small amounts of tokens for conversation summarization, which powers the --resume feature that lets you pick up a previous session. This background cost is typically under $0.04 per session, so it is negligible for most workflows. However, if you leave many sessions idle for long periods across a team, it can add up and is worth awareness for enterprise monitoring.
Real-World Cost Benchmarks
Anthropic publishes aggregate cost data that helps set realistic expectations. Understanding these benchmarks prevents sticker shock and gives you a baseline for evaluating whether your own spending is in a healthy range. The numbers below reflect official data from production usage across thousands of developers, and every dollar figure ultimately traces back to token consumption.
Per-Developer Daily and Monthly Averages
The average Claude Code user spends approximately $13 per active developer day. This is the mean across all users, including both heavy and light usage patterns. Over a typical month of active development, the average lands between $150 and $250 per developer. These figures assume usage-based API billing; subscription plan users should instead track plan allowance consumption.
Importantly, the distribution is right-skewed. Ninety percent of users spend under $30 per active day. The mean is pulled above the median by a minority of power users who run long autonomous sessions, agent teams, or heavy CI pipelines. If your daily cost is below $30, you are well within the normal range. If it consistently exceeds $50, the optimization techniques later in this guide will help you bring it down.
Agent Teams and Elevated Usage
Agent teams, where multiple Claude Code instances run concurrently in plan mode, consume significantly more tokens than standard sessions. Expect roughly seven times the token usage of a single session when teammates run in plan mode. This multiplier exists because each agent maintains its own context window, performs its own file reads, and exchanges coordination messages. Budget accordingly when deploying team configurations.
For CI and headless automation, costs depend heavily on session length and how much context each run loads. Short, focused tasks like linting a single file or running a targeted fix cost cents. Long refactoring runs that read dozens of files can cost a few dollars each. The --max-budget-usd flag, covered in the headless mode guide, lets you cap individual CI runs.
Rate Limits and Team Throughput
Rate limits govern how many tokens and requests your organization can send per minute. Unlike per-user quotas, Claude Code rate limits apply at the organization level. This is a critical distinction: adding more developers to a team does not proportionally increase your throughput if they all share the same organization. Planning rate limit allocation is essential for growing teams.
Recommended Limits by Team Size
The table below shows recommended tokens-per-minute (TPM) and requests-per-minute (RPM) allocations per user, scaled by team size. These are planning guidelines for organizations that need to ensure fair access across members.
| Team Size | TPM per User | RPM per User |
|---|---|---|
| 1-5 | 200k-300k | 5-7 |
| 5-20 | 100k-150k | 2.5-3.5 |
| 20-50 | 50k-75k | 1.25-1.75 |
| 50-100 | 25k-35k | 0.62-0.87 |
| 100-500 | 15k-20k | 0.37-0.47 |
| 500+ | 10k-15k | 0.25-0.35 |
Notice that per-user allowance decreases as teams grow. This reflects the fact that larger organizations have more aggregate demand competing for the same organizational ceiling. A 500-person team cannot give each member 200K TPM because the combined load would far exceed any plan’s limit. Plan your team structure and rate limit distribution together, not separately.
Hitting Rate Limits in Practice
When you exceed a rate limit, Claude Code pauses and retries automatically after a short backoff. You will see a brief delay rather than an error in most cases. However, sustained overages can cause longer throttling periods. The most common cause on teams is multiple developers running large refactoring sessions simultaneously. If this happens frequently, consider staggering heavy work or upgrading your plan tier.
For CI pipelines, rate limits can cause flaky failures if many jobs start at once. The fix is to serialize expensive Claude Code jobs or add jitter to their start times. Monitor your rate limit utilization in the Claude Console to catch chronic pressure before it causes production issues.
Cost Optimization Techniques That Work
Optimization is where token management delivers tangible savings. The techniques below are ordered roughly by impact, though the best combination depends on your specific workflow. Try one or two at a time, measure the effect with /usage, and keep what works.
Clear Context Between Tasks
The single highest-impact habit is running /clear when you switch tasks. A context window full of conversation about the previous task is dead weight that inflates every subsequent turn. Clearing gives you a fresh baseline with only the always-on system tokens. Pair this with specific prompts: instead of asking Claude to improve the entire codebase, point it at the exact file and line.
Compaction with Focus Instructions
When you need to preserve context but the window is getting full, use /compact with instructions about what to keep. A bare /compact lets Claude decide what matters, which may not match your priorities. A focused compaction like /compact Focus on code samples and the authentication logic tells Claude exactly what to retain in the summary and what it can safely drop.
Model Selection
Choosing the right model for each task is a high-impact lever. Claude Sonnet handles the vast majority of coding tasks effectively and costs less than Opus. Reserve Opus for genuinely complex reasoning such as architectural design, tricky debugging, or cross-file refactoring. For simple tasks like generating boilerplate or renaming symbols, even Haiku may suffice. Every model swap is ultimately a token-cost decision, since Sonnet and Haiku price per token far below Opus. You can also override the model per subagent for granular control.
Disable Unused MCP Servers
Every enabled MCP server contributes tool definitions to the context window, even if you rarely use them. Run /mcp to see which servers are active and disable any you are not using in the current session. Fewer active servers means fewer token definitions loaded on every request. This is a medium-impact optimization that compounds over long sessions, since tool definitions are sent with every request.
Lower Extended Thinking
Extended thinking mode lets Claude reason step by step before responding, which improves quality on complex tasks but consumes significant tokens. For straightforward tasks, reduce the thinking budget. Use the /effort command or set MAX_THINKING_TOKENS=8000 to cap reasoning depth. This is a medium-to-high impact optimization that many users overlook.
Preprocessing Hooks for Test Output
If your workflow involves running tests frequently, the full test output can flood the context window with thousands of tokens of stack traces and pass markers. A preprocessing hook can filter or summarize test output before Claude sees it, preserving only the relevant failures. This has high impact for test-heavy workflows where you iterate through many test cycles.
Write Specific Prompts
Vague prompts like “improve this codebase” force Claude to explore broadly, reading many files and generating verbose analysis. Specific prompts like “fix the null check in auth.ts line 42” let Claude go straight to the target. This medium-impact technique compounds across a session because every unnecessary file read is also unnecessary tokens in the context history.
Subagents and Context Delegation Economics
Subagents are one of the most powerful token management tools available. A subagent runs in its own isolated context window, performs a task, and returns only a summary to the main session. This means all the file reads, tool calls, and intermediate reasoning happen outside your main context budget. The economics are compelling.
Consider a typical scenario, a clear illustration of token delegation economics: you ask Claude to investigate how authentication works across your codebase. Without a subagent, Claude might read six files totaling 6,100 tokens, explore related modules, and build up a chain of reasoning. All of that accumulates in your context window permanently. With a subagent, the same investigation happens, but only a 420-token summary returns to the main session. That is a 14-to-1 reduction in context cost for the main thread.
{
"subagents": [
{
"name": "code-investigator",
"description": "Explores code and returns findings",
"model": "haiku",
"tools": ["read", "grep", "glob"]
}
]
}Configure subagents with the minimum tools they need. A read-only investigator does not need write access. Assigning a cheaper model like Haiku to simple investigation tasks compounds the savings: the subagent uses Haiku pricing for its work and returns a compact summary to your main Sonnet or Opus session. For a deep dive on subagent configuration and patterns, see the Claude Code Subagents Guide.
Delegate Verbose Operations
Any operation that produces verbose output is a candidate for subagent delegation. Running a large test suite, analyzing a dependency tree, or reading a massive configuration file all generate token-heavy results. Wrapping these in a subagent keeps the verbose output out of your main context entirely. The main thread only sees the distilled summary, keeping it lean for the reasoning that matters.
This pattern is especially valuable for memory and context persistence. When Claude needs to recall project history or accumulated decisions, a subagent can retrieve and summarize only the relevant portion rather than loading the entire memory file. Learn more about structuring this in the Claude Code Memory Guide.
Prompt Caching and Auto-Compaction
Two built-in mechanisms work automatically to reduce your token costs without any configuration: prompt caching and auto-compaction. Understanding how they operate helps you structure your workflow to maximize their benefit.
Prompt Caching
Prompt caching, a built-in token-saving mechanism, is enabled by default and requires no configuration. When Claude Code sends a request, any repeated portions of the context, such as the system prompt, CLAUDE.md content, and tool definitions, are served from cache rather than reprocessed. This reduces both latency and cost for repeated context patterns. The cache hit rate is highest when your context has stable prefix portions, which is the natural case for most sessions.
You do not need to do anything to benefit from prompt caching. However, being aware of it explains why the first turn of a session sometimes feels slower than subsequent turns: the cache is cold on the first request and warm thereafter. Avoid unnecessary changes to your CLAUDE.md or system configuration mid-session, as these invalidate the cache and force a cold reload.
Auto-Compaction
When the context window approaches its limit, Claude Code automatically compacts the conversation. The oldest messages are summarized into a condensed form that replaces the full history. This prevents hard failures where the context overflows, but it means some detail from early in the session is lost. Auto-compaction is a safety net, not a strategy.
For better results, trigger compaction manually with /compact before the auto-compaction threshold. This gives you control over what gets preserved through focus instructions. You can also add a “Compact instructions” section to your CLAUDE.md that tells Claude how to summarize your sessions by default. This medium-impact technique ensures consistent compaction behavior across all your sessions without manual intervention.
# In CLAUDE.md
## Compact instructions
When compacting this conversation, preserve:
- All code examples and their file locations
- Decisions made and their rationale
- Current task status and next steps
Drop:
- Exploratory file reads that did not yield results
- Verbose tool output already incorporated into decisionsSpend Limits and Budget Controls
Spend limits provide a hard ceiling on how much a session or user can consume in token terms. They are the last line of defense against runaway costs, whether from an accidental infinite loop, a misconfigured agent team, or a developer who leaves a long session running overnight. The mechanism differs by plan type.
Pro and Max Plans
On Pro and Max subscription plans, use the /usage-credits command to set a monthly spend limit. This caps how much of your plan allowance you consume. Once the limit is reached, Claude Code warns you before continuing. This is useful for staying within personal budget targets or for distributing a team’s plan allowance across members fairly.
API and Console Plans
For usage-based API billing, set workspace spend limits on the Claude Console. Navigate to your workspace settings and define a dollar ceiling. When the workspace approaches the limit, requests are throttled or blocked depending on your configuration. This protects against unexpected charges from scripts or CI pipelines that run longer than anticipated.
Cloud Provider Gateways
If you access Claude Code through a cloud provider gateway, such as the Claude apps gateway, you can set per-user spend limits at the gateway level. This is the most granular control available and is ideal for organizations that need to enforce individual budgets. Gateway limits apply before requests reach the API, so they are effective even for autonomous agents.
Enterprise Plans
Enterprise plans with usage-based billing do not have per-seat limits. Instead, the organization is billed at API rates for actual consumption. Monitoring and governance happen through the Claude Console’s organizational dashboards and through integrations with your existing cloud cost management tools. For enterprise cost monitoring strategies, see the enterprise guide.
Headless CI Budget Caps
For CI and automated pipelines, the --max-budget-usd flag sets a per-run dollar ceiling. When a headless session exceeds the cap, it stops gracefully rather than continuing to accrue cost. This is essential for automated workflows where a bug could otherwise cause unbounded spending. The headless mode guide covers this flag in detail with CI configuration examples.
A Worked Example
Let us walk through a realistic scenario that puts token management into practice. Imagine you are refactoring a payment processing module. The module spans twelve files, has extensive test coverage, and you need to update the error handling pattern across all of them. Without token management, this is exactly the kind of task that balloons context and triggers multiple compaction events.
You start by running /clear to ensure a clean baseline. Your context window begins at roughly 7,800 tokens: the system prompt, your CLAUDE.md, environment info, and loaded skills. This is your starting budget. Next, instead of asking Claude to read all twelve files at once, you dispatch a subagent to map the current error handling pattern across the codebase.
The subagent reads all twelve files, consuming about 18,000 tokens in its own isolated context. It analyzes the patterns and returns a 500-token summary identifying the three distinct error handling styles currently in use, along with the specific files and line numbers for each. Your main context only grew by 500 tokens, not 18,000. You check the result with /usage and confirm the subagent’s work cost a fraction of what a direct exploration would have.
Now you give Claude a specific, focused prompt: “Update the error handling in payment-validator.ts lines 45-80 to use the Result pattern, matching the style in transaction-handler.ts.” Claude reads just those two files, about 3,200 tokens total, and makes the change. You run the targeted test file to verify. A preprocessing hook you configured earlier filters the test output, passing only the three failing assertions to Claude rather than the full 2,000-token test report.
Claude fixes the failing tests in two more turns. You move to the next file, reusing the context already loaded about the Result pattern. After four files, you run /compact Focus on the Result pattern implementation and remaining files to update to keep the window lean. The compaction reduces your conversation from 45,000 tokens to about 8,000, preserving exactly what you need for the remaining eight files.
By the end of the session, /usage shows a total cost of $0.42. Without token management techniques, the same task would have cost an estimated $1.80 or more: the initial file exploration alone would have consumed the context budget, forcing multiple auto-compactions that lose detail and require re-reading files. The subagent delegation, focused prompts, preprocessing hooks, and strategic compaction combined to deliver a fourfold cost reduction.
Token management: Common Mistakes to Avoid
Even experienced developers fall into the same traps when managing tokens. These mistakes are easy to make because Claude Code works well enough without active management that the costs accumulate invisibly. Recognizing these patterns is the first step to avoiding them.
- Never running /clear: Carrying an entire previous task’s context into a new task means every turn pays for irrelevant history. This is the most common and most expensive mistake. Get in the habit of clearing whenever you switch focus.
- Treating the /usage estimate as your bill: The dollar figure is a local approximation from token counts, not an invoice. For actual billing, check the Claude Console. Making decisions based on the estimate alone can mislead your budgeting.
- Enabling every MCP server by default: Each enabled server adds tool definitions to every request, even when unused. Disable servers you are not actively using in the current session to reclaim context budget.
- Ignoring model selection: Defaulting to the most powerful model for every task, including trivial ones, wastes tokens and money. Match the model to the task complexity: Sonnet for most work, Opus for hard reasoning, Haiku for simple operations.


Token management: Best Practices
- Run
/clearevery time you switch tasks to shed accumulated context and start from a lean baseline of roughly 7,000 system tokens instead of carrying tens of thousands of irrelevant history. - Use
/compactwith focus instructions before auto-compaction triggers, specifying exactly what Claude should preserve in the summary so you retain control over what detail survives. - Delegate file exploration and verbose operations to subagents configured with minimal tools and cheaper models, so only compact summaries enter your main context window.
- Match the model to the task: Sonnet for everyday coding, Opus for complex architectural reasoning, and Haiku for simple lookups, renames, and boilerplate generation.
- Check
/usageperiodically throughout your session, not just at the end, so you can catch cost drift early and adjust your approach before it compounds.
Token management: Frequently Asked Questions
What is the difference between /usage and /cost?
/cost was an earlier command name; /usage is the current documented command for checking token spend. The official documentation references /usage exclusively. Use /usage in your workflow and any documentation you write about token management.
Is the dollar amount from /usage what I actually pay?
Not necessarily. The figure is a local token-cost estimate, not an invoice. It approximates real spending on API plans. On subscription plans like Pro and Max, billing is a flat rate regardless of session token usage.
How much does the average developer spend on Claude Code?
According to Anthropic data, the average is about $13 per active developer day, or $150 to $250 monthly. Ninety percent of users spend under $30 per day. Power users running agent teams push average token consumption higher.
Do rate limits apply per user or per organization?
Rate limits apply at the organization level, not per user. All developers sharing an organization draw from the same throughput pool. As teams grow, the per-user token allowance must decrease to stay within the shared ceiling.
How do I set a hard spending cap for automated CI runs?
Use the --max-budget-usd flag in headless mode to set a per-run dollar ceiling, capping token spend automatically. For subscription plans, use /usage-credits for monthly limits. For API plans, configure workspace spend limits in the Claude Console.
Token management comes down to three habits: check /usage to know where your tokens go, shed context aggressively with /clear and focused /compact, and delegate verbose work to subagents so only summaries reach your main window. Combine these with model selection and spend limits, and your sessions stay fast, affordable, and under control.