Cut Your Claude Code Bill
Run Claude Code through GreenTokens, point each model slot at the right Claude model, cap spending with a dedicated key, and keep sessions lean.
What you'll need
- Claude Code installed and working.
- A GreenTokens account with some balance. Sign in and top up from the Billing page.
What you'll end up with
Claude Code running on discounted Claude models, with a daily spending cap and a clear view of what each session costs.
Claude Code is often a developer's biggest AI bill. Every step of an agentic session reads files, runs tools and resends a growing context, and it's easy to leave a heavy model working on light tasks. This guide lowers the cost in three ways: a lower price per token, the right model for each job, and hard limits so a long session can't surprise you.
1. Create a dedicated key with a daily limit
On the API Keys page of your dashboard, create a key just for Claude Code and name it, for example, "claude-code laptop". Then set a daily spend limit that fits how you work; $10 a day is a sensible starting point for one developer.
Why a separate key
With its own key, Claude Code's usage shows up separately in the Requests log, and its limit can't be used up by your other apps, or theirs by it. When the limit is reached, requests with that key stop until the next day instead of running on.
2. Connect Claude Code to GreenTokens
Claude Code reads its connection settings from environment variables. Put them in its settings file so they apply to every session:
{
"env": {
"ANTHROPIC_BASE_URL": "https://api.greentokens.io",
"ANTHROPIC_AUTH_TOKEN": "sk-gt-…"
}
}Use the base URL exactly as shown, without /v1. Start Claude Code and send a short message; it should appear in your dashboard's Requests log within seconds. The Claude Code docs page has the same setup as shell variables.
3. Map each model slot to the right model
Claude Code uses three model slots: Opus and Sonnet for your conversation, and Haiku for small background tasks. Mapping them explicitly controls which model, and which price, each one uses:
{
"env": {
"ANTHROPIC_BASE_URL": "https://api.greentokens.io",
"ANTHROPIC_AUTH_TOKEN": "sk-gt-…",
"ANTHROPIC_DEFAULT_OPUS_MODEL": "claude-opus-5-5",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "claude-sonnet-5",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "claude-haiku-4-5"
}
}| Slot | Model | GreenTokens price in / out per 1M | List price |
|---|---|---|---|
| Opus | claude-opus-5-5 | $2 / $10 | $4 / $20 |
| Sonnet | claude-sonnet-5 | $1 / $5 | $2 / $10 |
| Haiku | claude-haiku-4-5 | $0.50 / $2.50 | $1 / $5 |
The Haiku slot handles frequent small jobs, so keeping it on the cheapest model saves money on every session without affecting your main conversation. Prices for every model are on the models page.
4. Pick the model per task
Switch models inside a session with /model. A simple habit makes a large difference:
- Use Sonnet for everyday work: edits, tests, refactors, explanations. It costs half of Opus per token.
- Switch to Opus for the hard problems: tricky debugging, large design decisions. Switch back when they're done.
- Don't leave Opus selected for a whole day of routine changes.
5. Keep the context lean
Every step resends the session's context, so a bloated context costs you on every turn. Two built-in commands help:
- /clear starts fresh. Use it when you move to an unrelated task, instead of carrying the old conversation along.
- /compact summarises the conversation so far into a shorter form. Use it when a long task is still in progress but the history has grown.
Also avoid asking Claude Code to read large generated files, lockfiles or build output unless the task needs them. Everything it reads becomes part of the context. What a context window is explains why this adds up.
Caching is already working for you
Claude Code marks its stable context for prompt caching, and GreenTokens bills cache reads at the cached rate: $0.10 per million tokens on Claude Sonnet 5, a tenth of its input price. Lean sessions and caching together keep long sessions affordable.
6. Check what it costs
After a day of normal use, open the Requests page and filter by your Claude Code key. You'll see every call with its model, tokens and cost, and the totals for the period.
- If most spend is on Opus, check whether those tasks needed it.
- If you hit the daily limit on normal days, raise it to match your real usage.
- If you never get near it, lower it: a tight limit is a better safety net.
Next steps
- Building your own agent too? Add prompt caching to it.
- Use the same key setup in other tools: Codex CLI, opencode and more in the docs.
More guides
- Add Prompt Caching to Your AppRestructure your prompts so the repeated part is cached, turn caching on for Claude, confirm it's working, and measure what it saves.
- Switch to GreenTokens in 5 MinutesMove an app that uses the OpenAI or Anthropic SDK onto GreenTokens by changing the base URL and key, then test it and roll it out safely.