Managing Session Continuity
Session state mgmt: context → JSON → restore
When to Use
- Session end w/ unfinished work
- New session w/ sp.json exists
- User: "save|load|resume session|progress|work"
/save-session-protocol or /load-session-protocol invoked
Core Workflows
WF1: Save Context
Purpose: Capture state → sp.json
Steps:
Check session state
- Protocol loaded this session? → Skip Read (overwrite)
- Protocol NOT loaded? → Read sp.json (merge)
Extract context
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)
- Schema: see JSON Format
- Task IDs: TASK_XXX (sequential, unique)
- Timestamps: ISO8601 UTC (YYYY-MM-DDTHH:MM:SSZ)
- Privacy: strip usernames from paths (~/project not /Users/john/project)
Write
- Write(sp.json) minified format
Report
- "Saved X pend, Y done (Z consolidated). Next: TASK_XXX"
WF2: Load Context
Purpose: Parse sp.json → restore state
Steps:
Read + parse
- Read(sp.json)
- Extract: metadata, tasks[], context_blocks[]
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
- Age: calc from metadata.created
- Counts: pend/prog/done (note consolidated count)
- Next: first pend/prog
- Warnings: git drift (if any)
Present
- Concise: counts, next action, warnings
JSON Format
Schema
{
"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"]
}
]
}
Fields
metadata (req):
- version: "2.0"
- created/updated: ISO8601
- git_branch/git_commit: str|null
tasks (req, arr, ≥1):
- id: "TASK_XXX"
- title: str
- status: "pending"|"in_progress"|"completed"
- priority: "P1"|"P2"|"P3" (opt)
- category: BUGFIX|FEATURE|CONFIG|DOCS|TEST|REFACTOR (opt)
- created: ISO8601
- completed: ISO8601|null
- consolidated: bool (true if grouped from multiple)
- consolidated_count: int (# of original tasks if consolidated)
- context: str (opt, include: summary, pitfalls, plan refs, file refs)
- files: arr[str] (opt, path:line format, rel or ~/)
context_blocks (opt, arr):
- title: str
- content: str (arch decisions, error patterns, critical pitfalls)
- updated: ISO8601
- related_tasks: arr[task_id] (opt)
Format Rules
- Minified JSON: no whitespace, single line
- Timestamps: UTC w/ Z suffix
- Completed limit: ≤5 individual + consolidated groups (no hard limit on consolidated)
- Privacy:
- Paths: ~/ or relative (never /Users/username/ or C:\Users\username)
- No emails, API keys, tokens, credentials, personal info
- Task IDs: sequential (TASK_001, TASK_002...)
Consolidation Matrix
Decision (3+ = consolidate):
If 3+ → create consolidated task:
- title: feature/area name
- consolidated: true
- consolidated_count: N
- context: summary + pitfalls + file refs
- completed: last task completion ts
Keep individual (never consolidate):
- Critical bugs w/ specific fixes
- Tasks w/ unique pitfalls/lessons
- Recent (<3 days) completed
- Tasks referenced by pending work
Tool Usage
- Write: sp.json (minified)
- Read: sp.json (if not loaded this session) or existing (if merge needed)
- Bash: git ops (only if .git exists)
Integration
Invoked by:
/save-session-protocol → WF1
/load-session-protocol → WF2
Examples
Save (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)
Error Handling
- No .git → skip git (no error)
- Invalid JSON → error "Cannot load: invalid JSON"
- Missing metadata → error "Cannot load: missing metadata"
- Never fail silently
Output Format
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
1---2name: managing-session-continuity3description: Managing session continuity across Claude conversations by saving structured context (tasks, files, errors, git state) to JSON and loading in new sessions. Use when user asks how session continuity works, explaining session protocol functionality, understanding session state management, describing what gets saved in sessions, ending a session with unfinished work, starting a session with existing session-protocol.json, or when user mentions 'save progress', 'save session', 'save my work', 'continue later', 'session context', 'pick up where left off', 'load session', 'restore session', or explicitly invokes /save-session-protocol or /load-session-protocol commands.4---5
6# Managing Session Continuity
7
8Session state mgmt: context → JSON → restore
9
10## When to Use
11
12- Session end w/ unfinished work
13- New session w/ sp.json exists
14- User: "save|load|resume session|progress|work"
15- `/save-session-protocol` or `/load-session-protocol` invoked
16
17## Core Workflows
18
19### WF1: Save Context
20
21**Purpose**: Capture state → sp.json
22
23**Steps**:
24
251. **Check session state**
26 - Protocol loaded this session? → Skip Read (overwrite)
27 - Protocol NOT loaded? → Read sp.json (merge)
28
292. **Extract context**
30 - Pending/in_progress: ALL from TodoWrite
31 - Completed: last 5 individual + consolidate older (see consolidation matrix)
32 - Context blocks: arch decisions, critical pitfalls, error patterns, plan file refs
33 - Git (if `.git` exists):
34 ```bash
35 [ -d .git ] && {
36 git rev-parse --abbrev-ref HEAD 2>/dev/null # branch
37 git rev-parse HEAD 2>/dev/null # commit
38 }
39 ```
40
413. **Consolidate tasks** (decision: 3+ = consolidate)
42 - [ ] Same feature/area (e.g., "redesign page X")
43 - [ ] >5 related completed tasks
44 - [ ] No critical findings to preserve individually
45 - [ ] >3 days since last task in group
46
47 If 3+ → group into 1 task w/ consolidated=true + summary
48
49 **Consolidation format**:
50 ```json
51 {
52 "id": "TASK_XXX",
53 "title": "Redesign homepage layout",
54 "status": "completed",
55 "consolidated": true,
56 "consolidated_count": 12,
57 "context": "Summary: Redesigned nav, hero, footer. Pitfall: CSS grid safari compat. See: docs/homepage-plan.md",
58 "completed": "2025-11-26T14:00:00Z"
59 }
60 ```
61
624. **Build JSON** (minified, no pretty-print)
63 - Schema: see JSON Format
64 - Task IDs: TASK_XXX (sequential, unique)
65 - Timestamps: ISO8601 UTC (YYYY-MM-DDTHH:MM:SSZ)
66 - Privacy: strip usernames from paths (~/project not /Users/john/project)
67
685. **Write**
69 - Write(sp.json) minified format
70
716. **Report**
72 - "Saved X pend, Y done (Z consolidated). Next: TASK_XXX"
73
74### WF2: Load Context
75
76**Purpose**: Parse sp.json → restore state
77
78**Steps**:
79
801. **Read + parse**
81 - Read(sp.json)
82 - Extract: metadata, tasks[], context_blocks[]
83
842. **Validate git** (if metadata has git fields AND .git exists)
85 ```bash
86 [ -d .git ] && {
87 curr=$(git rev-parse HEAD 2>/dev/null)
88 curr_br=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
89 [ "$curr" != "$saved_commit" ] && warn "Git state changed"
90 [ "$curr_br" != "$saved_branch" ] && warn "Branch: $saved → $curr_br"
91 }
92 ```
93
943. **Build summary**
95 - Age: calc from metadata.created
96 - Counts: pend/prog/done (note consolidated count)
97 - Next: first pend/prog
98 - Warnings: git drift (if any)
99
1004. **Present**
101 - Concise: counts, next action, warnings
102
103## JSON Format
104
105### Schema
106
107```json
108{
109 "metadata": {
110 "version": "2.0",
111 "created": "2025-11-26T10:00:00Z",
112 "updated": "2025-11-26T14:00:00Z",
113 "git_branch": "feature/auth",
114 "git_commit": "abc123f5d2e8a1b4c6e9f3a7"
115 },
116 "tasks": [
117 {
118 "id": "TASK_001",
119 "title": "Fix auth middleware",
120 "status": "pending",
121 "priority": "P1",
122 "category": "BUGFIX",
123 "created": "2025-11-26T10:00:00Z",
124 "completed": null,
125 "consolidated": false,
126 "consolidated_count": 0,
127 "context": "JWT RS256 validation fails. PEM format req. See: src/auth/middleware.ts:45",
128 "files": ["src/auth/middleware.ts:45", "config/jwt.ts:12"]
129 },
130 {
131 "id": "TASK_010",
132 "title": "Redesign homepage",
133 "status": "completed",
134 "priority": "P2",
135 "category": "FEATURE",
136 "created": "2025-11-20T09:00:00Z",
137 "completed": "2025-11-24T18:00:00Z",
138 "consolidated": true,
139 "consolidated_count": 12,
140 "context": "Redesigned nav, hero, footer (12 tasks). Pitfall: CSS grid Safari compat fixed with -webkit-. Plan: docs/homepage-plan.md",
141 "files": ["docs/homepage-plan.md"]
142 }
143 ],
144 "context_blocks": [
145 {
146 "title": "JWT Auth Setup",
147 "content": "RS256 algo. Pub key: ~/config/jwt-keys/public.pem. TTL: 1h access, 7d refresh. Rotation: monthly",
148 "updated": "2025-11-26T14:00:00Z",
149 "related_tasks": ["TASK_001"]
150 }
151 ]
152}
153```
154
155### Fields
156
157**metadata** (req):
158- version: "2.0"
159- created/updated: ISO8601
160- git_branch/git_commit: str|null
161
162**tasks** (req, arr, ≥1):
163- id: "TASK_XXX"
164- title: str
165- status: "pending"|"in_progress"|"completed"
166- priority: "P1"|"P2"|"P3" (opt)
167- category: BUGFIX|FEATURE|CONFIG|DOCS|TEST|REFACTOR (opt)
168- created: ISO8601
169- completed: ISO8601|null
170- consolidated: bool (true if grouped from multiple)
171- consolidated_count: int (# of original tasks if consolidated)
172- context: str (opt, include: summary, pitfalls, plan refs, file refs)
173- files: arr[str] (opt, path:line format, rel or ~/)
174
175**context_blocks** (opt, arr):
176- title: str
177- content: str (arch decisions, error patterns, critical pitfalls)
178- updated: ISO8601
179- related_tasks: arr[task_id] (opt)
180
181### Format Rules
182
183- **Minified JSON**: no whitespace, single line
184- **Timestamps**: UTC w/ Z suffix
185- **Completed limit**: ≤5 individual + consolidated groups (no hard limit on consolidated)
186- **Privacy**:
187 - Paths: ~/ or relative (never /Users/username/ or C:\Users\username\)
188 - No emails, API keys, tokens, credentials, personal info
189- **Task IDs**: sequential (TASK_001, TASK_002...)
190
191## Consolidation Matrix
192
193Decision (3+ = consolidate):
194- [ ] Same feature/area
195- [ ] >5 related completed tasks
196- [ ] No critical findings to preserve individually
197- [ ] >3 days since last task in group
198
199If 3+ → create consolidated task:
200- title: feature/area name
201- consolidated: true
202- consolidated_count: N
203- context: summary + pitfalls + file refs
204- completed: last task completion ts
205
206**Keep individual** (never consolidate):
207- Critical bugs w/ specific fixes
208- Tasks w/ unique pitfalls/lessons
209- Recent (<3 days) completed
210- Tasks referenced by pending work
211
212## Tool Usage
213
214- **Write**: sp.json (minified)
215- **Read**: sp.json (if not loaded this session) or existing (if merge needed)
216- **Bash**: git ops (only if .git exists)
217
218## Integration
219
220Invoked by:
221- `/save-session-protocol` → WF1
222- `/load-session-protocol` → WF2
223
224## Examples
225
226**Save (fresh session)**:
227```
228User: "Save progress"
229Claude: [Check: protocol not loaded → skip Read]
230 [Extract: 3 pend, 8 done → consolidate 5 old → 3 remain]
231 [Git: .git exists → capture state]
232 Saved 3 pend, 3 done (5 consolidated). Next: TASK_001 - Fix auth
233```
234
235**Load**:
236```
237User: "Load session"
238Claude: Loaded (2d old)
239 - 3 pend, 3 done (5 consolidated into 1)
240 - Next: TASK_001 - Fix auth middleware
241 - Git: state changed (2 commits ahead)
242```
243
244## Error Handling
245
246- No .git → skip git (no error)
247- Invalid JSON → error "Cannot load: invalid JSON"
248- Missing metadata → error "Cannot load: missing metadata"
249- Never fail silently
250
251## Output Format
252
253**Save**:
254```
255Saved → sp.json
256- 5 pend (2 P1, 3 P2)
257- 8 done (3 individual, 1 consolidated from 12)
258- Git: feature/auth @ abc123f
259Next: TASK_001 - Fix JWT validation
260```
261
262**Load**:
263```
264Loaded sp.json (2d old)
265- 3 pend, 1 prog, 8 done (1 consolidated from 12)
266- Git: feature/auth @ abc123f (2 commits ahead)
267Next: TASK_001 - Fix JWT validation
268```