Managing session continuity across Claude conversations by saving structured context (tasks, files, errors, git state) to JSON and loading in new sessions...
Session state mgmt: context → JSON → restore
/save-session-protocol or /load-session-protocol invokedPurpose: Capture state → sp.json
Steps:
Check session state
Extract context
.git exists):[ -d .git ] && {
git rev-parse --abbrev-ref HEAD 2>/dev/null # branch
git rev-parse HEAD 2>/dev/null # commit
}
Consolidate tasks (decision: 3+ = consolidate)
If 3+ → group into 1 task w/ consolidated=true + summary
Consolidation format:
{
"id": "TASK_XXX",
"title": "Redesign homepage layout",
"status": "completed",
"consolidated": true,
"consolidated_count": 12,
"context": "Summary: Redesigned nav, hero, footer. Pitfall: CSS grid safari compat. See: docs/homepage-plan.md",
"completed": "2025-11-26T14:00:00Z"
}
Build JSON (minified, no pretty-print)
Write
Report
Purpose: Parse sp.json → restore state
Steps:
Read + parse
Validate git (if metadata has git fields AND .git exists)
[ -d .git ] && {
curr=$(git rev-parse HEAD 2>/dev/null)
curr_br=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
[ "$curr" != "$saved_commit" ] && warn "Git state changed"
[ "$curr_br" != "$saved_branch" ] && warn "Branch: $saved → $curr_br"
}
Build summary
Present
{
"metadata": {
"version": "2.0",
"created": "2025-11-26T10:00:00Z",
"updated": "2025-11-26T14:00:00Z",
"git_branch": "feature/auth",
"git_commit": "abc123f5d2e8a1b4c6e9f3a7"
},
"tasks": [
{
"id": "TASK_001",
"title": "Fix auth middleware",
"status": "pending",
"priority": "P1",
"category": "BUGFIX",
"created": "2025-11-26T10:00:00Z",
"completed": null,
"consolidated": false,
"consolidated_count": 0,
"context": "JWT RS256 validation fails. PEM format req. See: src/auth/middleware.ts:45",
"files": ["src/auth/middleware.ts:45", "config/jwt.ts:12"]
},
{
"id": "TASK_010",
"title": "Redesign homepage",
"status": "completed",
"priority": "P2",
"category": "FEATURE",
"created": "2025-11-20T09:00:00Z",
"completed": "2025-11-24T18:00:00Z",
"consolidated": true,
"consolidated_count": 12,
"context": "Redesigned nav, hero, footer (12 tasks). Pitfall: CSS grid Safari compat fixed with -webkit-. Plan: docs/homepage-plan.md",
"files": ["docs/homepage-plan.md"]
}
],
"context_blocks": [
{
"title": "JWT Auth Setup",
"content": "RS256 algo. Pub key: ~/config/jwt-keys/public.pem. TTL: 1h access, 7d refresh. Rotation: monthly",
"updated": "2025-11-26T14:00:00Z",
"related_tasks": ["TASK_001"]
}
]
}
metadata (req):
tasks (req, arr, ≥1):
context_blocks (opt, arr):
Decision (3+ = consolidate):
If 3+ → create consolidated task:
Keep individual (never consolidate):
Invoked by:
/save-session-protocol → WF1/load-session-protocol → WF2Save (fresh session):
User: "Save progress"
Claude: [Check: protocol not loaded → skip Read]
[Extract: 3 pend, 8 done → consolidate 5 old → 3 remain]
[Git: .git exists → capture state]
Saved 3 pend, 3 done (5 consolidated). Next: TASK_001 - Fix auth
Load:
User: "Load session"
Claude: Loaded (2d old)
- 3 pend, 3 done (5 consolidated into 1)
- Next: TASK_001 - Fix auth middleware
- Git: state changed (2 commits ahead)
Save:
Saved → sp.json
- 5 pend (2 P1, 3 P2)
- 8 done (3 individual, 1 consolidated from 12)
- Git: feature/auth @ abc123f
Next: TASK_001 - Fix JWT validation
Load:
Loaded sp.json (2d old)
- 3 pend, 1 prog, 8 done (1 consolidated from 12)
- Git: feature/auth @ abc123f (2 commits ahead)
Next: TASK_001 - Fix JWT validation