5 ways to save token costs in Claude Code
These five tips will help you get more coding done with fewer tokens.
You’ll spend less on API costs and hit usage limits less often.
1. Keep context lean and clear
The longer you chat with your AI coding agent the more context it has to keep track of.
Old messages and debugging attempts can pile up quickly. Most of that stuff becomes useless once you move on to something else.
In Claude Code you can clean things up with:
/compact
This tells Claude to summarize your conversation and keep the important details.
You can also tell it what to keep:
/compact Keep the key decisions and remaining tasksDon’t wait until your context window is almost full. Compact after fixing a tricky bug or finishing a big task.
If you’re starting something completely new use /clear instead.
2. Take advantage of multi-phase planning
You don’t need your most expensive AI model for every task.
Planning a complex feature takes a lot more brainpower than writing code from a clear set of instructions. You can save money by using different models for these tasks.
Start with a powerful model like Claude Opus to think through the problem and write a solid plan.
Then switch to a cheaper model like Sonnet or Haiku to write the code.
In Claude Code you can switch models with:
/modelYou can even do this:
/model opusplanThis uses Opus for planning and Sonnet for execution if your setup supports it.
You won’t always use fewer tokens this way. But you can spend a lot less money on them.
3. Don’t waste coding context asking questions
You can waste a lot of context by asking your coding agent questions that have nothing to do with your current task.
Say you’re building a login system and want to know how JWT works.
You ask Claude for an explanation and follow up with a few more questions. All those messages now take up space in your coding context.
Claude Code’s /btw command helps you avoid this:
/btw How does JWT authentication work?This lets you ask quick questions without adding them to your main conversation.
For longer discussions you can use:
/exportCopy your conversation and paste the relevant parts into ChatGPT or Gemini for free continue chatting there.
So you end up only using your paid coding tokens for actual coding.
Just make sure you don’t share private code or secrets.
4. Ignore files the right way
Your AI doesn’t need to read every file in your project.
Folders like node_modules/ and dist/ can eat up a huge amount of context for no good reason.
You might try creating a .claudeignore file to stop this. But Claude Code doesn’t actually support .claudeignore by default.
Instead you can block files in .claude/settings.json:
{
"permissions": {
"deny": [
"Read(.env*)",
"Read(config/secrets/**)"
]
}
}You can also tell Claude to avoid unnecessary folders in your project instructions.
For more control you can use hooks to stop Claude from reading certain files.
5. Use AGENTS.md like a pro
You waste tokens every time you repeat the same project instructions to your AI.
You might have to remind it to use pnpm instead of npm or tell it not to touch generated files. You might also need to explain where certain files live.
You can put all these instructions in AGENTS.md so your AI can find them when it needs them.
Here’s a simple example:
# Project Instructions
## Stack
- Next.js
- TypeScript
- PostgreSQL
## Commands
- Test: pnpm test
- Build: pnpm build
## Rules
- Follow existing code patterns.
- Don't edit generated files.
- Write tests for new features.Keep this file short and focused on the things your AI needs to know most often.
If you have long docs just link to them and tell your AI to read them only when it needs them.
This helps you avoid wasting tokens on information that has nothing to do with your current task.
These habits help you spend less on AI while getting more coding done.
5 ways to save token costs in Claude Code Read More »






















