Session preservation via PreCompact and Stop hooks. Automatically captures your plan, progress, and context before it gets lost.
PreCompact is the most important hook event in Claude Code. When the context window fills up, Claude compresses the conversation to make room. That compression destroys information -- your current plan, what you've tried, what failed, what's next. This plugin intercepts that moment and writes a structured handoff file before anything is lost.
The Stop hook provides a second safety net, capturing session state when Claude finishes responding.
The plugin writes to .claude/handoff.md in your project root:
# Session Handoff
**Saved:** 2026-02-25T14:32:01Z
**Trigger:** PreCompact (context window about to be compressed)
**Session:** abc123
## What to do with this file
This was auto-generated when the context window filled up. Read it at the
start of your next session to pick up where you left off. Add your own notes
below before starting a new session.
## Recent Context
(recent transcript lines extracted from the session file)
## Your Notes
<!-- Add your plan, progress, and blockers here before starting a new session -->Copy the plugin directory into your project's .claude/plugins/ or reference it from your hooks config:
{
"hooks": {
"PreCompact": [{ "type": "command", "command": ".claude/plugins/context-handoff/hooks/context-save.sh" }],
"Stop": [{ "type": "command", "command": ".claude/plugins/context-handoff/hooks/session-state.sh" }]
}
}Make the hook scripts executable:
chmod +x .claude/plugins/context-handoff/hooks/*.sh- Claude Code fires
PreCompactwhen the context window is about to be compressed context-save.shreceives a JSON payload withsession_idandtranscript_path- The script reads recent context from the transcript file at that path
- Writes a handoff template to
.claude/handoff.mdwith the extracted context - On
Stop,session-state.shappends the stop reason and timestamp
The handoff file persists across sessions. Next time you start Claude Code in that project, you (or Claude) can read .claude/handoff.md to pick up exactly where you left off.
jqfor JSON parsing- Standard POSIX shell utilities