Shell
Session-Resilient Development System
Status: PLANNING
Created: 2025-11-28 Last Updated: 2025-11-28 Session: Initial Planning
Problem Statement
Context windows are ephemeral, but work shouldn't be. When sessions timeout or crash:
- Plans are lost
- Progress is unclear
- Tool/agent assignments forgotten
- Work must be reconstructed from scratch
Requirements (Confirmed with User)
| Requirement | Details |
|---|---|
| Scope | Global - all projects, not just id8 |
| SDK Agents | Initializer + Coding agent |
| Slash Commands | For invoking patterns |
| Hooks | Auto-save on session events |
| Testing | Automatic via Playwright MCP |
| Progress Tracking | .claude-progress.txt + Notion sync |
| Plan Persistence | Save to file with tool assignments |
| Crash Recovery | Checkpoints, resumable anywhere |
Core Components to Build
1. SDK Agents (TypeScript)
-
session-initializer- Project scaffolding -
session-coder- Incremental progress with auto-testing
2. Slash Commands
-
/init-project- Run initializer -
/resume- Continue from last checkpoint -
/save-state- Force save current state -
/status- Show current progress
3. Hooks
-
on-session-start- Load state, read progress -
on-session-end- Auto-commit, sync Notion -
on-plan-create- Persist plan to file
4. Progress System
-
.claude-progress.txtformat spec -
claude-plan.jsonformat spec - Notion integration for cloud backup
5. Plan Persistence Format
Plans should include:
- Task description
- Assigned agents/subagents
- Assigned MCPs/plugins
- Checkpoints with status
- Tool configurations
Exploration Completed
Existing Infrastructure (Highly Sophisticated)
- 37 specialized agents (Leonardo strategist, KRANG brain, operations-manager, etc.)
- 18 automation hooks (verify-after-write, auto-commit, progress-report, etc.)
- 18 slash commands (/start, /test, /fix, /ship, /status, etc.)
- 17 plugins (agent-sdk-dev, testing-suite, git-workflow, etc.)
- 8 MCP servers (Notion, Supabase, Playwright, GitHub, Perplexity, Firecrawl)
Key Existing Patterns to Leverage
verify-after-write.sh/verify-after-edit.sh- Verification hooksprogress-report.sh- Progress loggingmilestone-tracker.sh- Milestone trackingauto-commit.sh/auto-git-workflow.sh- Git automation/start [name]- Feature branch creation/status- Project state report
Agent SDK Dev Plugin
- Already installed at
~/.claude/plugins/marketplaces/claude-code-plugins/plugins/agent-sdk-dev - Can use
/agent-sdk-dev:new-sdk-appto scaffold new agents - No existing Agent SDK projects yet (using direct Anthropic SDK)
Critical Files to Modify
~/.claude/CLAUDE.md- Add session resilience instructions~/.claude/settings.local.json- Add new hooks~/.claude/hooks.json- Register new hooks~/.claude/commands/- Add new slash commands~/.claude/agents/- Add new agent definitions
Synthesized Implementation Plan
Architecture: Hybrid Approach
Combines best of both perspectives:
- SDK Agents: Standalone TypeScript project at
~/Development/session-resilience-agents/ - Claude Code Integration: Extend existing hooks and commands in
~/.claude/ - State Persistence: Local checkpoints + Notion sync (dual redundancy)
- Testing: Playwright MCP auto-testing integrated into coding agent
Why Hybrid?
| Aspect | Decision | Rationale |
|---|---|---|
| Agent Location | ~/Development/ |
Standalone project, version-controlled, reusable |
| Integration | Extend existing hooks | Leverage 18 hooks already in place |
| Commands | New + Extend existing | /resume, /save-state new; /start, /status extended |
| State | Local + Notion | Crash recovery (local) + Cloud backup (Notion) |
Implementation Phases
Phase 1: SDK Agent Project Setup
Goal: Scaffold TypeScript Agent SDK project
- Run
/agent-sdk-dev:new-sdk-app session-resilience-agents - Configure MCP connections (Notion, Playwright)
- Create state directory structure
- Define TypeScript schemas for session state
Files Created:
~/Development/session-resilience-agents/
├── package.json
├── src/
│ ├── agents/
│ │ ├── initializer-agent.ts
│ │ └── coding-agent.ts
│ ├── tools/
│ │ ├── notion-sync.ts
│ │ ├── checkpoint-manager.ts
│ │ └── playwright-runner.ts
│ └── schemas/
│ └── session-state.ts
└── state/
├── sessions/
└── checkpoints/
Phase 2: Session State System
Goal: Implement state persistence with crash recovery
Session State Schema:
{
"session_id": "uuid",
"project_path": "/path/to/project",
"notion_page_id": "abc123",
"plan": {
"file": "~/.claude/plans/plan-name.md",
"tasks": [
{
"id": "task-001",
"description": "Implement feature X",
"status": "in_progress",
"assigned_agent": "code-reviewer",
"assigned_mcp": ["playwright"],
"checkpoint": "CP-003"
}
]
},
"context": {
"files_modified": [],
"decisions_made": [],
"last_activity": "2025-11-28T12:00:00Z"
},
"recovery_instructions": "Continue with task-002..."
}
Checkpoint Strategy (User Confirmed):
- Auto-checkpoint every 5 significant tool uses (balanced)
- Also checkpoint on task completion
- Also checkpoint before test runs
Recovery Behavior (User Confirmed):
- Auto-prompt on session start if crashed session detected
- Show recovery options (files modified, current task, decisions)
- User chooses: Resume, Start Fresh, or Review Plan
Notion Setup (User Confirmed):
- Create NEW "Claude Sessions" database
- Link from existing workspace
Phase 3: Slash Commands
Goal: Create/extend commands for session control
| Command | Type | Purpose |
|---|---|---|
/resume |
NEW | Load session from checkpoint, continue work |
/save-state |
NEW | Force checkpoint, sync to Notion |
/start |
EXTEND | Add session initialization |
/status |
EXTEND | Show session state, progress |
Phase 4: Hooks Integration
Goal: Extend existing hooks for auto-persistence
| Hook | Action |
|---|---|
session-persist.sh (NEW) |
Save state after Write/Edit |
session-recovery-check.sh (NEW) |
Check for crashed session on start |
progress-report.sh (EXTEND) |
Add session state to progress |
verify-after-write.sh (EXTEND) |
Trigger Playwright after changes |
Phase 5: Notion Integration
Goal: Cloud backup and visibility
- Create "Claude Sessions" database in Notion
- Schema: Session ID, Status, Project, Progress %, Last Updated
- Sync triggers: session start, checkpoint, task completion, session end
Phase 6: Auto-Testing Integration
Goal: Playwright runs automatically after code changes
- Detect project test config (playwright.config.ts)
- Run relevant tests after code changes
- Update session state with test results
- Screenshot on failure for evidence
CLAUDE.md Additions
## Session Resilience Protocol
### On Session Start
1. Check for incomplete sessions: `~/.claude/session-state/`
2. If found, prompt: "Resume session from [checkpoint]?"
3. Run `/resume` to continue or `/start` for fresh session
### During Work
- State auto-saves after every code change
- Use `/save-state` for immediate checkpoint
- Plans persist with tool/agent assignments
### On Crash Recovery
1. Next session detects incomplete work
2. `/resume` shows: files modified, decisions made, current task
3. Continue from last checkpoint
### Progress Tracking
- Local: `.claude-progress.txt` in project
- Cloud: Notion "Claude Sessions" database
- Plans: `~/.claude/plans/` with checkpoints
File Modification Summary
| File | Action |
|---|---|
~/Development/session-resilience-agents/ |
CREATE (SDK project) |
~/.claude/commands/resume.md |
CREATE |
~/.claude/commands/save-state.md |
CREATE |
~/.claude/commands/start.md |
EXTEND |
~/.claude/commands/status.md |
EXTEND |
~/.claude/hooks/session-persist.sh |
CREATE |
~/.claude/hooks/session-recovery-check.sh |
CREATE |
~/.claude/hooks/progress-report.sh |
EXTEND |
~/.claude/settings.local.json |
EXTEND (add hooks) |
~/.claude/CLAUDE.md |
EXTEND (add protocol) |
Checkpoints
- Requirements gathered
- Existing setup explored (37 agents, 18 hooks, 18 commands found)
- Architecture designed (Hybrid: SDK agents + extend existing)
- User decisions captured:
- Checkpoint frequency: Every 5 changes
- Notion: Create new database
- Recovery: Auto-prompt on session start
- Plan approved by user
- Implementation started
- SDK project created (
~/Development/session-resilience-agents/) - Slash commands created (
/resume,/save-state) - Hooks created and registered
- CLAUDE.md updated with Session Resilience Protocol
- Notion database setup (user action required)
- End-to-end testing
Resume Instructions
If this session crashes, the next session should:
- Read this file at
~/.claude/plans/zany-inventing-whistle.md - Check the "Checkpoints" section for current status
- Continue from the last incomplete checkpoint
Implementation Order (Ready to Execute)
- Phase 1: Scaffold SDK project with
/agent-sdk-dev:new-sdk-app - Phase 2: Create session state schemas and checkpoint manager
- Phase 3: Create
/resumeand/save-stateslash commands - Phase 4: Create hooks (
session-persist.sh,session-recovery-check.sh) - Phase 5: Set up Notion database and sync integration
- Phase 6: Integrate Playwright auto-testing
- Phase 7: Extend
/startand/statuscommands - Phase 8: Update CLAUDE.md with Session Resilience Protocol
- Phase 9: Test crash recovery workflow end-to-end
Critical Files to Read Before Implementation
~/.claude/settings.local.json- Current hooks configuration~/.claude/hooks/progress-report.sh- Existing progress pattern~/.claude/commands/start.md- Existing start command to extend~/.claude/agents/operations-manager.md- Agent coordination pattern~/.claude/agents/krang-brain-agent.md- Project brain pattern for state