Quick Answer
If your Claude Code or Codex session gets slower, harder to steer, or more expensive in API-billed workflows as it goes on, the fix is usually workflow shape, not a better prompt.
On 2026-04-17, NVIDIA's Dynamo team published a detailed post on agentic inference that used Claude Code- and Codex-style sessions as examples. Their key point is practical: long coding sessions behave like write-once, read-many systems. The expensive prefix is the stable part of the conversation: system instructions, tool definitions, repo rules, and the part of the task that stays true across turns. When you keep changing that prefix, you force more recomputation. When you keep it stable, the system can reuse more of it.
If you run through APIs that support prompt caching, that reuse can also lower repeated-input spend. But stable wording alone is not enough. Anthropic's prompt-caching docs say you need cacheable content blocks and a cache breakpoint, with the cache point placed after content that will stay identical across later requests. OpenAI's prompt-caching guide says reuse depends on exact prefix matches and starts only once the prompt reaches at least 1,024 tokens. If you use bundled products such as Claude Code or Codex desktop, treat the same pattern as a latency and context-hygiene optimization first, not as a verified billing guarantee.
The best default is simple:
- keep one session for one objective,
- move stable instructions into a small reusable prefix,
- split parallel work only when the branches are truly independent,
- summarize milestones into files before the thread turns into a transcript dump,
- and stop attaching tools or files that are not needed for the current turn.
Long Sessions Amplify The Problem
This topic got a real trigger on 2026-04-17, not just a vague "agents are popular" excuse.
NVIDIA's official post says coding-agent sessions can make hundreds of API calls while carrying forward a large shared prefix. In the examples they published, later turns in a Claude Code-style session hit cache reuse in the 85% to 97% range after the first write, and a four-agent team reached 97.2% aggregate cache hit rate with an 11.7x read-to-write ratio. Those are infrastructure numbers, not a promise for every hosted product. But they reveal the pattern clearly: long sessions are dominated by repeated reuse of the same context.
For API-billed workflows, the pricing side makes the workflow matter too.
As of 2026-04-20, Anthropic's prompt-caching docs say the default cache lifetime is 5 minutes, and Anthropic's pricing page lists Sonnet 4.6 at $3 / MTok input, $3.75 / MTok 5-minute cache writes, and $0.30 / MTok cache reads. OpenAI's API pricing page lists GPT-5.4 at $2.50 / 1M input and $0.25 / 1M cached input, and GPT-5.4 mini at $0.75 / 1M input and $0.075 / 1M cached input. If you are using product bundles instead of raw API billing, read this as evidence for reuse economics and latency behavior, not as proof of direct product-billing savings.
What Actually Causes Token Waste In Coding Agents
Most token waste does not come from one bad answer. It comes from repeatedly making the model re-read too much volatile context.
Common causes:
| Pattern | What happens | Better move |
|---|---|---|
| One chat for many unrelated jobs | The prefix grows, but less of it is relevant to the current turn | Start a new session when the objective changes |
| Re-explaining repo rules every time | Stable instructions get rewritten or paraphrased on each turn | Put repo rules in one small file and point the agent to it |
| Spawning subagents for loosely related work | Each branch starts cold and may repeat setup context | Split only when outputs can be reviewed independently |
| Dumping whole files and logs into chat | The thread keeps carrying old detail that no longer helps | Summarize the result into a note, diff, or issue comment |
| Leaving many tools in scope | Tool schemas and permissions add context and surface area | Keep only the tools needed for the current task |
Tip 1: Treat Stable Instructions As A Prefix, Not As Chat Chatter
If a rule survives most turns, it should live outside the conversational back-and-forth.
Anthropic's prompt-caching docs are a useful mental model here because they frame cached prompt structure as a stable prefix before later conversation turns. Anthropic's Claude Code memory docs apply the same idea at the workflow level: keep durable project rules in CLAUDE.md instead of restating them in every chat turn.
For API users, make the rule more concrete. In Anthropic's docs, a cache hit depends on where you place the breakpoint and whether the reusable prefix is long enough for the model's minimum cacheable length. In OpenAI's docs, the reusable part must match exactly from the start of the prompt, not just in meaning. "Mostly the same" is not the same as cacheable.
If you are working inside the named products, use their native session controls too. As of 2026-04-20, Anthropic's Claude Code commands docs list /compact for compressing the current conversation and /clear for starting fresh with cleared history. OpenAI's Introducing the Codex app says Codex agents run in separate threads organized by projects and the app includes built-in worktrees. In practice, that means:
- in Claude Code, use
/compactwhen the objective is still the same but the transcript has grown bulky, and use/clearwhen the old history is now dead context, - in Codex, prefer a new thread and, when the code path diverges, a fresh worktree instead of forcing unrelated work through one long-running session.
Good candidates:
- repo conventions
- coding style rules
- test commands
- review checklist
- approval boundaries
- links to product or API docs that stay relevant for the whole task
For Claude Code, that usually means a tight project instruction file such as CLAUDE.md or repo docs the agent can repeatedly consult. For Codex, it means a task brief that stays small and stable, plus project notes in files instead of re-pasting the same constraints into every message.
Bad pattern:
Use TypeScript. Also keep accessibility in mind. Also do not change analytics. Also prefer server components. Also keep changes small. Also run the same test command as before.
Better pattern:
Use the repo rules in AGENTS.md.
Task: fix the mobile checkout validation error without changing analytics or auth flows.
Stop after code changes plus the exact verification commands.
The change looks minor. It is not. Stable instructions become a reusable prefix instead of a growing pile of paraphrases.
Tip 2: Keep One Session For One Objective
A coding thread should have one finish line.
Good session boundaries:
- one bug
- one refactor inside one subsystem
- one PR review pass
- one setup or migration task
- one documentation change with one verification path
Bad session boundaries:
- "clean up the repo while you are here"
- "also update docs and fix CI and compare pricing and review this PR"
- "keep this chat as my general coding workspace for the week"
A useful reset rule is:
- if the acceptance test changed, start a new session;
- if the main directory changed, probably start a new session;
- if you need to explain the old context before asking the new task, definitely start a new session.
This is also where worktrees help. A new worktree gives you a new branch, a smaller diff, and a natural place to open a fresh agent session.
git worktree add ../repo-fix-checkout -b fix-checkout-validation
cd ../repo-fix-checkout
Tip 3: Use Parallel Agents Only For Independent Branches
NVIDIA's 2026-04-17 post is useful here because it separates a lead agent from subagents instead of pretending all parallelism is free.
Parallel work helps when each branch can answer a narrow question such as:
- trace one failing test,
- inspect one dependency upgrade,
- review one folder for dead code,
- compare two implementation options.
Parallel work hurts when every branch needs the whole repo story plus the full conversation so far.
There is also a cache-timing caveat for API users. Anthropic's prompt-caching docs say a cache entry only becomes available after the first response begins. OpenAI's prompt-caching guide says cache routing can reduce effectiveness when many requests with the same prompt prefix arrive at once. So if you want the shared prefix to help, let one lead request establish it first, then fan out narrower branches.
Use this quick rule before spawning another agent:
- If the subtask can end with a small memo, diff, or yes/no recommendation, spawn it.
- If the subtask needs the full evolving plan, keep it in the main thread.
A compact delegation prompt works better than forwarding the whole conversation:
Check only `src/payments/` for why the checkout form sends duplicate validation events.
Do not edit files.
Return:
1. likely root cause,
2. exact files involved,
3. whether the fix is low, medium, or high risk.
That preserves independence. It also limits how much context each branch has to carry.
Tip 4: Summarize Milestones Before The Thread Becomes A Log Archive
Long coding chats degrade when old exploration stays in the active context forever.
A better pattern is to convert temporary reasoning into durable notes at milestones:
- after repo exploration,
- after root-cause identification,
- after the chosen fix,
- after verification,
- before handing work to another agent or another human.
The summary should be short and file-backed.
Example checkpoint note:
## Checkout validation checkpoint
- Root cause: `useCheckoutValidation` fires both on blur and on submit for the same empty state.
- Files: `src/features/checkout/useCheckoutValidation.ts`, `src/features/checkout/CheckoutForm.tsx`
- Safe fix path: dedupe submit-time emission when blur already marked the same field invalid.
- Verify with: `bun test src/features/checkout` and manual mobile checkout flow.
This gives the next turn a clean anchor. It is better than dragging 60 turns of exploration forward.
Tip 5: Keep Tool Scope Narrow During Long Sessions
Every extra tool, connector, or permission surface adds more opportunity for irrelevant context, longer tool definitions, and slower recovery after pauses.
As of 2026-04-16, OpenAI's Codex update post expands the product a lot: browser actions, plugins, memory, multiple terminals, review-comment handling, and automations. That is useful. It also makes it easier to create a session with too much active surface area.
The safe default is boring and effective:
- enable only the tools needed for the current task,
- keep browser or desktop control for steps that really require it,
- avoid attaching extra docs, logs, or screenshots "just in case",
- turn long-lived memory into stable preferences, not volatile project state.
For Claude-side workflows, the same rule applies to connectors, tools, and prompt caching boundaries. Cache the parts that stay stable. Do not keep padding the live thread with temporary debris.
A Simple Session Template That Usually Reduces Waste
Use this when starting a non-trivial coding task:
You are helping with one bounded coding task.
Goal: fix [specific problem].
Scope: only [files, folders, or subsystem].
Constraints: follow repo rules in [file]; do not change [out-of-scope areas].
Tools: use only what is needed for this task.
Process:
1. inspect,
2. propose the smallest fix,
3. apply it,
4. run the exact verification commands,
5. stop.
Return a short checkpoint summary before any optional follow-up work.
This template works because it stabilizes the prefix and gives the session a stop line.
When You Should Ignore These Tips And Start Fresh
Start over instead of optimizing the current thread when:
- the agent misunderstood the task for many turns,
- the accepted plan changed,
- the relevant repo area changed completely,
- the thread now contains large dead context,
- a review pass needs a cleaner record than the existing session can provide.
A fresh session is often the cleaner move than trying to rescue a bloated one.
FAQ
Does this only matter if I pay per token?
No. The billing signal is clearest in API pricing, but the same reuse pattern can still show up as latency and session-quality gains inside bundled products.
Does prompt caching mean I can keep one huge thread forever?
No. Anthropic's docs describe prompt caching as prefix reuse, not permission to keep adding irrelevant context forever. Relevance still matters.
Should I always use subagents to go faster?
No. Use them when the branch can stay narrow and return a bounded result. Otherwise you just create several cold starts and more review work.
Is a summary file really better than the chat history?
Usually yes. A short file-backed checkpoint keeps the next turn grounded in facts you still care about, while the full transcript keeps carrying everything.
Verification Note
Verified on 2026-04-20.
Checked against official sources:
- NVIDIA: Full-Stack Optimizations for Agentic Inference with NVIDIA Dynamo for the 2026-04-17 publication date, cache-reuse examples, and multi-agent read-to-write ratio.
- Anthropic Prompt Caching, Anthropic Claude Code Memory, Anthropic Claude Code Commands, and Anthropic Pricing for default cache lifetime, cache breakpoints, concurrency behavior,
CLAUDE.mdmemory guidance,/compact,/clear, and Sonnet 4.6 cache pricing. - OpenAI Prompt Caching and OpenAI API Pricing for exact-prefix matching, minimum cacheable length, cache-routing caveats, and cached-input pricing for GPT-5.4 and GPT-5.4 mini.
- OpenAI: Introducing the Codex app for Codex threads organized by projects, built-in worktrees, and session-history continuity; and OpenAI: Codex for almost everything for the 2026-04-16 Codex desktop feature surface referenced in Tip 5.