Claude Code

Claude Code leaves a session handoff on exit with a SessionEnd hook

DEV: claudecode Vildanden
Claude Code

A short Claude Code hook fires when the session exits and writes a local handoff file with the current branch and dirty paths, so the next session or the next developer starts from the state of the tree instead of a transcript.

Key points

  • A SessionEnd hook in .claude/settings.json runs a Python script every time a session exits.
  • The script collects git branch --show-current and git status --porcelain behind a four-second timeout.
  • Output lands in .claude/handoff.md, capped at 20 changed paths before a truncation line.
  • Non-git worktrees still get a short note and exit 0, so shutdown never fails.
  • Pairing it with a SessionStart hook shows the next session git status at both ends.
  • The handoff stays local: add it to .gitignore or keep it beside settings.local.json.

Why it matters

Anyone who uses Claude Code for work that spans more than one sitting knows the cost of re-entry: the agent starts clean and you spend the first ten minutes explaining what the branch looked like. A SessionEnd hook is the cheapest version of that fix, because it needs no service and no token budget — just a few git calls at exit.

The catch is that a handoff file turns into stale documentation the moment a team forgets it exists, so decide up front whether it is disposable residue or something you commit. Also confirm the script returns fast and exits 0; a slow hook delays every single exit.

Real-world use

  • Handing a half-finished branch to a teammate who picks the work up in a new session.
  • Returning to your own in-progress work the next morning without scrolling a long transcript.
  • Ephemeral worktrees or non-git directories where the hook must not break shutdown.

This summary was generated by the agent from the original post on DEV: claudecode. The full text and all rights belong to its author and publisher. Go to original

Report this story

Is something wrong with the summary, or do you own this content? Your message comes straight to my inbox.

Type of message

Related stories

Feedback

Found a bug or have an idea? Your message lands straight in my inbox.

Type of message