Browse Source

feat: Add session-manager submodule for unified session state

- Add session-manager as submodule (commands/session-manager/)
- Remove standalone save.md and load.md (now in submodule)
- Session-manager provides: /status, /save, /load commands
- Unified state model: plan awareness + TodoWrite persistence

The session-manager submodule provides:
- /status: Dashboard view of plan + tasks + git state
- /save: Persist session state with plan context
- /load: Restore session with plan awareness

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
0xDarkMatter 4 months ago
parent
commit
d9f084eb7b
4 changed files with 4 additions and 429 deletions
  1. 3 0
      .gitmodules
  2. 0 218
      commands/load.md
  3. 0 211
      commands/save.md
  4. 1 0
      commands/session-manager

+ 3 - 0
.gitmodules

@@ -1,3 +1,6 @@
 [submodule "commands/g-slave"]
 	path = commands/g-slave
 	url = https://github.com/0xDarkMatter/g-slave.git
+[submodule "commands/session-manager"]
+	path = commands/session-manager
+	url = https://github.com/0xDarkMatter/session-manager.git

+ 0 - 218
commands/load.md

@@ -1,218 +0,0 @@
----
-description: "Load session context from saved state. Reads claude-state.json and claude-progress.md, shows what changed, suggests next action."
----
-
-# Load - Restore Session Context
-
-Load your session context from a previous save. Reads state files, shows what's changed since, and suggests the next action.
-
-## Why This Exists
-
-This command pairs with `/save` to implement structured session continuity. Claude Code's `--resume` restores conversation history, but **TodoWrite task state does not persist by design**.
-
-This is intentional—Claude Code treats each session as isolated. TodoWrite tasks are stored at `~/.claude/todos/[session-id].json` and deleted when the session ends. The philosophy is that persistent state belongs in files you control.
-
-From Anthropic's [Effective Harnesses for Long-Running Agents](https://www.anthropic.com/engineering/effective-harnesses-for-long-running-agents):
-
-> "Every subsequent session asks the model to make incremental progress, then leave structured updates."
-
-`/load` reads those structured updates and restores your working context:
-- **Tasks** are restored to TodoWrite
-- **Git context** shows what changed since you left
-- **Notes** remind you where you stopped
-- **Suggested action** helps you pick up immediately
-
-### How It Differs from `--resume`
-
-| `claude --resume` | `/load` |
-|-------------------|---------|
-| Restores conversation history | Restores task state from files |
-| Internal storage | Git-trackable files |
-| Local to your machine | Portable across machines |
-| Automatic | Explicit (you control when) |
-
-**Use both together**: `claude --resume` for conversation context, `/load` for task state.
-
-## Arguments
-
-$ARGUMENTS
-
-If no arguments, read from default `.claude/` location.
-
-## What This Command Does
-
-1. **Read State Files**
-   - Load `.claude/claude-state.json`
-   - Load `.claude/claude-progress.md`
-
-2. **Analyze Changes Since Save**
-   - Git commits since last save
-   - File modifications
-   - Time elapsed
-
-3. **Restore TodoWrite State**
-   - Populate TodoWrite with saved tasks
-   - Preserve status (completed, in-progress, pending)
-
-4. **Suggest Next Action**
-   - Based on in-progress tasks
-   - Highlight blockers or notes
-
-## Execution Steps
-
-### Step 1: Check for State Files
-
-```bash
-ls -la .claude/claude-state.json .claude/claude-progress.md 2>/dev/null
-```
-
-If missing, report:
-```
-⚠ No saved state found in .claude/
-
-To create one, use: /save
-```
-
-### Step 2: Read State
-
-Parse `.claude/claude-state.json`:
-- Extract timestamp
-- Extract task arrays
-- Extract context (branch, last commit, notes)
-
-### Step 3: Calculate Time Since Save
-
-Compare save timestamp to current time:
-- Format as human-readable ("2 hours ago", "3 days ago")
-
-### Step 4: Analyze Git Changes
-
-```bash
-# Commits since save
-git log --oneline <last_commit>..HEAD
-
-# Current status
-git status --short
-```
-
-### Step 5: Restore TodoWrite
-
-Use TodoWrite tool to restore tasks:
-- Map `completed` → status: "completed"
-- Map `in_progress` → status: "in_progress"
-- Map `pending` → status: "pending"
-
-### Step 6: Display Summary
-
-```markdown
-# Session Loaded
-
-**Saved**: <timestamp> (<relative time>)
-**Branch**: <branch>
-
-## Since Last Save
-- <N> new commits
-- <M> files modified
-- <time> elapsed
-
-## Restored Tasks
-
-### In Progress
-- [ ] Task that was being worked on
-
-### Pending
-- Task 1
-- Task 2
-
-### Completed (this session)
-- [x] Previously completed task
-
-## Notes from Last Session
-> <any notes saved>
-
-## Suggested Next Action
-Based on your in-progress task: **<task name>**
-
-<Context or suggestion based on what was being worked on>
-```
-
-## Usage Examples
-
-```bash
-# Basic load
-/load
-
-# Load from specific directory
-/load path/to/project
-
-# Load with verbose git log
-/load --verbose
-```
-
-## Flags
-
-| Flag | Effect |
-|------|--------|
-| `--verbose` | Show full git log since save |
-| `--no-restore` | Show state without restoring TodoWrite |
-| `--clear` | Clear saved state after loading |
-
-## Edge Cases
-
-### No Saved State Found
-```
-⚠ No saved state found
-
-This could mean:
-1. You haven't saved yet (use /save)
-2. Wrong directory (check pwd)
-3. State files were deleted
-
-To start fresh, just begin working normally.
-```
-
-### Stale State (>7 days)
-```
-⚠ Saved state is 12 days old
-
-A lot may have changed. Consider:
-1. Review git log manually
-2. Start fresh if context is lost
-3. Load anyway with: /load --force
-```
-
-### Branch Changed
-```
-⚠ Branch changed since save
-
-Saved branch: feature/old-branch
-Current branch: feature/new-branch
-
-The saved state may not be relevant. Options:
-1. Switch back: git checkout feature/old-branch
-2. Load anyway (tasks may still apply)
-3. Clear and start fresh: /load --clear
-```
-
-## Integration with /save
-
-These commands form a pair:
-
-```
-Session 1:
-  [work on tasks]
-  /save "Stopped at auth module"
-
-Session 2:
-  /load
-  → Shows: "In progress: Auth module refactor"
-  → Notes: "Stopped at auth module"
-  → Suggests: "Continue with auth module testing"
-```
-
-## Notes
-
-- Load automatically populates TodoWrite
-- Use `--no-restore` to preview without changing state
-- Clear old saves periodically with `--clear`
-- Works across machines if .claude/ is committed

