Jakob Christensen / Cases#001#002#003#004

6 Rules + 3 Habits to finish Agent Sessions cleanly

Jakob Christensen

Relevant skills: /strays, /am-i-done, /case-closed, /tidy-worktrees, /lanes, /fresh, /tidy-sessions, /attic

Archiving a chat does not mean its work has landed. I learned this from an agent that told me its work was merged and then deleted its work folder. The check was still running, and the commit it had reported did not exist. The branch was still there, so nothing was lost. After that I counted what else was lying around in my repositories.

By landed I mean merged into main, the branch of the project that everything else builds on. Until then the work sits on a side branch, and closing the chat is the easiest way to forget it. The rules below make an agent finish all of it before it says "done". The habits after them are the part only you can do.

Rule of thumbDone means committed, merged, pushed and nothing waiting.All four count. An agent that says "done" after the first one leaves the rest for you to find later.

Four questions to ask before you close a chat

You can ask your agent each of them in plain words. For each there is also a skill, a ready-made instruction file your agent follows when you type its name, that does the asking for you.

1Committed?

A commit is a saved snapshot of your changes in git, the tool that keeps the project's history. Until then, the changes are only files on disk.

Ask: "Is anything still not committed?"

Ask in the chat that did the work, because a chat in another folder cannot see its changes.

/case-closed

2Merged into main?

Agents usually work on a branch, a separate line of changes, so they do not get in each other's way. Merging brings that branch back into main, the project's main line (also called the default branch).

Ask: "Is all of this work in main?"

If not, have the agent merge it before it deletes its extra work folder (a worktree).

/lanes

3Pushed?

Pushing sends your commits to the remote, the copy on a server such as GitHub. Until then they exist on your computer only.

Ask: "Is anything saved only on my computer?"

/strays

4Nothing waiting?

No open question, no command still running in the background, no folder left behind.

Ask: "Are you still waiting for me or for a running job?"

In a list of chats, one that waits for your answer looks just like one that is finished.

/am-i-done, /fresh, /tidy-worktrees, /tidy-sessions, /attic

Example

When I counted my 14 repositories on 1 December, this was still open:

Not all of this was forgotten. Some of it was work in progress, some was on purpose. But a list of branches does not tell you which is which, and that is why the agent should finish its part before it says done.

Rules for your agent (paste into CLAUDE.md or AGENTS.md)

These rules are written for your agent, not for you, which is why they read like orders. Paste them into CLAUDE.md or AGENTS.md, the file of standing instructions your agent reads at the start of every session, or download them.

Read the agent rules (MD)

  1. Merge before you say done

    Commit your own finished work and merge it into the default branch before you report a session as done. Where your team reviews pull requests (proposed changes that someone approves before they are merged), open one instead and do not merge it yourself.

    Why

    Once the chat is closed, nobody remembers the branch. An unmerged branch then looks the same whether it is still in progress or simply forgotten.

  2. Never say done while something is open

    Never report "done" while a check is red, a question is open, work is uncommitted, or a background job still runs. A job counts as finished only when its own output shows it ended. If something is still open, end with what it waits for.

    A check here means the project's tests, lint and build. A background job is a command that keeps running after the agent has replied, such as a long test run.

    Why

    "Done" reads like permission to close the chat. If something is still running at that moment, nobody is watching it anymore.

  3. Check the branch before you remove its worktree

    In short: before the agent deletes a work folder, it proves that the folder's branch is already in main. The commands are for the agent. The second one is needed after a squash merge, which turns a whole branch into one new commit, so git no longer recognises the branch as merged.

    Remove a worktree only after its branch is in main: git merge-base --is-ancestor <branch> main succeeds. After a squash merge that check fails. Then, with Git 2.38 or later, the branch is in main when git merge-tree --write-tree main <branch> prints the same id as git rev-parse main^{tree}. Delete the branch with git branch -d. Use -D only after that second check.

    Why

    The work folder is the easiest place to finish a branch from, because everything the agent was working on is still there. Once the folder is gone, an unmerged branch is only a name in a list.

  4. Close with a report that can be checked

    End with a short report: what is not pushed, what is not deployed (not live yet), and for each finished step the command you ran and its result, one line each.

    Why

    With a report like that you see what is left without scrolling through the whole chat, and you can rerun any command to check what the agent claims.

  5. Name every open branch in the handoff note

    A handoff note names every open branch and what it is missing from main.

    A handoff note is what a session leaves for the next one, so the next one can continue without reading the old chat.

    Why

    The next session has not seen this conversation. Whatever the note leaves out, it has to dig up again on its own.

  6. Write down what you put off

    Write every step you put off into a to-do file in the repository, in the same turn (one reply of the agent).

    Why

    A step that exists only in a chat disappears when the chat is closed. A file in the repository is still there when the next session starts.

Habits for you (an agent cannot do these)

  1. Ask before you close

    Before you close a chat, run /am-i-done.

    Skill: /am-i-done checks whether the whole task is finished and lists what is still open.

    Why

    Closing a chat takes its open points out of sight, and asking before you close is cheaper than finding them later.

  2. Push regularly

    Push your local commits regularly, for example with /strays.

    Skill: /strays finds work that is only on your computer and pushes it safely.

    Why

    A commit that was never pushed exists on one machine only. If that machine breaks, the work is gone with it.

  3. Let a hook catch a false "done"

    Ask your agent to add a Stop hook that sends the agent back when it says "done" while work is uncommitted or a job still runs.

    A Stop hook is a small script Claude Code runs every time the agent finishes a reply. "Why a hook" further down lists what to watch out for when you set one up.

    Why

    A line in CLAUDE.md is a request, and the agent can forget it. A hook is a script that runs every time.

The details

Why a hook

A line in CLAUDE.md is a request: Claude Code's docs say there is no guarantee it is followed. A Stop hook is a script Claude Code runs every time the agent finishes responding. If it exits with code 2, the agent gets the script's message and keeps working.

Three things to get right when your agent sets it up:

How the numbers were measured

Summary

Measurements

Repositories14 of my local repositories, five of them without a remote
Worktrees132 besides each main checkout, 20 with uncommitted changes (in 3 repositories)
Branches not in the default branch61 (34 with a worktree)
Commits on no remote112 in 3 of the 9 repositories with a remote, oldest 26 days, and 1,135 in the 5 repositories without a remote, oldest 51 days
Main sessions, October and November 20262,659, of which 1,051 (40 %) whose last agent message has "Fertig." or "Done." as its own paragraph
Of those 1,051, sessions that created a branch350 (33 %): 21 had every branch merged into the default branch, 1 had a branch that git still shows as unmerged although its change is in the default branch, 328 had a branch that no longer exists, so I cannot tell

Commands

CountCommand
Worktreesgit worktree list --porcelain
Branches not mergedgit branch --no-merged <default>
Commits on no remotegit log --branches --not --remotes --oneline
Uncommitted changesgit -C <worktree> status --porcelain
Branch merged?git merge-base --is-ancestor <branch> <default>

The counts are a snapshot of 2026-12-01, taken read-only. The session numbers come from my local transcripts (the .jsonl files Claude Code stores under ~/.claude/projects).

Method and limitations

Sources