Save session state to ledger file for continuity across crashes, context switches, or /clear + reload cycles
Autonomous agent that snapshots session state to a ledger file for crash recovery and context refresh. Use it during long workflows to enable `/clear` + reload cycles that preserve full signal while avoiding cumulative degradation from repeated compaction.
/plugin marketplace add majesticlabs-dev/majestic-marketplace/plugin install majestic-engineer@majestic-marketplacehaikuAutonomous agent that snapshots current session state to a ledger file. Designed to be triggered by other agents during long-running workflows.
Key insight: /clear + ledger reload provides fresh context with full signal preservation, avoiding the cumulative degradation of repeated /compact cycles.
Task(subagent_type="majestic-engineer:session-checkpoint", prompt="<optional context about current work>")
Requires session.ledger: true in .agents.yml:
session:
ledger: true
ledger_path: .claude/session_ledger.md # optional, defaults to .claude/session_ledger.md
Note: The ledger is per-worktree (ephemeral session state). Handoffs go to main worktree (permanent, for /learn).
Read session config:
claude -p "/majestic:config session {}"If session.ledger is false or missing:
Checkpoint skipped - session.ledger not enabled in .agents.ymlUse session.ledger_path from config, or default to .claude/session_ledger.md.
Ensure the directory exists:
mkdir -p .claude
From the prompt context provided, extract:
UNCONFIRMED if uncertain)Write to the ledger file using this format:
# Session Ledger
_Last updated: <timestamp>_
## Goal
<goal and success criteria>
## Constraints/Assumptions
- <constraint 1>
- <constraint 2>
## Key Decisions
- <decision 1>
- <decision 2>
## State
### Done
- <completed item 1>
- <completed item 2>
### Now
<current focus>
### Next
<planned next step>
## Open Questions
- <question 1>
- <question 2> `UNCONFIRMED`
## Working Set
- Files: <key files>
- IDs: <relevant IDs>
- Commands: <useful commands>
Return a brief confirmation:
Checkpoint saved to .claude/session_ledger.md
- Goal: <brief goal>
- State: <done count> done, now: <current>, next: <next>
/clear + ledger reload/session:handoffOther agents can invoke this checkpoint:
Before starting major refactor, invoke `session-checkpoint` agent to save current state.
After completing each major step, invoke `session-checkpoint` agent with current progress.
If context usage exceeds 70%, invoke `session-checkpoint` agent before continuing.
Task(
subagent_type="majestic-engineer:session-checkpoint",
prompt="Working on: Add user authentication. Done: Created User model, Added bcrypt gem. Now: Writing login controller. Next: Add session management."
)
Task(
subagent_type="majestic-engineer:session-checkpoint",
prompt="Debugging N+1 in OrdersController. Found root cause: missing includes on line_items. About to apply fix."
)
Task(
subagent_type="majestic-engineer:session-checkpoint",
prompt="Implementing feature X, halfway done"
)
When resuming after /clear with a ledger file:
UNCONFIRMED needs verificationMark assumptions as UNCONFIRMED when:
Prefer /clear + ledger reload over multiple /compact cycles:
| Approach | Context Quality | Signal Loss |
|---|---|---|
Single /compact | Good | Minimal |
Multiple /compact cycles | Degraded | Cumulative - each cycle loses detail |
/clear + ledger reload | Fresh | None - ledger preserves full signal |
Guideline: After 2-3 compactions in a session, checkpoint to ledger and /clear for fresh context with preserved state.
| Tool | Purpose | Persistence | Trigger |
|---|---|---|---|
session-checkpoint | Crash recovery, quick state save | File (.claude/session_ledger.md) | Agent-triggered |
/session:handoff | Cross-session continuity | File (main worktree .claude/handoffs/) | User/ship-triggered |
TodoWrite | In-session task tracking | In-context only | Agent-triggered |
Use session-checkpoint for:
Use /session:handoff for:
Designs feature architectures by analyzing existing codebase patterns and conventions, then providing comprehensive implementation blueprints with specific files to create/modify, component designs, data flows, and build sequences