Sub topic 11
Starting Fresh: Handing Work to a New Session
This chapter assumes you have used a coding agent for multi-step tasks, that you know what a context window is, and that you can read a progress file and run basic git commands. It builds on compaction and external notes. Here the question is what to do when compaction is not enough and you decide to end the session.
When a fresh session beats continuing
Compaction shrinks a session but keeps its history, including wrong turns and stale assumptions. A fresh session starts with an empty conversation. Only the instructions you load and the files you point it to are in context. That gives you a clean window and removes any false beliefs the old session had built up.
Start fresh when one or more of these hold:
- The agent repeats a mistake you already corrected, or contradicts an earlier decision.
- You have compacted more than once and the summaries are summaries of summaries.
- The next subtask has little in common with the previous one, such as moving from a code change to writing docs.
- The session carries a long trail of failed attempts that the agent keeps referring back to.
- You want a quick start tomorrow without reloading yesterday's conversation.
Continue the current session when the agent is working well, the remaining work is a direct continuation of what it just did, and usage is comfortably below your action threshold.
What a handoff must carry
A handoff transfers just enough state for the new session to continue without redoing work or reversing decisions. Think of it as a note to a colleague who has never seen the project today.
| Item | Why it matters | Where it lives |
|---|---|---|
| Goal and current subtask | Without it the agent cannot judge what counts as done | Progress file |
| Decisions and reasons | Without reasons, the new agent may reopen settled questions | Progress file |
| State of the code | The agent should not trust a description of the code when it can check | Git (branch, diff, commits) |
| Unresolved failures | Prevents the agent from assuming everything passes | Progress file, with the exact failing command |
| Next steps | Gives a concrete place to start | Progress file |
| Dead ends | Stops the new agent from retrying approaches that failed | One line each in the progress file |
The code itself is the most reliable part of the handoff. Do not paste file contents into the notes. Name the files and let the new session read them with targeted reads.
Where the state comes from
You have three sources of truth, and they have different reliability.
- Git. The repository records what actually changed.
git status,git diff, andgit logcannot drift from reality. - The progress file. It records intent and reasoning, which git cannot. It can go stale if you do not update it, so refresh it before ending a session.
- The old conversation. It holds everything, but it is large and unreliable. Treat it as a source to mine for the progress file, not something to carry forward.
Commit work in a coherent state before you hand off, even on a scratch branch. A clean commit boundary gives the new session a known starting point and lets you roll back if the next session goes wrong.
Writing the handoff
Before closing the old session, ask the agent to update the progress file. Be explicit about what to include, the same way you guide compaction.
Before we end this session, update PROGRESS.md so a new session can continue.
Include: the goal, decisions with reasons, what is done, what is failing
(with the exact command to reproduce), dead ends we ruled out, and the next
three steps. Do not paste file contents. Then show me `git status`.The progress file from the earlier chapter works as the handoff document. Add a section for dead ends and a section for how to verify state:
# PROGRESS.md
## Goal
Migrate the settings loader from INI to TOML without changing the public API.
## Decisions
- Keep `load_settings()` signature unchanged (other packages import it).
- Use the standard library `tomllib` (read-only is enough).
## Done
- [x] Added TOML parser path in `config.py`
- [x] Updated unit tests for the loader
## Failing
- `pytest tests/test_config.py::test_legacy_ini -x` fails: legacy INI files
with duplicate keys now raise an error.
## Dead ends
- Tried wrapping `configparser` to emit TOML: too many edge cases, dropped.
## Next
1. Decide how to treat duplicate keys in legacy INI files.
2. Update the configuration docs page.
3. Run the full test suite.
## Verify state
Run `git log --oneline -5` and `pytest -x -q 2>&1 | tail -n 30`.Notice the "Verify state" section. It tells the new session to check reality before trusting the notes.
Starting the new session
Open the new session and give it a short, specific opening instruction. Do not paste the old conversation.
Read PROGRESS.md. Then run `git log --oneline -5` and `git status` and tell me
whether the code matches the notes. Do not change anything yet.Asking for a comparison first catches stale notes before the agent builds on them. Once the agent confirms the state, give it the first item from "Next" and proceed.
If your tool can resume or fork a previous session, that is a different operation. Resuming restores the old conversation, including its crowded context, so it does not solve the problem described here. Use it when you need the exact earlier exchange, not when you need a clean window.
The handoff flow
Handing work to a subagent
A subagent is a separate agent instance with its own context window. Delegating to one is a handoff in miniature. The same rules apply, but the parent session cannot be asked follow-up questions cheaply, so the brief must be self-contained.
A good delegation brief states:
- The task and the definition of done.
- The files or directories in scope, and anything out of scope.
- The output format you want back, such as "a list of file paths with one line each, under 200 words".
- Constraints, such as "read only, do not edit".
The returned result enters your session's context, so ask for a summary and not a transcript. A subagent that explores 40 files and returns a 10-line answer saves your context. One that returns everything it saw does not.
Common errors
- Trusting stale notes. The progress file says tests pass, but a later edit broke them. Always have the new session verify with git and a test run.
- Handing off uncommitted work. If changes exist only in the working tree, a branch switch or reset can lose them. Commit first.
- Carrying over the old framing. If the notes describe a failed approach as "the plan", the new session will follow it. Label dead ends clearly.
- Notes that are too long. A progress file of several hundred lines uses the context you were trying to save. Prune finished items to one line or move them into the commit history.
- Missing the reasons. "Use tomllib" without "read-only is enough" invites the new agent to question it.
- Pasting the old transcript. This recreates the crowded context in the new session.
- Skipping the reproduction command. "Tests fail" is not actionable. The exact command and the failing test name are.
A worked example
You have spent two hours on the TOML migration. The agent has started to suggest reintroducing configparser, which you rejected an hour ago. Usage is high and you have compacted once.
- Ask the agent to update
PROGRESS.mdusing the prompt above, including the rejectedconfigparserapproach under "Dead ends". - Review the file. Correct anything wrong. This is the moment where you fix the agent's misunderstandings, because the new session will believe whatever is written.
- Run
git add -A && git commit -m "WIP: TOML loader, legacy INI test failing". - Open a new session and send the opening instruction.
- Read the agent's comparison of notes and code. If it reports a mismatch, resolve it before continuing.
- Tell it to start with "Next" item 1.
The new session starts with a few thousand tokens in use instead of most of the window, and it does not suggest configparser again, because the notes say why it failed.
Checking that the handoff worked
After a few turns in the new session, test it with a question whose answer is in your notes, such as "Why are we not using configparser?" A correct answer shows the reasons transferred. A vague answer means the notes are missing something. Add it, and treat the gap as a lesson for the next handoff.
Exercise
You are ending a long session. Name the three sources of state for a handoff, rank them from most to least reliable, and say what the new session should do before it trusts the progress file.
Show answer
Ranked from most to least reliable: git (commits, diff, status), the progress file, and the old conversation. Git reflects what actually changed, the progress file records intent and decisions but can go stale, and the old conversation is large and error-prone. Before trusting the progress file, the new session should check it against git (for example git log --oneline -5 and git status) and run the relevant tests, then report any mismatch before changing code.
Exercise
A progress file says "Tests: all passing" and lists "Next: update docs". The new session starts the docs work, and then the test suite shows a failure. Give two likely causes of the mismatch and one change to the handoff that would have prevented it.
Show answer
Likely causes: the notes were not updated after a final code edit, or the work was never committed or tested after the last change. A prevention is to add a "Verify state" step with the exact test command, and to have the new session run it and compare the result with the notes before doing any new work. Committing at a known state and recording the test result with its command also helps.