# How to lower a Claude Code or Codex API bill

> Source: https://minniai.com/learn/lower-claude-code-codex-api-bill (canonical HTML page)

[Guides](https://minniai.com/learn)


On an API key you pay per token, and a coding agent sends the whole session again with every request. So the bill follows the size of the context more than the number of questions you ask. To lower it, keep sessions short, load less memory on every turn, match the model to the job, and measure the same task before and after each change.

Updated 2026-11-16

## What you are billed for

A request is made of four kinds of token. **Fresh input** is text the model has not seen in this session. A **cache write** stores the start of the request so the next one can reuse it. A **cache read** is that reused part, billed at a small fraction of the input price. **Output** is what the model writes back, its thinking included, and it costs the most per token.

In an agent session the cache lines carry most of the volume, because the same session is read back on every turn. That is why two people asking the same question can pay very different amounts: one asks it in a fresh session, the other at the end of a long one.

## Where a high bill usually comes from

[Anthropic’s cost docs](https://code.claude.com/docs/en/costs) name the two usual causes of unexpectedly high spend on an API plan: long sessions that were never cleared, and the largest model left as the default. The rest of the list is the same in any coding agent:

- **Memory files that grew.** CLAUDE.md and AGENTS.md are sent with every request, whether the task needs them or not.
- **Long tool output.** A full log read into context is paid for again on every later turn.
- **Cache misses.** The first message after a long break processes the whole context again at the write price.
- **Parallel agents.** Subagents and agent teams each send their own requests.
- **Unused MCP servers.** Each one adds to what the model carries.

## The levers, in each tool

| Lever | Claude Code | Codex |
| --- | --- | --- |
| Start fresh between tasks | `/clear`; `/rename` first to come back with `/resume` | Start a new session |
| Shrink the history | `/compact` with what to keep | A short handoff note into a new session |
| Use a smaller model | `/model` | Pick the model per task; avoid the fast modes for routine work |
| Lower reasoning effort | `/effort` | Lower the reasoning effort |
| Shorten memory | CLAUDE.md under 200 lines; workflows into skills | A shorter AGENTS.md, nested per folder |
| Drop unused servers | `/mcp`, and `/context` to see what fills the window | Disable the MCP servers you do not use |
| See the numbers | `/usage` | `/status` |

Asking for shorter answers helps in both.

For a team on the Claude API, the Claude Console has workspace spend limits and per-member cost reporting, so one runaway session does not become a surprise at the end of the month.

## A measured before and after

Memory is the lever that pays on every turn, so it is the one we measured. We asked the same 30 questions in Claude Code 2.1.325 on Claude Sonnet 5.5, three full sessions a side: once with a test memory in the layout Claude Code itself writes, as it was, and once after MinniMemoryMCP 1.6.0 sorted it, with its server and hook on.

| Token kind | Before | After | Change |
| --- | --- | --- | --- |
| Fresh input | 490 | 256 | -47.8% |
| Cache write | 134,041 | 96,034 | -28.4% |
| Cache read | 4,133,084 | 2,152,150 | -47.9% |
| Output | 46,520 | 28,142 | -39.5% |

Measured 15 November 2026: at API rates, a Claude Code session on our test memory cost $0.47 before MinniMemoryMCP 1.6.0 and $0.29 after on average, 37.7% less, for the same 30 questions (each of three sessions 33.9% to 40.0% less). A blind judge found 80 of 87 answers correct before and 81 after. The method, the date and the build are on the [Evidence page](https://minniai.com/evidence).

The change was made by [MinniMemoryMCP](https://minniai.com/minnimemorymcp), an MCP server for Claude Code and Codex. It sorts your memory files into a small part that loads on every turn and files the agent opens only when a task needs them. Every line is kept, and `undo` puts the originals back.

install it for Claude Code

```
$ npm i -g minnimemory
$ minnimemory install
```

## Measure your own

Pick one task you do often. Run it in a fresh session, note the token counts and cost, change one thing, and run it again. In Claude Code the Session block of `/usage` lists input, output, cache read and cache write tokens with an estimated cost. Comparing two different days of work tells you nothing; the same task twice does.

More detail per tool: [How to reduce Claude Code token usage](https://minniai.com/learn/reduce-claude-code-token-usage), [How to reduce Codex token usage](https://minniai.com/learn/reduce-codex-token-usage) and [Why Claude Code sessions get expensive](https://minniai.com/learn/why-claude-code-sessions-get-expensive).

Try MinniMemoryMCP

Free, runs on your computer, and every change can be undone. Two commands install it for Claude Code; the [docs](https://minniai.com/minnimemorymcp/docs) cover Codex and the rest.

install it for Claude Code

```
$ npm i -g minnimemory
$ minnimemory install
```

## More guides

- [How to reduce Claude Code token usage](https://minniai.com/learn/reduce-claude-code-token-usage) Where the tokens go each turn, and eight ways to spend fewer.

Updated 2026-11-16 · Minni AI

- [Claude Code usage limit reached: what to do, and how to hit it less](https://minniai.com/learn/claude-code-usage-limit-reached) What each limit message means, what to do now, and how to send less every turn.

Updated 2026-11-16 · Minni AI

- [CLAUDE.md too long: what Claude Code does with it, and how to split it](https://minniai.com/learn/claude-md-too-long) What a long CLAUDE.md costs, the real size limits, and four ways to cut it.

Updated 2026-11-16 · Minni AI

- [Claude Code context window keeps filling up: why it compacts, and what to do](https://minniai.com/learn/claude-code-context-window-full) What fills the window, what compaction keeps, and how to compact less often.

Updated 2026-11-16 · Minni AI

- [How to reduce Codex token usage](https://minniai.com/learn/reduce-codex-token-usage) Where Codex spends tokens, and seven ways to spend fewer.

Updated 2026-11-16 · Minni AI

- [Codex usage limits: why they drain and how to use fewer tokens](https://minniai.com/learn/codex-usage-limits) How the windows work, how to check what is left, and what uses the allowance up.

Updated 2026-11-11 · Minni AI

- [AGENTS.md too large: what Codex cuts off and how to split it](https://minniai.com/learn/agents-md-too-large) The 32 KiB cap, how to see which files load, and five ways back under it.

Updated 2026-11-11 · Minni AI

- [Why Claude Code sessions get expensive](https://minniai.com/learn/why-claude-code-sessions-get-expensive) Every turn re-sends the whole session. What makes that grow.

Updated 2026-11-05 · Minni AI

- [Claude Code memory: CLAUDE.md vs MinniMemoryMCP](https://minniai.com/learn/claude-code-memory-claude-md-vs-minnimemorymcp) What belongs in CLAUDE.md, and splitting the rest out by hand or with a tool.

Updated 2026-11-16 · Minni AI

- [MinniMemoryMCP vs Mem0, Zep, supermemory and Letta](https://minniai.com/learn/minnimemorymcp-vs-mem0-zep-supermemory-letta) Four tools add memory to an agent. MinniMemoryMCP cuts what the agent already loads. When each fits.

Updated 2026-11-16 · Minni AI

- [How Claude Code remembers across sessions](https://minniai.com/learn/claude-code-memory-across-sessions) What carries over between sessions, what does not, and how to keep it small.

Updated 2026-11-16 · Minni AI

- [Where Claude Code keeps its memory](https://minniai.com/learn/claude-code-memory-directory) Every memory path on your machine, what each file is for, and which ones load every turn.

Updated 2026-11-07 · Minni AI

- [How to run a coding agent on free, open models](https://minniai.com/learn/run-a-coding-agent-on-free-open-models) What a free key gets you, what a local model can do, and where the tokens go.

Updated 2026-10-25 · Minni AI

- [Get a free NVIDIA API key for a coding agent](https://minniai.com/learn/free-nvidia-api-key-for-a-coding-agent) Where the key comes from, where to keep it, and how to run a coding agent on it.

Updated 2026-11-07 · Minni AI

- [What a Windows PC optimization agent should and should not touch](https://minniai.com/learn/what-a-pc-optimization-agent-should-touch) The settings worth changing, the ones that are placebo, and the ones that break things.

Updated 2026-10-25 · Minni AI

---

Index for agents: https://minniai.com/llms.txt. Doing a task: https://minniai.com/agents.md
