How to Stop Burning Through Claude Code Tokens: The Context Management Guide for Beginners
Token costs in Claude Code balloon exponentially — every new message re-sends your full history. Here's how to use /compact, /clear
Your Claude Code Bill Is Exponential, Not Linear
Most people assume token costs scale with message length. They don’t. Every new message you send in Claude Code re-sends your entire conversation history as input tokens. That 200-message session you’ve been running for two hours? Message 201 costs as much in input tokens as messages 1 through 200 combined. This is why your credits seem fine for the first hour and then evaporate in the last fifteen minutes.
You can fix most of this in under ten minutes with three slash commands and one configuration file. Here’s how.
Why This Hurts More Than You Think
A token is roughly three-quarters of a word. The phrase “Build me a landing page for a wedding DJ” costs 10 tokens. That sounds trivial.
The problem isn’t the individual message. It’s the accumulation. Every time Claude Code generates a response, it processes the full conversation as input — every message you sent, every response it gave, every file it read. The input token count grows quadratically with conversation length.
- ✕a coding agent
- ✕no-code
- ✕vibe coding
- ✕a faster Cursor
The one that tells the coding agents what to build.
There’s a second problem that’s less obvious: Claude Code’s context quality starts degrading at around 50% full, not at 100%. Most users assume they have a clean signal until the context window hits its limit and auto-compacts. They don’t. By the time you’re halfway through your context window, you’re already getting worse results and spending more per response than you were at the start of the session. The /context slash command will show you exactly where you are — type it anytime and Claude reports the percentage of the context window currently consumed.
This is the core tension: longer sessions feel productive because you’ve built up shared context with the model, but they’re actively working against you past the halfway point.
What You Need Before Starting
You need Claude Code installed as an extension inside VS Code, Cursor, or Anti-gravity (the free Google IDE available at anti-gravity.google). If you’re not sure which to use, Anti-gravity is the easiest starting point — it’s free and the Claude Code extension installs from the left-hand sidebar plugin search.
You need a Claude account with an active session. The token limits discussed here apply to session limits, weekly limits, and model-specific limits — all of which Claude Code tracks separately.
You should know which model you’re running. Inside Claude Code, type / to access the model switcher. The default is Opus 4.7, which is the most capable but burns through your limits fastest. Haiku is cheap and fast. Sonnet sits in the middle. The strategies below apply regardless of model, but they matter more when you’re running Opus.
No programming experience required. Every technique here is a slash command or a markdown file.
Step 1: Check Your Context Before You’re in Trouble
Open any active Claude Code conversation and type /context.
Claude will return the current percentage of your context window that’s been consumed. This is your baseline. Check it after every major task — not just when things feel slow.
The number to watch is 50%. Once you cross it, you’re in the degradation zone. You’re paying more per response and getting less reliable output. Most users never check this and wonder why their long sessions produce worse results than their short ones.
Now you have a real-time gauge for your session health.
Step 2: Use /compact Before You Hit 50%, Not After
The instinct is to wait until Claude auto-compacts the conversation at 100%. Don’t. By then you’ve already wasted significant tokens on degraded responses, and the automatic compaction happens without your input on what matters most.
Type /compact manually when your context hits around 40–50%. Claude will summarize the entire conversation into a compressed representation, resetting the context window while preserving the essential state of what you’ve been building.
The manual version gives you one advantage the automatic version doesn’t: you can add a note to the compaction prompt. Something like /compact focus on the database schema decisions and the API endpoint structure we agreed on will bias the summary toward what actually matters for your next set of tasks. The default compaction summarizes everything equally; your version preserves the decisions that are hard to reconstruct.
After compaction, run /context again. You should see the percentage drop significantly. You’re now working with a clean signal again.
Now you have a repeatable intervention point instead of hoping the auto-compaction catches everything important.
Step 3: Use /clear for Hard Resets Between Distinct Tasks
/compact preserves conversation state. /clear throws it away entirely.
Remy doesn't build the plumbing. It inherits it.
Other agents wire up auth, databases, models, and integrations from scratch every time you ask them to build something.
Remy ships with all of it from MindStudio — so every cycle goes into the app you actually want.
That sounds destructive, but it’s the right call when you’re switching between genuinely unrelated tasks. If you just finished building a landing page and now you want to write a LinkedIn post, there’s no reason to carry the landing page context forward. It’s dead weight — tokens you’ll pay for on every subsequent message without getting any value from them.
Type /clear to reset the conversation completely. Claude starts fresh with no memory of the prior session (unless you have persistent memory configured, which we’ll cover in a moment).
The discipline here is recognizing when you’re actually switching tasks versus continuing one. A good heuristic: if you’d open a new document in Google Docs for this work, you should /clear in Claude Code.
Now you have a way to eliminate token debt between unrelated work sessions.
Step 4: Use Plan Mode for Large Projects
This one prevents the problem rather than fixing it after the fact.
When you’re starting a large project — a multi-page website, a complex automation, anything that will require many back-and-forth messages — switch to Plan mode before you write a single line of code. In Claude Code, this is the permission mode where the model thinks and plans first, you approve the plan, and then it executes.
Why does this save tokens? Because without a plan, you’ll spend the first 20–30 messages of a session doing implicit planning through trial and error. Each wrong turn costs tokens. Each correction costs tokens. Each “actually, let me reconsider the architecture” costs tokens — and by that point, all those exploratory messages are baked into your context window and will be re-sent with every subsequent message.
Plan mode front-loads the thinking. You get a structured plan, you approve it, and then execution is more linear. Fewer wrong turns means a shorter conversation means lower total token cost for the same output.
For smaller, well-defined tasks, Plan mode adds overhead. For anything that would take more than 30 messages to complete, it almost always saves tokens overall.
Now you have a way to reduce total session length for complex work.
Step 5: Use a claude.md File to Avoid Repeating Context
Every time you start a new conversation, you’re starting from zero — unless you’ve configured persistent context.
The claude.md file is an instruction document that Claude reads at the start of every session. Think of it as the briefing document you’d give a new contractor: who you are, what you’re building, how you like to work, what rules apply. Without it, you spend the first several messages of every session re-establishing context that Claude should already know. Those messages cost tokens.
A good claude.md for token efficiency includes:
- Your project’s current state (what’s built, what’s in progress)
- Architectural decisions that are locked in (don’t relitigate these)
- Your preferences for how Claude should behave (e.g., “before creating a file, check if it already exists”)
- Any rules that prevent expensive mistakes (e.g., “don’t publish anything without my explicit approval”)
The claude.md file loads into every conversation automatically. You pay for it once per session as a fixed cost, but you avoid paying for the equivalent re-establishment messages across every session indefinitely.
Now you have persistent context that doesn’t require manual re-entry.
Step 6: Add a Post-Compaction Hook to Preserve Critical Context
One coffee. One working app.
You bring the idea. Remy manages the project.
This is the most underutilized technique in this entire guide. Even among people actively using Claude Code in production, hooks are rarely configured — which is a shame because they’re straightforward and reliable.
A hook is an automated action that fires at one of 18+ lifecycle events in Claude Code. The one that matters most for token management is the post-compaction hook.
When /compact runs — either manually or automatically — it summarizes your conversation. But summaries lose detail. If your business context, your project constraints, or your architectural decisions were established early in the conversation, they may get compressed into vague summaries or dropped entirely.
A post-compaction hook re-injects that core context immediately after compaction completes. You configure it once, and every time your conversation compacts, Claude automatically receives a fresh injection of the information you can’t afford to lose.
To create one, open Claude Code and ask: “Please create a post-compaction hook that injects my core business context after every compaction.” Then describe what that context is. Claude will build the hook for you — you don’t need to write any code.
The result is a session that recovers cleanly from compaction instead of gradually losing track of who you are and what you’re building.
Now you have a self-healing context management system.
What Goes Wrong (and How to Fix It)
You compacted too late and the summary is useless. If you waited until 90%+ to run /compact, the summary may be too compressed to be useful. The fix is /clear and a fresh start, with your claude.md providing the baseline context. This is why 40–50% is the right intervention point.
Your context percentage isn’t dropping after /compact. This sometimes happens if the conversation contains very large files that were read into context. The compaction summarizes messages but doesn’t necessarily remove large file contents. The fix is to be more selective about which files you reference — use the @ symbol to reference specific files rather than asking Claude to read entire directories.
You’re burning tokens on model selection. If you’re running Opus 4.7 for tasks that don’t require it, you’re paying a premium for no reason. Haiku handles straightforward tasks — formatting, simple edits, answering questions about existing code — at a fraction of the cost. Switch models with the / command and pick the right tool for the task. The Claude Code effort levels guide covers this in more detail.
Your claude.md is too long. A claude.md that’s 5,000 words loads 5,000 words of tokens into every single session. Keep it focused on what Claude actually needs to know to work effectively, not everything you could possibly tell it. If you find yourself adding to it constantly, that’s a sign you need to restructure your project files instead.
Day one: idea. Day one: app.
Not a sprint plan. Not a quarterly OKR. A finished product by end of day.
You’re losing context between agent handoffs. If you’re using agent teams — where a manager agent delegates to parallel worker agents — each worker starts with its own context. The orchestrator pattern helps here: load one agent with the full roles and responsibilities of all sub-agents so it can coordinate without cold-start mismatches. This is a more advanced configuration, but the 18 Claude Code token management hacks post covers the agent coordination angle in depth.
The Bigger Picture: Data Quality Matters as Much as Context Management
There’s a failure mode that slash commands can’t fix: bloated context caused by poorly structured data.
If you’re asking Claude to analyze six months of sales data and it has to pull raw JSON from an API, process it, and then analyze it — most of your context window gets consumed by the retrieval and processing step. By the time Claude gets to the actual analysis you wanted, you’re in the degraded zone where quality drops and costs spike.
The fix is pre-aggregation. Create summary tables of your key metrics outside of Claude Code, using deterministic Python scripts rather than AI inference. When Claude reads a clean summary table instead of raw API output, it spends its context window on synthesis rather than data wrangling. This is the same principle as the claude.md file: pay a fixed cost once to avoid a variable cost on every query.
If you’re building agents that need to query business data regularly, platforms like MindStudio handle this orchestration differently — 200+ models, 1,000+ integrations, and a visual builder for chaining agents and workflows, which means you can pre-process data in a pipeline before it ever reaches the model’s context window.
For teams building production applications from this kind of structured data, Remy takes a different approach entirely: you write your application as an annotated markdown spec, and it compiles into a complete TypeScript backend, SQLite database, auth, and deployment. The spec is the source of truth; the generated code is derived output. It’s a different abstraction level than Claude Code, but the underlying principle — give the model precise, structured input rather than raw noise — is the same.
Where to Take This Further
The techniques above handle the most common token waste patterns. For more advanced optimization, the /compact command deep-dive covers the mechanics of what gets preserved and what gets lost during compaction, including how to write compaction prompts that bias the summary toward your most important decisions.
If you’re hitting session limits regularly despite good context hygiene, the Opus Plan Mode guide covers a specific pattern: use Opus for planning (where its reasoning quality matters) and switch to Sonnet for execution (where you need throughput). It’s a meaningful cost reduction for complex projects without sacrificing the quality of the architectural decisions.
And if you want a systematic audit of your entire Claude Code setup — what data you have, what’s missing, what you could automate — the Silver Platter skill described in Mark Kashef’s work is worth running. It audits your existing claude.md, skills, and rules in 10–50 seconds, then generates an HTML data map with a 30-day plan. It’s available as a slash command and requires no manual configuration. The hidden Claude Code features post covers several other underutilized capabilities in a similar vein.
The core insight is simple: token costs are exponential, not linear, and the degradation starts at 50%, not 100%. Everything else follows from that.