claude-code-handoff 2.0.1 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +64 -14
- package/cli.js +10 -10
- package/commands/context-doctor.md +96 -0
- package/commands/handoff.md +16 -1
- package/commands/resume.md +5 -9
- package/commands/save-handoff.md +10 -3
- package/install.sh +12 -14
- package/package.json +2 -2
- package/rules/session-continuity.md +5 -21
- package/uninstall.sh +1 -0
- package/update.sh +44 -9
package/README.md
CHANGED
|
@@ -36,7 +36,7 @@ Either way, you lose. Auto-compact gives you a degraded Claude that forgets. Man
|
|
|
36
36
|
|
|
37
37
|
## The Solution
|
|
38
38
|
|
|
39
|
-
Instead of relying on lossy compression or starting from zero, **claude-code-handoff** gives Claude **structured persistent memory** —
|
|
39
|
+
Instead of relying on lossy compression or starting from zero, **claude-code-handoff** gives Claude **structured persistent memory** — 7 slash commands that capture exactly what matters and restore it cleanly:
|
|
40
40
|
|
|
41
41
|
| Command | Description |
|
|
42
42
|
|---------|-------------|
|
|
@@ -46,6 +46,7 @@ Instead of relying on lossy compression or starting from zero, **claude-code-han
|
|
|
46
46
|
| `/switch-context <topic>` | Switch between parallel workstreams |
|
|
47
47
|
| `/delete-handoff` | Delete one or more saved handoffs |
|
|
48
48
|
| `/auto-handoff` | Enable/disable auto-handoff or adjust threshold |
|
|
49
|
+
| `/context-doctor` | Diagnose context bloat and optimize token usage |
|
|
49
50
|
|
|
50
51
|
The workflow becomes: work until context is full → `/handoff` → `/clear` → `/resume` → continue with full context. No degradation, no amnesia. Just clean handoffs.
|
|
51
52
|
|
|
@@ -110,8 +111,7 @@ flowchart TD
|
|
|
110
111
|
C -->|Yes| E[Present interactive picker]
|
|
111
112
|
E --> F[User selects session]
|
|
112
113
|
F --> G[Load full handoff]
|
|
113
|
-
G -->
|
|
114
|
-
H --> I[Present summary + next steps]
|
|
114
|
+
G --> I[Present summary + next steps]
|
|
115
115
|
I --> J[Wait for user instruction]
|
|
116
116
|
```
|
|
117
117
|
|
|
@@ -199,8 +199,8 @@ The threshold is configured as a **percentage of your plan's context window**. T
|
|
|
199
199
|
|
|
200
200
|
| Preset | Value | Triggers at (200K) | Triggers at (500K) | Best for |
|
|
201
201
|
|--------|-------|---------------------|---------------------|----------|
|
|
202
|
-
| **90
|
|
203
|
-
| **80
|
|
202
|
+
| **90%** | `THRESHOLD_PERCENT=90` | 180K tokens | 450K tokens | Maximizing context usage |
|
|
203
|
+
| **80% (default)** | `THRESHOLD_PERCENT=80` | 160K tokens | 400K tokens | Balance between space and safety |
|
|
204
204
|
| **75%** | `THRESHOLD_PERCENT=75` | 150K tokens | 375K tokens | Short sessions, early handoff |
|
|
205
205
|
|
|
206
206
|
The calculation uses real data:
|
|
@@ -246,7 +246,7 @@ claude: Which threshold do you want?
|
|
|
246
246
|
```bash
|
|
247
247
|
# In .claude/hooks/context-monitor.sh, change the defaults:
|
|
248
248
|
MAX_CONTEXT_TOKENS=${CLAUDE_MAX_CONTEXT:-200000} # change 200000 to your value
|
|
249
|
-
THRESHOLD_PERCENT=${CLAUDE_CONTEXT_THRESHOLD:-
|
|
249
|
+
THRESHOLD_PERCENT=${CLAUDE_CONTEXT_THRESHOLD:-80} # change 80 to your value
|
|
250
250
|
```
|
|
251
251
|
|
|
252
252
|
### Safety Mechanisms
|
|
@@ -304,9 +304,10 @@ your-project/
|
|
|
304
304
|
│ ├── save-handoff.md ← /save-handoff (wizard)
|
|
305
305
|
│ ├── switch-context.md ← /switch-context (workstream switch)
|
|
306
306
|
│ ├── delete-handoff.md ← /delete-handoff (remove handoffs)
|
|
307
|
-
│
|
|
307
|
+
│ ├── auto-handoff.md ← /auto-handoff (on/off + threshold)
|
|
308
|
+
│ └── context-doctor.md ← /context-doctor (diagnose bloat)
|
|
308
309
|
├── rules/
|
|
309
|
-
│ ├── session-continuity.md ← Auto-loaded behavioral rules
|
|
310
|
+
│ ├── session-continuity.md ← Auto-loaded behavioral rules (lean, ~10 lines)
|
|
310
311
|
│ └── auto-handoff.md ← Auto-handoff trigger rules
|
|
311
312
|
├── hooks/
|
|
312
313
|
│ ├── context-monitor.sh ← Stop hook (monitors context size)
|
|
@@ -486,7 +487,7 @@ graph TD
|
|
|
486
487
|
R["/resume"]
|
|
487
488
|
R --> R1["Lists all sessions"]
|
|
488
489
|
R --> R2["Shows summary per session"]
|
|
489
|
-
R --> R3["
|
|
490
|
+
R --> R3["Lists key files (no read)"]
|
|
490
491
|
end
|
|
491
492
|
|
|
492
493
|
subgraph "Switch"
|
|
@@ -507,18 +508,61 @@ graph TD
|
|
|
507
508
|
| **When** | Before `/clear` | When you need options | Start of session | Mid-session | Anytime |
|
|
508
509
|
| **Interactive** | No | Yes (wizard) | Yes (picker) | No (with arg) | Yes (wizard) |
|
|
509
510
|
| **Creates files** | Auto | User chooses | No | Auto | Toggle file |
|
|
510
|
-
| **Reads files** | `_active.md` | `_active.md` + `archive/` |
|
|
511
|
+
| **Reads files** | `_active.md` | `_active.md` + `archive/` | Handoff only (no key files) | `_active.md` + target | Hook config |
|
|
511
512
|
|
|
512
513
|
---
|
|
513
514
|
|
|
515
|
+
## Context Optimization (v2.1)
|
|
516
|
+
|
|
517
|
+
Every line in `CLAUDE.md` and `rules/` costs tokens on **every single message**. v2.1 aggressively minimizes the always-on footprint:
|
|
518
|
+
|
|
519
|
+
| Component | v2.0 | v2.1 | Savings |
|
|
520
|
+
|-----------|------|------|---------|
|
|
521
|
+
| `session-continuity.md` (rule) | 28 lines | 10 lines | -64% |
|
|
522
|
+
| CLAUDE.md section | 5 lines + auto-read | 2 lines, no auto-read | -60% |
|
|
523
|
+
| `/resume` Key File read | 50 lines | 0 (removed) | -100% |
|
|
524
|
+
| Handoff compaction | 200 line limit | 100 line limit, auto-compact | -50% |
|
|
525
|
+
|
|
526
|
+
**Estimated savings: ~5-6K tokens per message** for projects with moderate CLAUDE.md and rules.
|
|
527
|
+
|
|
528
|
+
### `/context-doctor` — Diagnose context bloat
|
|
529
|
+
|
|
530
|
+
Run `/context-doctor` to get a full audit of your context usage:
|
|
531
|
+
|
|
532
|
+
```
|
|
533
|
+
you: /context-doctor
|
|
534
|
+
claude: ## Context Health Report
|
|
535
|
+
|
|
536
|
+
### Always-on context (loaded every message)
|
|
537
|
+
| Source | Lines | Est. tokens | Status |
|
|
538
|
+
|----------------|-------|-------------|---------|
|
|
539
|
+
| CLAUDE.md | 260 | ~3900 | BLOATED |
|
|
540
|
+
| rules/mcp.md | 176 | ~2640 | BLOATED |
|
|
541
|
+
| rules/cont.md | 10 | ~150 | OK |
|
|
542
|
+
| **Total** | **446** | **~6690** | — |
|
|
543
|
+
|
|
544
|
+
### Recommendations
|
|
545
|
+
1. Move rules/mcp.md to commands/ (saves ~2640 tokens/message)
|
|
546
|
+
2. Trim CLAUDE.md: remove code examples on lines 117-145
|
|
547
|
+
3. Compact handoff: 8 sessions → keep last 3
|
|
548
|
+
|
|
549
|
+
Want me to apply any of these optimizations?
|
|
550
|
+
```
|
|
551
|
+
|
|
552
|
+
### Tips for users
|
|
553
|
+
|
|
554
|
+
1. **Move reference docs from `rules/` to `commands/`** — Rules are loaded every message. Commands are loaded only when invoked. If a rules file has >50 lines and is mostly reference material, move it to `commands/`.
|
|
555
|
+
2. **Keep CLAUDE.md lean** — Remove generic instructions ("write clean code", error handling patterns, debugging tips). Claude already knows these. Only keep project-specific rules and guardrails.
|
|
556
|
+
3. **Run `/context-doctor` after installing new tools** — MCP rules, agent definitions, and framework configs can bloat context silently.
|
|
557
|
+
|
|
514
558
|
## Behavioral Rules
|
|
515
559
|
|
|
516
|
-
The installer adds a `session-continuity.md` rules file that Claude auto-loads on every session
|
|
560
|
+
The installer adds a lean `session-continuity.md` rules file (~10 lines) that Claude auto-loads on every session:
|
|
517
561
|
|
|
518
562
|
- **On session start**: Claude knows `_active.md` exists but doesn't read it unless asked
|
|
519
563
|
- **During work**: Claude proactively reminds you to save after significant milestones
|
|
520
|
-
- **Command awareness**: Claude understands all
|
|
521
|
-
- **Auto-handoff awareness**: When the context monitor triggers, Claude
|
|
564
|
+
- **Command awareness**: Claude understands all 7 commands natively
|
|
565
|
+
- **Auto-handoff awareness**: When the context monitor triggers, Claude saves the handoff immediately
|
|
522
566
|
|
|
523
567
|
---
|
|
524
568
|
|
|
@@ -555,7 +599,7 @@ curl -fsSL https://raw.githubusercontent.com/eximIA-Ventures/claude-code-handoff
|
|
|
555
599
|
```
|
|
556
600
|
|
|
557
601
|
The uninstaller:
|
|
558
|
-
- Removes all
|
|
602
|
+
- Removes all 7 command files (including legacy `auto-handoff-toggle.md`)
|
|
559
603
|
- Removes rules and hooks
|
|
560
604
|
- Cleans hooks from `settings.json` (requires `jq`)
|
|
561
605
|
- Preserves handoff data if sessions exist (won't delete your session history)
|
|
@@ -609,6 +653,12 @@ A: Yes. Run `/auto-handoff` and select "Disable", or manually delete `.claude/ho
|
|
|
609
653
|
**Q: What if auto-handoff triggers too early/late?**
|
|
610
654
|
A: Adjust the threshold. If it triggers too early, increase to 95%. If you're running out of context before it triggers, lower to 80% or 75%. Use `/auto-handoff` to change it interactively.
|
|
611
655
|
|
|
656
|
+
**Q: My context fills up too fast. What can I do?**
|
|
657
|
+
A: Run `/context-doctor` to audit your always-on context (CLAUDE.md + rules/). Common fixes: move large rules files to commands/ (on-demand loading), trim generic boilerplate from CLAUDE.md, and compact old handoff sessions. See the [Context Optimization](#context-optimization-v21) section.
|
|
658
|
+
|
|
659
|
+
**Q: What changed in v2.1?**
|
|
660
|
+
A: v2.1 focuses on context efficiency: leaner rules file (28→10 lines), no auto-read on session start (saves double reading), `/resume` no longer reads Key Files by default (saves ~50 lines), handoff compaction at 3 sessions (100 line target), and new `/context-doctor` diagnostic command.
|
|
661
|
+
|
|
612
662
|
---
|
|
613
663
|
|
|
614
664
|
## Contributing
|
package/cli.js
CHANGED
|
@@ -26,7 +26,7 @@ const SCRIPT_DIR = __dirname;
|
|
|
26
26
|
// ─── Banner ───────────────────────────────────────────
|
|
27
27
|
console.log('');
|
|
28
28
|
console.log(` ${AMBER}${BOLD}┌──────────────────────────────────────┐${NC}`);
|
|
29
|
-
console.log(` ${AMBER}${BOLD}│${NC} ${WHITE}${BOLD}claude-code-handoff${NC} ${DIM}
|
|
29
|
+
console.log(` ${AMBER}${BOLD}│${NC} ${WHITE}${BOLD}claude-code-handoff${NC} ${DIM}v2.1${NC} ${AMBER}${BOLD}│${NC}`);
|
|
30
30
|
console.log(` ${AMBER}${BOLD}│${NC} ${GRAY}Session Continuity for Claude Code${NC} ${AMBER}${BOLD}│${NC}`);
|
|
31
31
|
console.log(` ${AMBER}${BOLD}└──────────────────────────────────────┘${NC}`);
|
|
32
32
|
console.log('');
|
|
@@ -86,7 +86,8 @@ copyFile('commands/switch-context.md', path.join(CLAUDE_DIR, 'commands', 'switch
|
|
|
86
86
|
copyFile('commands/handoff.md', path.join(CLAUDE_DIR, 'commands', 'handoff.md'));
|
|
87
87
|
copyFile('commands/delete-handoff.md', path.join(CLAUDE_DIR, 'commands', 'delete-handoff.md'));
|
|
88
88
|
copyFile('commands/auto-handoff.md', path.join(CLAUDE_DIR, 'commands', 'auto-handoff.md'));
|
|
89
|
-
|
|
89
|
+
copyFile('commands/context-doctor.md', path.join(CLAUDE_DIR, 'commands', 'context-doctor.md'));
|
|
90
|
+
ok('7 slash commands installed');
|
|
90
91
|
|
|
91
92
|
// ─── Rules ────────────────────────────────────────────
|
|
92
93
|
head('Installing rules');
|
|
@@ -199,11 +200,9 @@ if (fs.existsSync(gitignorePath)) {
|
|
|
199
200
|
head('Updating CLAUDE.md');
|
|
200
201
|
|
|
201
202
|
const claudeMdPath = path.join(CLAUDE_DIR, 'CLAUDE.md');
|
|
202
|
-
const continuityBlock = `## Session Continuity
|
|
203
|
+
const continuityBlock = `## Session Continuity
|
|
203
204
|
|
|
204
|
-
|
|
205
|
-
During work, update the handoff proactively after significant milestones.
|
|
206
|
-
Use \`/handoff\` before \`/clear\`. Use \`/resume\` to pick up. Use \`/switch-context <topic>\` to switch workstreams.`;
|
|
205
|
+
Use \`/resume\` to pick up from a previous session. Use \`/handoff\` before \`/clear\` to save.`;
|
|
207
206
|
|
|
208
207
|
if (fs.existsSync(claudeMdPath)) {
|
|
209
208
|
const content = fs.readFileSync(claudeMdPath, 'utf-8');
|
|
@@ -237,17 +236,17 @@ if (cleaned > 0) info(`Removed ${cleaned} legacy command(s)`);
|
|
|
237
236
|
head('Verifying');
|
|
238
237
|
|
|
239
238
|
let installed = 0;
|
|
240
|
-
for (const f of ['resume.md', 'save-handoff.md', 'switch-context.md', 'handoff.md', 'delete-handoff.md', 'auto-handoff.md']) {
|
|
239
|
+
for (const f of ['resume.md', 'save-handoff.md', 'switch-context.md', 'handoff.md', 'delete-handoff.md', 'auto-handoff.md', 'context-doctor.md']) {
|
|
241
240
|
if (fs.existsSync(path.join(CLAUDE_DIR, 'commands', f))) installed++;
|
|
242
241
|
}
|
|
243
242
|
let hooksOk = 0;
|
|
244
243
|
if (fs.existsSync(path.join(CLAUDE_DIR, 'hooks', 'context-monitor.sh'))) hooksOk++;
|
|
245
244
|
if (fs.existsSync(path.join(CLAUDE_DIR, 'hooks', 'session-cleanup.sh'))) hooksOk++;
|
|
246
245
|
|
|
247
|
-
if (installed ===
|
|
248
|
-
ok(`${installed}/
|
|
246
|
+
if (installed === 7 && hooksOk === 2) {
|
|
247
|
+
ok(`${installed}/7 commands, ${hooksOk}/2 hooks`);
|
|
249
248
|
} else {
|
|
250
|
-
fail(`Partial: ${installed}/
|
|
249
|
+
fail(`Partial: ${installed}/7 commands, ${hooksOk}/2 hooks`);
|
|
251
250
|
}
|
|
252
251
|
|
|
253
252
|
// ─── Done ─────────────────────────────────────────────
|
|
@@ -263,6 +262,7 @@ console.log(` ${CYAN}/save-handoff${NC} ${GRAY}Save with options${NC}`)
|
|
|
263
262
|
console.log(` ${CYAN}/switch-context${NC} ${GRAY}Switch workstream${NC}`);
|
|
264
263
|
console.log(` ${CYAN}/delete-handoff${NC} ${GRAY}Delete handoff(s)${NC}`);
|
|
265
264
|
console.log(` ${CYAN}/auto-handoff${NC} ${GRAY}Toggle auto-handoff${NC}`);
|
|
265
|
+
console.log(` ${CYAN}/context-doctor${NC} ${GRAY}Diagnose context bloat${NC}`);
|
|
266
266
|
console.log('');
|
|
267
267
|
console.log(` ${WHITE}${BOLD}Auto-handoff:${NC} ${DIM}beta — disabled by default${NC}`);
|
|
268
268
|
console.log(` ${GRAY}Run ${CYAN}/auto-handoff${GRAY} inside Claude Code to enable${NC}`);
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# Context Doctor
|
|
2
|
+
|
|
3
|
+
Diagnose context usage and recommend optimizations to maximize your usable context window.
|
|
4
|
+
|
|
5
|
+
## Instructions
|
|
6
|
+
|
|
7
|
+
### Step 1: Audit always-loaded files
|
|
8
|
+
|
|
9
|
+
These files are loaded into Claude's context on **every single message**:
|
|
10
|
+
|
|
11
|
+
1. **CLAUDE.md**: Read `.claude/CLAUDE.md` and count lines
|
|
12
|
+
2. **Rules**: List all `.md` files in `.claude/rules/` — for each, count lines and note the filename
|
|
13
|
+
3. **Global CLAUDE.md**: Check if the project has a parent CLAUDE.md (from `~/.claude/CLAUDE.md`) — note if it exists
|
|
14
|
+
|
|
15
|
+
Calculate total "always-on" lines (CLAUDE.md + all rules).
|
|
16
|
+
|
|
17
|
+
### Step 2: Audit handoff size
|
|
18
|
+
|
|
19
|
+
1. Read `.claude/handoffs/_active.md` and count lines
|
|
20
|
+
2. Count session entries (### Session N patterns)
|
|
21
|
+
3. Check if compaction is needed (>3 sessions or >100 lines)
|
|
22
|
+
|
|
23
|
+
### Step 3: Scan for bloat patterns
|
|
24
|
+
|
|
25
|
+
Check CLAUDE.md for common bloat patterns:
|
|
26
|
+
- Code examples (```...```) — these consume many tokens for little value
|
|
27
|
+
- Generic rules that Claude already knows (error handling patterns, "write clean code", "follow best practices")
|
|
28
|
+
- Duplicate instructions (same info in CLAUDE.md AND rules/)
|
|
29
|
+
- Environment setup / debugging tips
|
|
30
|
+
- Long lists of "NEVER do X" (>10 items)
|
|
31
|
+
|
|
32
|
+
Check rules/ for:
|
|
33
|
+
- Files >50 lines (likely too verbose)
|
|
34
|
+
- Content that could be a command/skill instead (loaded on-demand)
|
|
35
|
+
|
|
36
|
+
### Step 4: Present report
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
## Context Health Report
|
|
40
|
+
|
|
41
|
+
### Always-on context (loaded every message)
|
|
42
|
+
| Source | Lines | Est. tokens | Status |
|
|
43
|
+
|--------|-------|-------------|--------|
|
|
44
|
+
| CLAUDE.md | X | ~Y | [OK/BLOATED] |
|
|
45
|
+
| rules/file1.md | X | ~Y | [OK/BLOATED] |
|
|
46
|
+
| rules/file2.md | X | ~Y | [OK/BLOATED] |
|
|
47
|
+
| **Total** | **X** | **~Y** | — |
|
|
48
|
+
|
|
49
|
+
### Handoff state
|
|
50
|
+
- Active handoff: X lines, N sessions
|
|
51
|
+
- [NEEDS COMPACTION / OK]
|
|
52
|
+
|
|
53
|
+
### Recommendations
|
|
54
|
+
[numbered list of specific, actionable recommendations]
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Token estimation
|
|
58
|
+
Use this rough formula: `tokens ≈ lines × 15` (average for markdown with code).
|
|
59
|
+
|
|
60
|
+
### Recommendation templates
|
|
61
|
+
|
|
62
|
+
Use these as appropriate:
|
|
63
|
+
|
|
64
|
+
1. **"Move rules/X.md to commands/"** — When a rules file is >50 lines and contains reference material (not behavioral rules). Moving to commands/ makes it a skill that's only loaded when invoked.
|
|
65
|
+
- Action: `mv .claude/rules/X.md .claude/commands/X.md` and remove the `paths:` frontmatter
|
|
66
|
+
|
|
67
|
+
2. **"Trim CLAUDE.md"** — When CLAUDE.md has code examples, generic best practices, or debug tips.
|
|
68
|
+
- Action: Remove generic content. Keep only project-specific rules and critical guardrails.
|
|
69
|
+
|
|
70
|
+
3. **"Compact handoff"** — When handoff has >3 sessions or >100 lines.
|
|
71
|
+
- Action: Run `/handoff` which will auto-compact, or manually edit `_active.md`.
|
|
72
|
+
|
|
73
|
+
4. **"Split rules file"** — When a rules file has both behavioral rules AND reference docs.
|
|
74
|
+
- Action: Keep behavioral rules (short, <20 lines) in rules/. Move reference docs to commands/.
|
|
75
|
+
|
|
76
|
+
5. **"Remove duplicate instructions"** — When the same info appears in CLAUDE.md and rules/.
|
|
77
|
+
- Action: Keep in one place only.
|
|
78
|
+
|
|
79
|
+
### Step 5: Offer to fix
|
|
80
|
+
|
|
81
|
+
After presenting the report, ask:
|
|
82
|
+
|
|
83
|
+
Question: "Want me to apply any of these optimizations?"
|
|
84
|
+
Header: "Fix"
|
|
85
|
+
Options:
|
|
86
|
+
- "Apply all recommendations" — "Automatically fix all issues found"
|
|
87
|
+
- "Let me choose" — "I'll tell you which ones to apply"
|
|
88
|
+
- "Just the report" — "No changes, I'll handle it manually"
|
|
89
|
+
|
|
90
|
+
If the user chooses "Apply all" or specific fixes, execute them.
|
|
91
|
+
|
|
92
|
+
## Important
|
|
93
|
+
- This is a READ-ONLY diagnostic by default — only modify files if the user explicitly approves
|
|
94
|
+
- Be specific in recommendations — "Remove lines 45-80 from CLAUDE.md (code examples)" not "trim CLAUDE.md"
|
|
95
|
+
- Show before/after line counts when making changes
|
|
96
|
+
- Never remove content from rules/ without explaining what it does and confirming
|
package/commands/handoff.md
CHANGED
|
@@ -109,10 +109,25 @@ This command exists because:
|
|
|
109
109
|
2. **Context-aware** — it appends to the active handoff if the workstream matches, or creates a new one if it doesn't.
|
|
110
110
|
3. **Pre-clear workflow** — the natural flow is: work → `/handoff` → `/clear` → `/resume`.
|
|
111
111
|
|
|
112
|
+
## Compaction Rule
|
|
113
|
+
|
|
114
|
+
When a handoff exceeds 3 session entries in "What Was Done":
|
|
115
|
+
1. Keep the **last 3 sessions** in full detail
|
|
116
|
+
2. Merge all older sessions into a single **"Prior Sessions Summary (1-N)"** section with 1-2 bullet points each
|
|
117
|
+
3. Example:
|
|
118
|
+
```markdown
|
|
119
|
+
### Prior Sessions Summary (1-5)
|
|
120
|
+
- Sessions 1-2: Initial setup, D1-D4 decided
|
|
121
|
+
- Session 3: Refactored auth module
|
|
122
|
+
- Sessions 4-5: API integration, E2E tests added
|
|
123
|
+
```
|
|
124
|
+
4. Target: keep the entire handoff under **100 lines**
|
|
125
|
+
5. The Decisions Registry is NEVER compacted — all decisions are preserved
|
|
126
|
+
|
|
112
127
|
## Important
|
|
113
128
|
- Be THOROUGH — extract everything relevant from the conversation
|
|
114
129
|
- Be PRECISE — file paths, specific changes, exact error messages
|
|
115
130
|
- Be ACTIONABLE — next steps should be specific enough to execute cold
|
|
116
131
|
- NEVER delete existing handoff data — always append or archive
|
|
117
|
-
- Keep under
|
|
132
|
+
- Keep under 100 lines — compact older sessions aggressively
|
|
118
133
|
- If conversation is very short or trivial, still save (even a one-liner is better than nothing)
|
package/commands/resume.md
CHANGED
|
@@ -27,23 +27,18 @@ Header: "Handoff"
|
|
|
27
27
|
Once the user selects, read the full handoff file and extract:
|
|
28
28
|
- Active Workstream
|
|
29
29
|
- Active Agent(s)
|
|
30
|
-
- What Was Done (last session summary)
|
|
30
|
+
- What Was Done (last session summary only)
|
|
31
31
|
- What's Next (pending items)
|
|
32
|
-
- Key Files
|
|
32
|
+
- Key Files (list only — do NOT read the files)
|
|
33
33
|
- Decisions Registry (if any)
|
|
34
34
|
|
|
35
|
-
### Step 4:
|
|
36
|
-
|
|
37
|
-
If **Key Files** lists a main document (Current Document field), read the first 50 lines of it.
|
|
38
|
-
|
|
39
|
-
### Step 5: Present context
|
|
35
|
+
### Step 4: Present context
|
|
40
36
|
|
|
41
37
|
```
|
|
42
38
|
## Resuming session
|
|
43
39
|
|
|
44
40
|
**Workstream:** [name]
|
|
45
41
|
**Agent(s):** [active agents]
|
|
46
|
-
**Document:** [main file]
|
|
47
42
|
**Last updated:** [date]
|
|
48
43
|
|
|
49
44
|
### Last session summary
|
|
@@ -57,7 +52,7 @@ If **Key Files** lists a main document (Current Document field), read the first
|
|
|
57
52
|
What would you like to do?
|
|
58
53
|
```
|
|
59
54
|
|
|
60
|
-
### Step
|
|
55
|
+
### Step 5: Wait
|
|
61
56
|
|
|
62
57
|
Wait for user instruction before proceeding.
|
|
63
58
|
|
|
@@ -70,4 +65,5 @@ If `$ARGUMENTS` is provided (e.g., `/resume auth-refactor`), skip the wizard:
|
|
|
70
65
|
## Important
|
|
71
66
|
- Do NOT activate any agent automatically — let the user decide
|
|
72
67
|
- Do NOT start working — only present context and wait
|
|
68
|
+
- Do NOT read Key Files — just list them. The user can ask to read specific files when needed
|
|
73
69
|
- If the handoff references an agent (e.g., @architect), mention it but don't activate
|
package/commands/save-handoff.md
CHANGED
|
@@ -125,11 +125,18 @@ If `$ARGUMENTS` is provided:
|
|
|
125
125
|
- If it matches an existing archive name: update that specific archive file directly (skip wizard)
|
|
126
126
|
- Otherwise: treat as the name for a new context (skip wizard, go to "Save as new context" flow)
|
|
127
127
|
|
|
128
|
+
## Compaction Rule
|
|
129
|
+
|
|
130
|
+
When a handoff exceeds 3 session entries in "What Was Done":
|
|
131
|
+
1. Keep the **last 3 sessions** in full detail
|
|
132
|
+
2. Merge all older sessions into a single **"Prior Sessions Summary (1-N)"** section with 1-2 bullet points each
|
|
133
|
+
3. Target: keep the entire handoff under **100 lines**
|
|
134
|
+
4. The Decisions Registry is NEVER compacted — all decisions are preserved
|
|
135
|
+
|
|
128
136
|
## Important
|
|
129
137
|
- NEVER delete or overwrite without archiving first — always move to archive/
|
|
130
|
-
- PRESERVE session history — append, don't replace
|
|
138
|
+
- PRESERVE session history — append, don't replace (but compact older sessions)
|
|
131
139
|
- Be PRECISE — file paths, decision IDs, specific changes
|
|
132
140
|
- Be ACTIONABLE — someone reading cold should know exactly what to do
|
|
133
|
-
- Keep CONCISE — target <
|
|
134
|
-
- If a handoff exceeds 300 lines, summarize older sessions into "Prior Sessions Summary"
|
|
141
|
+
- Keep CONCISE — target <100 lines per handoff
|
|
135
142
|
- Slug derivation: lowercase, trim, replace spaces/special chars with hyphens, max 40 chars
|
package/install.sh
CHANGED
|
@@ -31,7 +31,7 @@ head() { echo -e "\n ${AMBER}${BOLD}$1${RESET}"; }
|
|
|
31
31
|
# ─── Banner ───────────────────────────────────────────
|
|
32
32
|
echo ""
|
|
33
33
|
echo -e " ${AMBER}${BOLD}┌──────────────────────────────────────┐${RESET}"
|
|
34
|
-
echo -e " ${AMBER}${BOLD}│${RESET} ${WHITE}${BOLD}claude-code-handoff${RESET} ${DIM}
|
|
34
|
+
echo -e " ${AMBER}${BOLD}│${RESET} ${WHITE}${BOLD}claude-code-handoff${RESET} ${DIM}v2.1${RESET} ${AMBER}${BOLD}│${RESET}"
|
|
35
35
|
echo -e " ${AMBER}${BOLD}│${RESET} ${GRAY}Session Continuity for Claude Code${RESET} ${AMBER}${BOLD}│${RESET}"
|
|
36
36
|
echo -e " ${AMBER}${BOLD}└──────────────────────────────────────┘${RESET}"
|
|
37
37
|
echo ""
|
|
@@ -87,7 +87,8 @@ download_file "commands/switch-context.md" "$CLAUDE_DIR/commands/switch-context.
|
|
|
87
87
|
download_file "commands/handoff.md" "$CLAUDE_DIR/commands/handoff.md"
|
|
88
88
|
download_file "commands/delete-handoff.md" "$CLAUDE_DIR/commands/delete-handoff.md"
|
|
89
89
|
download_file "commands/auto-handoff.md" "$CLAUDE_DIR/commands/auto-handoff.md"
|
|
90
|
-
|
|
90
|
+
download_file "commands/context-doctor.md" "$CLAUDE_DIR/commands/context-doctor.md"
|
|
91
|
+
ok "7 slash commands installed"
|
|
91
92
|
|
|
92
93
|
# ─── Rules ────────────────────────────────────────────
|
|
93
94
|
head "Installing rules"
|
|
@@ -303,11 +304,9 @@ if [ -f "$CLAUDE_MD" ]; then
|
|
|
303
304
|
/^# / && !done {
|
|
304
305
|
print
|
|
305
306
|
print ""
|
|
306
|
-
print "## Session Continuity
|
|
307
|
+
print "## Session Continuity"
|
|
307
308
|
print ""
|
|
308
|
-
print "
|
|
309
|
-
print "During work, update the handoff proactively after significant milestones."
|
|
310
|
-
print "Use `/handoff` before `/clear`. Use `/resume` to pick up. Use `/switch-context <topic>` to switch workstreams."
|
|
309
|
+
print "Use `/resume` to pick up from a previous session. Use `/handoff` before `/clear` to save."
|
|
311
310
|
print ""
|
|
312
311
|
done=1
|
|
313
312
|
next
|
|
@@ -323,11 +322,9 @@ else
|
|
|
323
322
|
cat > "$CLAUDE_MD" << 'CLAUDEMD'
|
|
324
323
|
# Project Rules
|
|
325
324
|
|
|
326
|
-
## Session Continuity
|
|
325
|
+
## Session Continuity
|
|
327
326
|
|
|
328
|
-
|
|
329
|
-
During work, update the handoff proactively after significant milestones.
|
|
330
|
-
Use `/handoff` before `/clear`. Use `/resume` to pick up. Use `/switch-context <topic>` to switch workstreams.
|
|
327
|
+
Use `/resume` to pick up from a previous session. Use `/handoff` before `/clear` to save.
|
|
331
328
|
CLAUDEMD
|
|
332
329
|
ok "CLAUDE.md created"
|
|
333
330
|
fi
|
|
@@ -348,17 +345,17 @@ fi
|
|
|
348
345
|
head "Verifying"
|
|
349
346
|
|
|
350
347
|
INSTALLED=0
|
|
351
|
-
for f in resume.md save-handoff.md switch-context.md handoff.md delete-handoff.md auto-handoff.md; do
|
|
348
|
+
for f in resume.md save-handoff.md switch-context.md handoff.md delete-handoff.md auto-handoff.md context-doctor.md; do
|
|
352
349
|
[ -f "$CLAUDE_DIR/commands/$f" ] && INSTALLED=$((INSTALLED + 1))
|
|
353
350
|
done
|
|
354
351
|
HOOKS_OK=0
|
|
355
352
|
[ -f "$CLAUDE_DIR/hooks/context-monitor.sh" ] && HOOKS_OK=$((HOOKS_OK + 1))
|
|
356
353
|
[ -f "$CLAUDE_DIR/hooks/session-cleanup.sh" ] && HOOKS_OK=$((HOOKS_OK + 1))
|
|
357
354
|
|
|
358
|
-
if [ "$INSTALLED" -eq
|
|
359
|
-
ok "${INSTALLED}/
|
|
355
|
+
if [ "$INSTALLED" -eq 7 ] && [ "$HOOKS_OK" -eq 2 ]; then
|
|
356
|
+
ok "${INSTALLED}/7 commands, ${HOOKS_OK}/2 hooks"
|
|
360
357
|
else
|
|
361
|
-
fail "Partial: ${INSTALLED}/
|
|
358
|
+
fail "Partial: ${INSTALLED}/7 commands, ${HOOKS_OK}/2 hooks"
|
|
362
359
|
fi
|
|
363
360
|
|
|
364
361
|
# ─── Done ─────────────────────────────────────────────
|
|
@@ -374,6 +371,7 @@ echo -e " ${CYAN}/save-handoff${RESET} ${GRAY}Save with options${RESET}
|
|
|
374
371
|
echo -e " ${CYAN}/switch-context${RESET} ${GRAY}Switch workstream${RESET}"
|
|
375
372
|
echo -e " ${CYAN}/delete-handoff${RESET} ${GRAY}Delete handoff(s)${RESET}"
|
|
376
373
|
echo -e " ${CYAN}/auto-handoff${RESET} ${GRAY}Toggle auto-handoff${RESET}"
|
|
374
|
+
echo -e " ${CYAN}/context-doctor${RESET} ${GRAY}Diagnose context bloat${RESET}"
|
|
377
375
|
echo ""
|
|
378
376
|
echo -e " ${WHITE}${BOLD}Auto-handoff:${RESET} ${DIM}beta — disabled by default${RESET}"
|
|
379
377
|
echo -e " ${GRAY}Run ${CYAN}/auto-handoff${GRAY} inside Claude Code to enable${RESET}"
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "claude-code-handoff",
|
|
3
|
-
"version": "2.0
|
|
4
|
-
"description": "Session continuity for Claude Code —
|
|
3
|
+
"version": "2.1.0",
|
|
4
|
+
"description": "Session continuity for Claude Code — 7 slash commands to save, resume, diagnose, and switch workstreams across /clear",
|
|
5
5
|
"bin": {
|
|
6
6
|
"claude-code-handoff": "./cli.js"
|
|
7
7
|
},
|
|
@@ -2,26 +2,10 @@
|
|
|
2
2
|
paths: **/*
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
-
# Session Continuity
|
|
5
|
+
# Session Continuity
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
This project uses `.claude/handoffs/` for session continuity across `/clear`.
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
- If `.claude/handoffs/_active.md` exists and has content, be aware of it but do NOT read it automatically unless the user invokes `/resume` or says "continue"/"resume"
|
|
13
|
-
|
|
14
|
-
### During Work
|
|
15
|
-
- After completing significant milestones (major edits, decisions made, features implemented), proactively update the handoff by writing to `.claude/handoffs/_active.md`
|
|
16
|
-
- If the session has been going for a while and substantial work was done, remind the user: "Want me to save the handoff before continuing?"
|
|
17
|
-
|
|
18
|
-
### Handoff Structure
|
|
19
|
-
- `_active.md` — current active workstream (the ONE thing being worked on now)
|
|
20
|
-
- `archive/` — paused or completed workstreams (switched via `/switch-context`)
|
|
21
|
-
|
|
22
|
-
### Commands Available
|
|
23
|
-
- `/resume` — resume from active handoff (interactive wizard)
|
|
24
|
-
- `/resume <topic>` — resume from a specific archived handoff
|
|
25
|
-
- `/save-handoff` — save current state (interactive wizard)
|
|
26
|
-
- `/switch-context <topic>` — switch workstream (archives current, loads target)
|
|
27
|
-
- `/handoff` — auto-save session state (no wizard, just save and go)
|
|
9
|
+
- Do NOT read `_active.md` automatically — wait for `/resume` or user saying "continue"/"resume"
|
|
10
|
+
- After significant milestones, remind: "Want me to save the handoff?"
|
|
11
|
+
- Commands: `/resume`, `/handoff`, `/save-handoff`, `/switch-context`, `/delete-handoff`, `/auto-handoff`
|
package/uninstall.sh
CHANGED
|
@@ -34,6 +34,7 @@ rm -f "$CLAUDE_DIR/commands/save-handoff.md"
|
|
|
34
34
|
rm -f "$CLAUDE_DIR/commands/switch-context.md"
|
|
35
35
|
rm -f "$CLAUDE_DIR/commands/delete-handoff.md"
|
|
36
36
|
rm -f "$CLAUDE_DIR/commands/auto-handoff.md"
|
|
37
|
+
rm -f "$CLAUDE_DIR/commands/context-doctor.md"
|
|
37
38
|
# Also remove legacy commands if present
|
|
38
39
|
rm -f "$CLAUDE_DIR/commands/auto-handoff-toggle.md"
|
|
39
40
|
# Also remove legacy Portuguese commands if present
|
package/update.sh
CHANGED
|
@@ -18,7 +18,7 @@ CLAUDE_DIR="$PROJECT_DIR/.claude"
|
|
|
18
18
|
|
|
19
19
|
echo ""
|
|
20
20
|
echo -e "${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
|
21
|
-
echo -e "${CYAN} claude-code-handoff — Update${NC}"
|
|
21
|
+
echo -e "${CYAN} claude-code-handoff — Update v2.1${NC}"
|
|
22
22
|
echo -e "${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
|
23
23
|
echo ""
|
|
24
24
|
echo -e " Project: ${GREEN}$PROJECT_DIR${NC}"
|
|
@@ -45,21 +45,22 @@ download_file() {
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
# 1. Update commands
|
|
48
|
-
echo -e " ${YELLOW}[1/
|
|
48
|
+
echo -e " ${YELLOW}[1/6]${NC} Updating commands..."
|
|
49
49
|
download_file "commands/handoff.md" "$CLAUDE_DIR/commands/handoff.md"
|
|
50
50
|
download_file "commands/resume.md" "$CLAUDE_DIR/commands/resume.md"
|
|
51
51
|
download_file "commands/save-handoff.md" "$CLAUDE_DIR/commands/save-handoff.md"
|
|
52
52
|
download_file "commands/switch-context.md" "$CLAUDE_DIR/commands/switch-context.md"
|
|
53
53
|
download_file "commands/delete-handoff.md" "$CLAUDE_DIR/commands/delete-handoff.md"
|
|
54
54
|
download_file "commands/auto-handoff.md" "$CLAUDE_DIR/commands/auto-handoff.md"
|
|
55
|
+
download_file "commands/context-doctor.md" "$CLAUDE_DIR/commands/context-doctor.md"
|
|
55
56
|
|
|
56
57
|
# 2. Update rules
|
|
57
|
-
echo -e " ${YELLOW}[2/
|
|
58
|
+
echo -e " ${YELLOW}[2/6]${NC} Updating rules..."
|
|
58
59
|
download_file "rules/session-continuity.md" "$CLAUDE_DIR/rules/session-continuity.md"
|
|
59
60
|
download_file "rules/auto-handoff.md" "$CLAUDE_DIR/rules/auto-handoff.md"
|
|
60
61
|
|
|
61
62
|
# 3. Update hooks (preserving user configuration)
|
|
62
|
-
echo -e " ${YELLOW}[3/
|
|
63
|
+
echo -e " ${YELLOW}[3/6]${NC} Updating hooks..."
|
|
63
64
|
mkdir -p "$CLAUDE_DIR/hooks"
|
|
64
65
|
|
|
65
66
|
# Save user's custom settings before overwriting
|
|
@@ -76,8 +77,8 @@ chmod +x "$CLAUDE_DIR/hooks/context-monitor.sh"
|
|
|
76
77
|
chmod +x "$CLAUDE_DIR/hooks/session-cleanup.sh"
|
|
77
78
|
|
|
78
79
|
# Restore user's custom settings
|
|
79
|
-
if [ -n "$SAVED_THRESHOLD" ] && [ "$SAVED_THRESHOLD" != "
|
|
80
|
-
sed -i.bak "s/CLAUDE_CONTEXT_THRESHOLD:-
|
|
80
|
+
if [ -n "$SAVED_THRESHOLD" ] && [ "$SAVED_THRESHOLD" != "80" ]; then
|
|
81
|
+
sed -i.bak "s/CLAUDE_CONTEXT_THRESHOLD:-80/CLAUDE_CONTEXT_THRESHOLD:-${SAVED_THRESHOLD}/" "$CLAUDE_DIR/hooks/context-monitor.sh"
|
|
81
82
|
rm -f "$CLAUDE_DIR/hooks/context-monitor.sh.bak"
|
|
82
83
|
echo -e " Preserved threshold: ${CYAN}${SAVED_THRESHOLD}%${NC}"
|
|
83
84
|
fi
|
|
@@ -88,7 +89,7 @@ if [ -n "$SAVED_MAX_CONTEXT" ] && [ "$SAVED_MAX_CONTEXT" != "200000" ]; then
|
|
|
88
89
|
fi
|
|
89
90
|
|
|
90
91
|
# 4. Ensure hooks are configured in settings.json
|
|
91
|
-
echo -e " ${YELLOW}[4/
|
|
92
|
+
echo -e " ${YELLOW}[4/6]${NC} Checking settings.json hooks..."
|
|
92
93
|
SETTINGS_FILE="$CLAUDE_DIR/settings.json"
|
|
93
94
|
if [ -f "$SETTINGS_FILE" ]; then
|
|
94
95
|
if ! grep -q "context-monitor" "$SETTINGS_FILE" 2>/dev/null; then
|
|
@@ -106,8 +107,38 @@ else
|
|
|
106
107
|
echo -e " ${YELLOW}⚠ settings.json not found — run install first${NC}"
|
|
107
108
|
fi
|
|
108
109
|
|
|
109
|
-
# 5.
|
|
110
|
-
echo -e " ${YELLOW}[5/
|
|
110
|
+
# 5. Migrate CLAUDE.md (v2.1: remove mandatory read, slim down)
|
|
111
|
+
echo -e " ${YELLOW}[5/6]${NC} Migrating CLAUDE.md..."
|
|
112
|
+
CLAUDE_MD="$CLAUDE_DIR/CLAUDE.md"
|
|
113
|
+
MIGRATED=false
|
|
114
|
+
if [ -f "$CLAUDE_MD" ]; then
|
|
115
|
+
# Replace old verbose section with lean version
|
|
116
|
+
if grep -q "At the START of every session, read" "$CLAUDE_MD" 2>/dev/null; then
|
|
117
|
+
TEMP_FILE=$(mktemp)
|
|
118
|
+
awk '
|
|
119
|
+
/## Session Continuity/ {
|
|
120
|
+
print "## Session Continuity"
|
|
121
|
+
print ""
|
|
122
|
+
print "Use `/resume` to pick up from a previous session. Use `/handoff` before `/clear` to save."
|
|
123
|
+
skip=1
|
|
124
|
+
next
|
|
125
|
+
}
|
|
126
|
+
skip && /^## / && !/Session Continuity/ {
|
|
127
|
+
skip=0
|
|
128
|
+
}
|
|
129
|
+
skip { next }
|
|
130
|
+
{ print }
|
|
131
|
+
' "$CLAUDE_MD" > "$TEMP_FILE"
|
|
132
|
+
mv "$TEMP_FILE" "$CLAUDE_MD"
|
|
133
|
+
MIGRATED=true
|
|
134
|
+
echo -e " ${GREEN}Migrated: removed auto-read rule (saves ~3K tokens/message)${NC}"
|
|
135
|
+
else
|
|
136
|
+
echo -e " Already up to date"
|
|
137
|
+
fi
|
|
138
|
+
fi
|
|
139
|
+
|
|
140
|
+
# 6. Remove legacy files if present
|
|
141
|
+
echo -e " ${YELLOW}[6/6]${NC} Cleaning up legacy files..."
|
|
111
142
|
CLEANED=0
|
|
112
143
|
for f in retomar.md salvar-handoff.md trocar-contexto.md auto-handoff-toggle.md; do
|
|
113
144
|
if [ -f "$CLAUDE_DIR/commands/$f" ]; then
|
|
@@ -121,7 +152,11 @@ echo -e "${GREEN} Updated successfully!${NC}"
|
|
|
121
152
|
if [ "$CLEANED" -gt 0 ]; then
|
|
122
153
|
echo -e " Removed $CLEANED legacy command(s)"
|
|
123
154
|
fi
|
|
155
|
+
if [ "$MIGRATED" = true ]; then
|
|
156
|
+
echo -e " ${CYAN}CLAUDE.md migrated to lean format (context optimization)${NC}"
|
|
157
|
+
fi
|
|
124
158
|
echo ""
|
|
125
159
|
echo -e " Handoff data in .claude/handoffs/ was ${CYAN}not touched${NC}."
|
|
126
160
|
echo -e " Auto-handoff settings (threshold, plan, on/off) were ${CYAN}preserved${NC}."
|
|
161
|
+
echo -e " ${CYAN}New:${NC} /context-doctor — diagnose context bloat"
|
|
127
162
|
echo ""
|