There is a sunk-cost trap in AI coding sessions. You have spent forty minutes with Codex CLI or Claude Code on a task, the agent has built up a lot of context, and it feels wasteful to throw it away. So you keep going, nudging it with "no, try again," while each turn gets slower, more expensive and less accurate.
Very often, the right move is to kill the session and start a new one with a short summary. Here is how to tell when.
Why long sessions degrade
Agent sessions carry their entire history forward: every file read, every tool output, every failed attempt. As that grows:
- Each turn costs more, because more context is sent each time.
- Quality drops. Models handle huge contexts less reliably, and early mistakes stay in the history, influencing later turns.
- Compaction loses detail. When tools auto-summarize to save space, specific facts like file paths or the exact error can vanish, leading to re-reading and repeated mistakes.
- Plan limits drain faster, so you hit usage caps sooner.
A fresh session with a precise brief often outperforms a bloated one on the same task.
Seven signs it is time to restart
- The agent repeats a fix it already tried. It has lost track of its own history.
- It contradicts earlier decisions, such as reintroducing an approach you rejected.
- You have corrected it on the same thing twice.
- The task changed. You started fixing a bug and are now redesigning a module. New task, new session.
- Spend or usage has climbed steadily without a commit. No checkpoint in 20–30 minutes is a red flag.
- Compaction has happened more than once and the agent asks about things it already knew.
- Responses are getting slower and vaguer.
Two or more of these and you should restart.
How to restart without losing progress
Killing a session does not mean losing the work. Do this first:
1. Commit or stash what is useful. If part of the diff is good, commit it on a branch. If none of it is, git stash or reset.
2. Ask for a handoff summary before exiting:
Summarize in under 150 words: the goal, what you changed, what
you tried that failed and why, and the current blocker. List the
relevant file paths.
3. Edit the summary. Remove wrong conclusions. Add what you know that the agent did not.
4. Start a new session with the summary as the first prompt, plus a tighter task statement: "Fix only the failing test in auth.test.ts. Do not change the session model."
This usually takes two minutes and saves far more than that.
Make restarts cheaper by design
- Small tasks. Scope prompts to something finishable in one short session.
- Persistent context files. Put project rules and architecture notes in CLAUDE.md or AGENTS.md so a new session gets them for free instead of rediscovering them.
- Checkpoint commits. Ask the agent to commit after each passing step.
- Worktrees for parallel attempts. If you are unsure which approach works, run two fresh sessions in separate git worktrees instead of one long one that tries both.
Use the meter as a tiebreaker
When you are unsure whether to push on or restart, look at what the session has cost so far against what it has produced. If usage has climbed steadily for half an hour and there is no commit, that is your answer. The problem is that many people never look, because usage lives in a web dashboard and the session lives in the terminal.
I use TokenBar, a Mac menu bar app that tracks Claude Code, Codex, Cursor and related AI usage so today's burn is always one glance away. It is $15 lifetime and built on the MIT-licensed CodexBar project. Disclosure: I built TokenBar (Aura Technologies). It will not make decisions for you, but it puts the number in view while you still have time to act on it.
A rule worth adding to your agent config
Agents follow explicit stop conditions well. Add something like:
If the same approach fails twice, stop and summarize what you
tried and what is blocking instead of trying variations.
This turns many would-be long sessions into short ones that end with a useful question.
Bottom line
Long sessions feel productive because you are invested in them. But context is not free, and history full of failed attempts actively hurts. When the agent starts repeating itself, drifting or burning usage without commits, save what is useful, get a summary and start fresh. It is cheaper, faster and usually gets a better result.
Top comments (0)