Long tasks rarely finish in one agent session. Context fills up, the session ends, or you stop for the night, and the next session starts cold.
What I keep losing in that handoff is not the code. It is the why: which approach was tried and dropped, what is half done, and what the agent was about to check next.
So I'm curious how other people do it:
- Do you have the agent write a handoff note before it stops, or do you write it yourself?
- Where does it live: a file in the repo, the PR description, an issue, or just the chat history?
- How do you catch a note that is out of date because work kept going after it was written?
Would love to hear what actually works for you, and what you tried that didn't.
Top comments (5)
For the 'why' I stopped putting it in the handoff note at all. Each rejected approach or standing rule is its own small markdown file with a status line, and a decision that reverses an older one names it, so the old one flips to superseded. The next session loads only the active ones. That covers the case @jacksonxly describes: a stop rule that was lifted is no longer in what the agent reads. The SHA stamp from @parlup is what I'd use for the code state. (I work on iwe, an open-source CLI; the session reads
iwe find --filter '{status: active}', though a grep on the status line works too.)One small file per decision with a status line, and a reversal that names what it supersedes, is a clean fix for the stale stop rule. Loading only the active ones means the old rule simply disappears from what the agent reads.
The pattern that has held up best for us is treating the handoff note as a SHA-stamped sidecar, not prose written at the very end:
current_head,dirty_files, andlast_verified_cmd(exact command + exit code) at the top, followed byruled_out(approach -> exact failure). Keeping rejected paths explicit stops the next session from re-trying the same dead end.git rev-parse HEADplus a hash ofgit diff(stored in.git/agent-handoff.mdor a draft PR comment so it doesn't pollute commits). On resume, the first step checks whetherHEADor the working-tree hash moved since the stamp; if it did, the agent readsgit diff <stamped_sha>..HEADbefore trusting any claim in the note.The handoff that went stale on me carried a stop rule, which a check on the code wouldn't flag. One run ended with a checkpoint that forbade new work, and in the next session I changed the goal and asked for a slower pace. The lead agent messaged some areas individually and forgot the rest, so several agents spent the morning declining to run anything, correctly, under an instruction that had expired. It only surfaced when one of them reported it was idle under a rule it hadn't been told was lifted.
I think the most valuable part of a handoff is making the next session understand not just the current state, but the reasoning that led there.
I'd want the agent to leave three things behind:
I'd keep that in a handoff file inside the repository rather than relying on chat history. The repo is where the actual work lives, and the note should travel with it.
One extra safeguard I'd use is to update the handoff at the end of the session, not just when the agent first announces it's running out of context. Otherwise, the note can describe a project that no longer exists in that state.
The interesting challenge is that an AI agent can summarize what it did, but it doesn't always recognize which decisions will matter to the next session.
What's your most reliable way of preserving that missing context — especially the reasoning behind decisions that aren't obvious from the code?