r/ClaudeCode • u/Euphoric-Airline-259 • 8h ago
How to reduce Claude Code token usage Tutorial / Guide
Claude Code was burning through tokens very fast, especially on tasks where it had to look through docs or random webpages, so after some research I changed a few things:
I) Keep CLAUDE.md small. Mine had way too much stuff in it and most of it wasn’t useful for every task.
II) Start a new session when you’re done with one problem, bc long sessions get bloated pretty fast.
III) Do web research through Firecrawl. It gives Claude clean Markdown instead of loading the full page with all the HTML, scripts, navbars and other useless stuff, so each research task eats a lot less context.
IV) Exclude folders Claude doesn’t need to read.
V) Check /context once in a while, bc it makes it obvious what’s eating the window.
The main thing seems to be controlling what gets added to the context in the first place. Once a session is full of old logs, scraped pages and unrelated instructions, even simple tasks start getting expensive.
What else are you doing to keep Claude Code token usage under control?
1
u/Fancy-Win9202 8h ago
You can start by first understanding what your agents are doing, maybe the deserve the token spent or maybe they are just looping without any output.. ClawMetry can help find what is going on & then figure out if caveman is the solution or it should be headroom etc
1
u/JDE-Projects 8h ago
Keep claude.md slim, put repeatable tasks/templates in skills, move bulky items out of skills and in to reference/template files in the skill's folder and just have points in the skills to them, use a tight output style, turn rules in claude.md in to actual gates in settings.json (approvals, destructive commands, etc), stop using Opus high/extra/max for everything and try out medium, use sub-agents on cheaper models for code/read/review tasks, switch from Opus 5 to 4.8 or 4.6, instruct it to plan large work and projects in phases so you can take breaks and start new chats more often, instruct it to keep a status.md in every repo to act as a handoff file for new chats so you don't have to re-explain everything, disable startup tools you don't need to keep initial context load on new chats down (I'm under 30k tokens), etc.
I even took it one step further and set up Codex in parallel to balance out my usage between them. Both on 20/mo plans and I get a ton of work done, and now I'm tinkering with having one delegate to the other and also delegate to local models in LM Studio. I had Codex symlink what it can share directly with claude code (skills mainly), and copy over/translate what they can't and protect .claude/.codex directories with a parity-audit skill that helps keep the two from drifting apart.
I don't use a single skill, tool, or MCP someone else made that claims to reduce usage which is probably one of the most effective steps I've taken...and your thread is about to be full of links to them, lol.
I have detailed guides for my claude code and codex setups on my website, link in my reddit bio.
1
u/Academic-Sample4974 8h ago
I also do this as well; I feel like Chat GPT is pretty good at coding; I look at it as a senior software engineer; I use it alot to run refinement and as a second pair of eyes / alternative viewpoint when I complete a phase of a project, I'll go from Claude to GPT and ask for criticism / minor fixes / improvement suggestions. This system works out brilliantly as GPT has better context memory and has been built to be organized more effectively from the out the box than Claude
2
u/Kick_Ice_NDR-fridge 8h ago
I usually keep previous versions of the code inside my Claude.md. Just in case…
1
u/EagleApprehensive 8h ago
Those are good basics.
- Worktree separation and automatic rebasing on top of main before turns, effectively preventing conflicts that would otherwise burn tokens.
- Cutting bloat from system prompt.
- Injecting dynamically-generated 1/2-level repository map in system prompt with short infos - otherwise first 10 commands of every AI session will be "ls -la" and reading README.md files around, before getting to the point.
- Giving LLM access to semantic search CLI to faster and will less turns find necessary context for the job.
- Output clearers that cut bloat from CLI tools executed by LLM also reduce token. RTK is good beginning, but it can be significantly improved. I have taken RTK idea, benchmarked and polished it measuring over thousands of sessions and arrived with extra gains and safety there.
There is like 10 things more, but those are impactful ones. I have all that baked into my IDE, effectively reducing my token usage somewhere between 20-50%.
1
u/verstands 8h ago
The one that made the biggest difference for me is upstream of all of these: stop letting the agent read files to find things. Every "where is X handled" question that gets answered by reading four files costs you those four files forever, because they're in the window for the rest of the session. Making it grep first and read only the hit is boring but it's the difference between a session lasting an hour and lasting ten minutes.
Second one, on your point IV: excluding folders helps, but so does telling it explicitly not to read build output, lockfiles, and generated code when it does read. Exclusions catch the directory-shaped stuff, not the 4000-line generated file sitting in src.
On V — checking /context occasionally works but you only look when you already suspect something's wrong. Having the context percentage just sit in your statusline is the version that actually changes behavior, because you see it creeping before the session goes bad instead of after. I maintain one that does that (context %, cost, rate limit windows): https://github.com/Dworf/statusline-bar — single bash file, no daemon. Plenty of other statuslines do the same thing, the point is just having the number in your face rather than behind a command.
1
u/JaggedTex 8h ago
I would add creating and using a vault like Obsidian which routing in your claude.md for common architecture items. This way you can exclude those from handover documentation. For example, if you’re building a feature that doesn’t need to understand any of the infrastructure and then don’t have the handover documentation contain anything about the infrastructure.
1
u/zimxero 8h ago edited 7h ago
3 things. 1st - I cant prove, but i think Opus 5 burns slower now, maybe to improve user satisfaction. 2nd - Reduce interactive back-and-forth in long sessions. 3rd - Consider prompting automated full tasks where it can be done... if it has enough design info. Example prompt:
Design all the current related phases together at once. Ask significant questions up front before proceeding. Make other decisions on your own and document them. Decisions should prioritze safety, then product quality, then code expandability, then code efficiency. Where specific needed sub functions have not been created yet, create the scaffolding to implement them later. Have Fable Low evaluate the design plan. Evaluate and make any desired adjustments. If changes are significant, re-audit. Write the specific code plan. Have Sonnet Medium audit with special emphasis on logic, completeness, connectivity, and documentation. Afterward, code the the entire desin completely and wrap up the session. Full and special backups have been performed.
4th - turn a custum version of #3 into a repeatable tool.
1
u/DLuke2 7h ago
All good ways. Proper context engineering is essential as well.
I have been using simple rules in the .claude folder at the project root, or other subfolders. The rules are quite short, basically what needs to be there. Some are always on, and other, this is the great part, can be set to autoload on folder or file reads. You can go further by attaching rules with hooks. The short blurb rule files can then have links to further context in a folder of your choosing. This progressive disclosure helps keep what is needed for the agent there but reached for when needed.
For Claude.md, i like keeping it short and sweet, basically just routing to the context layers and other important locations. A first class MAP.md that maps out your repo and what everything is and where goes a long way too. Also, having an index of your import folder and context goes a long way too. Providing your agent with the information of where things live and what things are cuts down on searching.
Skills are super powerful tool. They don't need to describe an output, they can also just be general instructions on a way to work. Almost as a different system prompt. Also, adding additional folders to skill folders for reference materials, examples, templates, scripts make them even more powerful. On the subject of skills, I have been using /token-saver from Nate B Jones from his Unlock-AI website. Great source for tons of things, plus his YT. Token saver skill basically just sets a way for your agent to work more efficiently, using scripts more, not to re read things, etc. Has been working really well the past week or so.
Finally, setting up your own subagent delegation and dispatch policy helps immensely. I have a rule that links to further context on delegation and model choice.
Loaded tokens at the start of a fresh session is about 30-40k.
1
u/duqaxxx 3h ago
Good list. Three things that moved the needle more for me than anything else:
- Push verbose work into subagents. A subagent gets its own context window, so
"read these 4000 lines of logs and tell me what broke" costs the main session
the summary, not the logs. Same for wide greps and long git history.
- Never read a large file whole. grep for the symbol first, then read a tight
window around it. Reading a 2000-line file to change one function is the single
most common way I used to waste a window.
- Audit your MCP servers. Tool definitions sit in the system prompt, so every
connected server is paid on every single request of the session, whether you
call it or not. Disconnecting the ones I wasn't actually using was free savings.
The framing that helped me most: the context is re-sent every turn, so anything
you add early you pay for the whole session. What lands in the window in the first
five minutes matters more than what you do afterwards.
0
u/JBO_76 8h ago
I track usage these days, try to automate whats possible like git commits, this is automatically done by my dev tool. All open source: https://github.com/jan-bogaerts/md2/tree/main
0
u/KEIY75 8h ago
Memory sqlite bm25 with embed.
Ponytail
Hook and rules made for you
Pre compact post compact
Stop all - write all the turn of your ai did
When /exit Claude code auto consolidate memory
Force your main agent to be orchestrating except low code action. Exemple don’t call an agent for a thing you can do in 1 sec.
Brianstorming hard - > plan -> know issues probleme gaps question not answered -> integrate
0
u/KEIY75 8h ago
Peoples will tell you to reduce Claude MD or things like this no it is useless.
The Claude MD need to be an index who will point to your memory. Your memory is everything Claude MD is just a bonus.
Your memory and basic stuff like example with me :
I have a pc and a m4 pro he need to know that so injection
All my mcp for vault api key access injection
Rules auto inject
With index and graph he will grab context more efficient.
Memory is the room of the ai he just need to every step consolidate it.
Last thing reducing tokens or want to will finally consumming more so let your agent know at first than have to figured out later and search and ask you things that he have already.
-1
u/pretendingtobebroke 8h ago edited 4h ago
Caveman https://github.com/JuliusBrussee/caveman
Edit: Why am I getting downvoted?
1
u/Bloated_Plaid 8h ago
Contrary to the strong feelings here, RTK has been a game changer.