+ 0 - 211
commands/save.md

@@ -1,211 +0,0 @@
----
-description: "Save session state before ending. Creates claude-state.json and claude-progress.md for session continuity."
----
-
-# Save - Session State Persistence
-
-Save your current session state before ending work. Creates both machine-readable and human-readable progress files.
-
-## Why This Exists
-
-Claude Code's native `--resume` flag restores conversation history, but **TodoWrite state does not persist between sessions by design**. Claude Code treats each session as isolated—the philosophy is that persistent state belongs in files you control, not in Claude's internal state.
-
-TodoWrite tasks are stored at `~/.claude/todos/[session-id].json` and **deleted when the session ends**. This is intentional, not a bug.
-
-This command bridges the gap by implementing the pattern from Anthropic's [Effective Harnesses for Long-Running Agents](https://www.anthropic.com/engineering/effective-harnesses-for-long-running-agents):
-
-> "Every subsequent session asks the model to make incremental progress, then leave structured updates."
-
-### What Persists vs What Doesn't
-
-| Claude Code Feature | Persists? | Location |
-|---------------------|-----------|----------|
-| Conversation history | Yes | Internal (use `--resume`) |
-| CLAUDE.md context | Yes | `./CLAUDE.md` |
-| TodoWrite tasks | **No** | Deleted on session end |
-| Plan Mode state | **No** | In-memory only |
-
-### The Gap `/save` Fills
-
-| Feature | Native `--resume` | `/save` + `/load` |
-|---------|-------------------|-------------------|
-| Conversation history | Yes | No |
-| TodoWrite tasks | **No** | Yes |
-| Git context | No | Yes |
-| Human-readable summary | No | Yes |
-| Git-trackable | No | Yes |
-| Works across machines | No | Yes (if committed) |
-| Team sharing | No | Yes |
-
-### When to Use
-
-- **End of work session** - Save before closing Claude Code
-- **Before context compaction** - Preserve state before `/compact`
-- **Handoff to teammates** - Commit state files for others to load
-- **Long-running tasks** - Checkpoint progress incrementally
-
-## Arguments
-
-$ARGUMENTS
-
-If no arguments, save current TodoWrite state and git context.
-
-## What This Command Does
-
-1. **Capture Current State**
-   - Read current TodoWrite tasks (completed, in-progress, pending)
-   - Get git branch and recent commits
-   - Detect uncommitted changes
-   - Note current working context
-
-2. **Write State Files**
-   - `.claude/claude-state.json` - Machine-readable state
-   - `.claude/claude-progress.md` - Human-readable summary
-
-3. **Optional Git Commit**
-   - If `--commit` flag: commit state files with message
-
-## Output Files
-
-### .claude/claude-state.json
-
-```json
-{
-  "version": "1.0",
-  "timestamp": "<ISO timestamp>",
-  "completed": ["task1", "task2"],
-  "in_progress": ["task3"],
-  "pending": ["task4", "task5"],
-  "context": {
-    "branch": "<current branch>",
-    "last_commit": "<commit hash>",
-    "last_commit_message": "<message>",
-    "modified_files": ["file1.ts", "file2.ts"],
-    "notes": "<any user-provided notes>"
-  }
-}
-```
-
-### .claude/claude-progress.md
-
-```markdown
-# Session Progress
-
-**Last Updated**: <timestamp>
-**Branch**: <branch name>
-
-## Completed
-- [x] Task 1
-- [x] Task 2
-
-## In Progress
-- [ ] Task 3
-  - Notes: <context>
-
-## Next Steps
-- Task 4
-- Task 5
-
-## Context
-- Last commit: <hash> "<message>"
-- Uncommitted: <count> files
-```
-
-## Usage Examples
-
-```bash
-# Basic save
-/save
-
-# Save with notes
-/save "Stopped mid-refactor, auth module needs testing"
-
-# Save and commit
-/save --commit
-
-# Save with notes and commit
-/save "Ready for review" --commit
-```
-
-## Execution Steps
-
-### Step 1: Gather State
-
-```bash
-# Get git info
-git branch --show-current
-git log -1 --format="%H %s"
-git status --porcelain
-```
-
-### Step 2: Read TodoWrite State
-
-Access the current TodoWrite state from the conversation context. Map statuses:
-- `completed` → Completed section
-- `in_progress` → In Progress section
-- `pending` → Next Steps section
-
-### Step 3: Create Directory
-
-```bash
-mkdir -p .claude
-```
-
-### Step 4: Write JSON State
-
-Create `.claude/claude-state.json` with:
-- Version: "1.0"
-- Timestamp: Current ISO timestamp
-- All task arrays from TodoWrite
-- Git context (branch, last commit, modified files)
-- User notes if provided in arguments
-
-### Step 5: Write Markdown Summary
-
-Create `.claude/claude-progress.md` with human-readable format:
-- Header with timestamp and branch
-- Checkbox lists for each status
-- Context section with git info
-- Any notes provided
-
-### Step 6: Optional Commit
-
-If `--commit` flag present:
-```bash
-git add .claude/claude-state.json .claude/claude-progress.md
-git commit -m "chore: save session state"
-```
-
-## Output
-
-After creating files, report:
-
-```
-✓ Session saved
-
-State saved to:
-  • .claude/claude-state.json
-  • .claude/claude-progress.md
-
-Summary:
-  • Completed: X tasks
-  • In Progress: Y tasks
-  • Pending: Z tasks
-  • Uncommitted files: N
-
-Load with: /load
-```
-
-## Flags
-
-| Flag | Effect |
-|------|--------|
-| `--commit` | Git commit the state files after creating |
-| `--force` | Overwrite existing state without confirmation |
-
-## Notes
-
-- State files are gitignored by default (add to .gitignore if needed)
-- Use `/load` to restore state in a new session
-- Save frequently during long tasks
-- Notes are preserved across sessions

+ 1 - 0
commands/session-manager

@@ -0,0 +1 @@
+Subproject commit 2fb5bc97660a594a84c10ca1511217c6d67486da