Claude Code Memory Checkpoint
Periodic state checkpoint to protect long-running Claude Code sessions
from crash, auto-compact, and other context-loss events.
What this solves
You start a long task with Claude Code. After two hours of back-and-forth,
something goes wrong: the machine reboots, the network drops, the conversation
gets auto-compacted, you accidentally /clear. The detailed state of where
you were — task list, in-progress action, next steps, key code locations — is
gone.
This tool installs four hooks that work together to keep a recoverable
checkpoint on disk:
- UserPromptSubmit hook reminds the assistant every
N minutes (default
30) to refresh today's session status snapshot before answering the next
question. The snapshot lives in your auto-memory directory and follows a
fixed template (task list, in-progress, next 3 steps, key context).
- SessionStart hook surfaces the existing checkpoint to the assistant on
every session start, resume, clear, or compact, so it can pick up where
the previous session left off.
- Stop hook fires at every turn-end. If today's autosnap file is older
than
CCMC_AUTOSNAP_INTERVAL_MIN (default 60), the hook silently
regenerates a small machine-readable snapshot — git branch, HEAD, working
tree, transcript pointer, last few turns. It does not inject context
into the conversation, does not block the turn, and does not consume
model tokens. This closes the silence-period gap that the
UserPromptSubmit hook cannot reach (long tool runs, hours of inactivity,
anything where the user is not actively typing).
- PreCompact hook silently snapshots the full transcript JSONL to disk
before context gets compacted, so nothing is unrecoverable.
The hooks are owned by the Claude Code harness, not the model — they fire
deterministically regardless of what the model is doing.
Two snapshot files, two roles
<memory-dir>/project_session_<YYYYMMDD>_status.md ← Claude writes (semantic)
<memory-dir>/project_session_<YYYYMMDD>_autosnap.md ← Stop hook writes (machine)
_status.md is the curated narrative — task list, in-progress, next steps,
key context. Refreshed when you talk to Claude and a reminder fires.
_autosnap.md is the objective fallback — written by a shell script with
whatever git, jq, and tail can see. Refreshed at most once per
CCMC_AUTOSNAP_INTERVAL_MIN, regardless of whether you are talking.
After a crash, prefer _status.md for narrative; check _autosnap.md if
the status file is stale or missing, and the transcript JSONL only as a
last resort.
Installation
git clone https://github.com/TbusOS/claude-code-memory-checkpoint.git
cd claude-code-memory-checkpoint
./install.sh
That writes:
- Hook scripts and the status template to
~/.claude/hooks/memory-checkpoint/
- Four hook entries (UserPromptSubmit, SessionStart, Stop, PreCompact)
merged into
~/.claude/settings.json (preserves any existing hooks;
backup at settings.json.bak)
- A discipline rule fragment appended to
~/.claude/CLAUDE.md between
<!-- BEGIN/END: memory-checkpoint --> markers (backup at CLAUDE.md.bak)
The installer is safe to re-run. Running ./install.sh (or ./install.sh upgrade) again refreshes everything without duplicating entries.
Requirements
- Claude Code installed (this tool depends on its hook system)
jq and sed available on PATH
- Bash 4+
Dry run
To preview changes without writing anything:
Configuration
All configuration is via environment variables read by the hook scripts at
runtime — no need to re-run the installer.
| Variable |
Default |
Meaning |
CCMC_INTERVAL_MIN |
30 |
Minutes between semantic checkpoint reminders (UserPromptSubmit) |
CCMC_AUTOSNAP_INTERVAL_MIN |
60 |
Minutes between machine autosnap writes (Stop hook) |
CCMC_MEMORY_DIR |
(auto) |
Override memory directory location |
CCMC_SNAPSHOT_KEEP |
5 |
Pre-compact transcript snapshots to retain |
CLAUDE_HOME |
$HOME/.claude |
Override Claude Code config dir |
By default, the hooks locate the per-project memory directory at
$HOME/.claude/projects/<sanitized-cwd>/memory/, which matches the
auto-memory layout. Override with CCMC_MEMORY_DIR if you keep memory
elsewhere.
How a checkpoint looks
Today's checkpoint is written to:
<memory-dir>/project_session_<YYYYMMDD>_status.md
One file per day, overwritten in place by successive checkpoints (not
appended). The template (also installed at
~/.claude/hooks/memory-checkpoint/status-template.md):
---
name: 2026-04-30 session status
description: Building installer for the checkpoint tool, blocked on jq merge logic
type: project
lastUpdate: 2026-04-30 14:32
---
## Task list
- [x] Hook protocol research — done
- [ ] install.sh — in progress (jq merge edge case)
- [ ] README — pending
## In progress
- **Action**: refining `merge_settings_json` to drop empty SessionStart wrappers
- **Stage**: code written, smoke test pending
- **Blocker**: none
## Next 3 steps
1. Run `./install.sh --dry-run` to verify
2. Real install on dev machine, restart Claude Code
3. Trigger 30-min reminder by waiting + sending a prompt
## Key context
- jq filter at install.sh:140
- Settings backup at ~/.claude/settings.json.bak
- Reference: https://code.claude.com/docs/en/hooks.md
How it interacts with auto-memory
This tool doesn't replace the auto-memory system — it complements it.
Auto-memory captures persistent facts (user role, feedback, project
context). The checkpoint captures the current state of work-in-progress
that would otherwise live only in the conversation buffer.
Persistent facts → auto-memory.
Volatile in-flight state → checkpoint.
Uninstall
That:
- Removes
~/.claude/hooks/memory-checkpoint/
- Strips memory-checkpoint hook entries from
~/.claude/settings.json
(other hooks are preserved)
- Removes the marker block from
~/.claude/CLAUDE.md
Backups (*.bak) are left in place — delete manually if you don't need them.
How the discipline rule works
The installer appends a short rule to your global CLAUDE.md between
<!-- BEGIN: memory-checkpoint vX.Y.Z --> and <!-- END: memory-checkpoint -->
markers. The rule tells the assistant to:
- Update today's status file when the UserPromptSubmit hook injects a
reminder, before answering the user's main request.
- Read the checkpoint on
SessionStart (especially source: resume or
source: compact) before acting.
- Treat checkpointing as insurance, not bookkeeping — even five lines of
"doing X, next: Y" beats a blank.
You can edit the rule in place (between the markers) without breaking
re-installs — the installer only replaces content within the markers.
Why hooks instead of a slash-command or a skill
Hooks fire deterministically from the harness; they don't depend on the
model deciding to run them. A skill is invoked when the model recognises
its trigger; a slash-command is run when the user types it. Neither survives
a crash mid-task. Hooks do.
License
MIT — see LICENSE.
Compatibility
Tested with Claude Code on Linux and macOS. Should work wherever Claude
Code, Bash 4+, and jq are available.
This tool is independent of Anthropic; it is a third-party companion that
uses Claude Code's public hook protocol.