Hand off, don't compact

When a Claude Code session gets long, I don't let it compact. I ask Claude to write down where we are, then I close it and start a fresh session that reads that note. It's one extra step, and I get a cleaner agent and a note I can actually read.

What compaction does

Every AI chat has a limit on how much it can hold in its head at once, called the context window. When a Claude Code session fills it up, Claude can compact: it writes a summary of the conversation for itself, throws away the rest, and keeps going from the summary.

That works. My problem with it is that the summary is written by the model, for the model, and I never really look at it. If it keeps a dead end we already ruled out, or drops the one constraint that mattered, I find out later when the agent does something odd.

What I do instead

When a session starts to feel heavy, I ask for a hand-off. Some of the actual prompts:

Guessing I need a new context. Can you give me a prompt to give claude to tell it what we're looking for.

Yeah give me the plan and I'll start a new agent.

When the worktree is ready give me a prompt to use for the new agent I will start.

Claude writes either a prompt I paste into a new session, or a file in the repo, something like FEATURE-HANDOFF.md. Then the new session gets one line:

Read FEATURE-HANDOFF.md in this worktree and follow it. Start with "Still to do".

The good hand-offs have the same few parts:

  • what the goal is, in a sentence or two
  • what's already done, with commit hashes
  • what we tried and ruled out, so the new agent doesn't try it again
  • the constraints that bit us ("never sed -i these files, they're CRLF")
  • what to check first, and when to stop and ask me

One I got before a debugging session listed the two commits already made, what I'd tested on a real phone, which log server to search, the exact search terms, and this line: "If it's still failing with an auth error, tell me plainly and stop rather than guessing further." That last part alone saved me a loop.

Why I like it better

I can read it. The hand-off is plain text in front of me before the new session starts. If it's wrong, I fix it. A compaction summary goes by without me ever really checking it.

It's on disk. If VS Code crashes or I close the wrong window, the file is still there. I can open it tomorrow and pick up where I left off.

The new agent starts clean. It gets the facts that matter and none of the back and forth it took to find them, and none of the dead ends either.

It works for handing work sideways too. Same trick when I spin up a second worktree for a side quest: the first agent writes the brief, the second one reads it. Neither one has to remember the other.

The one thing to watch: keep hand-off files out of your commits. I gitignore them.

It's a small habit. But "write it down before you forget" turns out to be good advice for agents too. Unlike me, they actually follow it.

Drafted with an assistant, edited by @wintaru

0 comments