curl -o ~/.claude/commands/handoff.md \
https://raw.githubusercontent.com/quantsquirrel/claude-handoff-baton/main/SKILL.mdDone. Now you can use /handoff to save and resume context manually.
Get automatic context monitoring, compaction protection, and session restoration:
# Clone the repository
git clone https://github.com/quantsquirrel/claude-handoff-baton.git ~/.claude/skills/handoff
# Register all 4 hooks
cd ~/.claude/skills/handoff && bash hooks/install.shDone. Everything works automatically from here.
| Skill Only | Full Install | |
|---|---|---|
/handoff command |
O | O |
| Auto token monitoring | - | O |
| Handoff reminder at threshold | - | O |
| Auto snapshot before compaction | - | O |
| Auto context restore on resume | - | O |
Start with Option 1, upgrade to Option 2 when you want automation.
/plugin update handoffcd ~/.claude/skills/handoff && git pullRe-run the curl command from Quick Start to download the latest version.
--continue restores conversations. Handoff passes a baton — distilled, structured, ready to run.
--continue (Raw History) |
Handoff Baton (Distilled Knowledge) |
|---|---|
| Loads entire message history (100K+ tokens) | Extracts essence in 100-500 tokens |
| Replays tool calls, file reads, errors | Captures decisions, failures, and next steps |
| Same session, same machine only | Clipboard: any session, any device, any AI |
| Doesn't highlight what failed | Explicitly tracks failed approaches |
| No prioritization of information | Smart auto-scaling for your needs |
One command. One baton. 500x compression.
claude --continue is great for short breaks. But it has limits:
- Token bloat: Restores everything — tool outputs, file contents, dead ends. Your 200K context fills fast.
- No knowledge extraction: Raw history doesn't highlight what matters. Failed approaches hide in noise.
- Single-tool lock-in: Only works within Claude Code. Can't share context with Claude.ai, teammates, or other AIs.
- Reliability: Session resume bugs can lose context silently.
Handoff complements --continue:
| Situation | Best Tool |
|---|---|
| Short break (< 30 min) | claude --continue |
| Long break (2+ hours) | /handoff → Cmd+V |
| Switching devices | /handoff → Cmd+V |
| Sharing context with team | /handoff |
| Context at 70%+ | /handoff |
1. /handoff → Context saved to clipboard
2. /clear → Start fresh session
3. Cmd+V (paste) → Resume with full context
/handoff [topic] # Smart handoff (auto-scales based on session complexity)Examples: /handoff · /handoff "auth migration" · /handoff "JWT refactor"
| Situation | Command |
|---|---|
| Context 70%+ reached | /handoff |
| Session checkpoint | /handoff |
| Session end | /handoff |
| Long break (2+ hours) | /handoff |
Output depth adjusts automatically based on session complexity:
| Level | Budget | Trigger | Sections |
|---|---|---|---|
| L1 | ~100 tokens | Under 10 messages OR 1 file modified | Time, Topic, Summary, Next Step |
| L2 | ~300 tokens | 10-50 messages OR 2-10 files modified | L1 + User Requests, Key Decisions, Failed Approaches, Files Modified |
| L3 | ~500 tokens | 50+ messages OR 10+ files modified | Full template (all sections) |
When message count and file count suggest different levels, the higher level wins. No manual level selection needed — just run /handoff.
v2.3 preserves the original context more faithfully:
| Feature | Description |
|---|---|
| Phase 0 Validation | Skips handoff when the session has no meaningful work |
| User Requests | Captures original user requests verbatim (10+ messages) |
| Constraints | Records user-stated constraints as-is (50+ messages) |
| Perspective Guide | Completed work in first person, pending work in objective voice |
Before creating a handoff, the skill validates that at least one of these is true:
- A tool was used
- A file was modified
- A substantive user message exists
If none: "No significant work in this session. Handoff skipped."
Original user requests are captured verbatim — not paraphrased:
## User Requests
- "JWT auth with refresh token rotation and RBAC"
- "Use async bcrypt, sync is too slow"User-stated constraints are preserved exactly as spoken (full-detail sessions only):
## Constraints
- "Use async bcrypt, sync is too slow"
- "Store tokens in httpOnly cookies, not localStorage"Session 1 → /handoff → Cmd+V → Session 2
- Working - You're deep in a coding session
- Save - Run
/handoffwhen context is high or before leaving - Resume - Paste in new session with
Cmd+V(orCtrl+V)
No /resume command needed. Just paste.
Handoff captures what matters, scaled to session complexity:
- Summary — What happened in 1-3 sentences
- User Requests — Original requests verbatim (v2.3)
- Completed / Pending tasks — Progress tracking
- Failed approaches — Don't repeat mistakes
- Key decisions — Why you chose what you chose
- Modified files — What changed
- Constraints — User-stated constraints as-is (v2.3)
- Next step — Concrete next action
Sections with no content are automatically omitted.
Handoff now intelligently detects task complexity and adjusts handoff timing accordingly.
-
Prompt Analysis
- Scans your request for keywords like "전체", "리팩토링", "migrate", "entire"
- Classifies task as Small / Medium / Large / XLarge
-
File Count Detection
- Counts files from Glob/Grep results
- Automatically upgrades task size when many files involved
-
Dynamic Thresholds
- Suggests handoff earlier for complex tasks
- Prevents context overflow on large refactors
You: "Refactor all authentication and migrate entire user database"
Large task detected - handoff will trigger at 50% (vs. 85% for small tasks)
This means you'll be prompted to create a handoff earlier, reducing the risk of losing progress.
Sensitive data is auto-detected and redacted:
API_KEY=sk-1234... → API_KEY=***REDACTED***
PASSWORD=secret → PASSWORD=***REDACTED***
Authorization: Bearer eyJ... → Authorization: Bearer ***REDACTED***
Detection includes:
- API keys and secrets
- JWT tokens and Base64-encoded credentials
- Bearer tokens in Authorization headers
- Environment variables with sensitive patterns
GDPR Consideration: Handoff documents may contain personal data. Review handoffs before sharing with third parties and delete old handoffs regularly.
The clipboard format includes safeguards to prevent Claude from auto-executing tasks:
<previous_session context="reference_only" auto_execute="false">
STOP: This is reference material from a previous session.
Do not auto-execute anything below. Wait for user instructions.
</previous_session>
New in v2.4: Context preservation across compaction + unified token tracking!
| Hook | File | Purpose |
|---|---|---|
| PrePromptSubmit | task-size-estimator.mjs |
Detects task complexity from prompt keywords |
| PostToolUse | auto-handoff.mjs |
Monitors token usage, suggests /handoff at dynamic thresholds |
| PreCompact | pre-compact.mjs |
Saves metadata snapshot before context compaction |
| SessionStart | session-restore.mjs |
Restores best available context after compact/resume |
- Unified token tracking with call-level deduplication (no double-counting)
- Dynamic thresholds based on task size:
- Small tasks: 85% / 90% / 95%
- Medium tasks: 70% / 80% / 90%
- Large tasks: 50% / 60% / 70%
- XLarge tasks: 30% / 40% / 50%
- PreCompact saves git state, modified files, and token count before compaction
- SessionStart scores available sources by
score = base × freshness + relevance - Selects the single best source (handoff .md > pre-compact snapshot)
- Auto-cleans old snapshots (keeps last 3)
# Clone for hook files
git clone https://github.com/quantsquirrel/claude-handoff-baton.git ~/.claude/skills/handoff
# Install all 4 hooks
cd ~/.claude/skills/handoff && bash hooks/install.shThe installer registers all 4 hooks automatically.
AUTO_HANDOFF_DEBUG=1 # Context monitoring logs
PRE_COMPACT_DEBUG=1 # Pre-compact snapshot logs
SESSION_RESTORE_DEBUG=1 # Session restore scoring logs- Single-node only: File locking uses local filesystem locks.
claude-handoff-baton/
├── SKILL.md # The skill (copy to ~/.claude/commands/)
├── README.md
├── hooks/
│ ├── utils.mjs # Shared utilities (lock, state I/O, token tracking)
│ ├── constants.mjs # Shared constants, thresholds, security patterns
│ ├── schema.mjs # JSON schema for structured handoff output
│ ├── task-size-estimator.mjs # PrePromptSubmit: Task size detection
│ ├── auto-handoff.mjs # PostToolUse: Context monitoring
│ ├── auto-checkpoint.mjs # PostToolUse: Time/token-based checkpoint trigger
│ ├── pre-compact.mjs # PreCompact: Metadata snapshot before compaction
│ ├── session-restore.mjs # SessionStart: Context restoration after compact/resume
│ ├── lockfile.mjs # Lock file management for interrupted handoffs
│ ├── recover.mjs # Recovery script for interrupted handoffs
│ ├── install.sh # Easy installation (registers all 4 hooks)
│ └── test-task-size.mjs # Integration tests
├── plugins/
│ └── handoff/
│ ├── plugin.json # Plugin manifest (v2.2)
│ └── skills/
│ └── handoff.md # Skill definition with smart auto-scaling
└── examples/
└── example-handoff.md
MIT License - See LICENSE for details.
Issues and PRs welcome at GitHub.
Ready to pass the baton? Run /handoff — don't pass raw history, pass distilled knowledge.
