cpr-compress-preserve-resume
Agent plugin
Created by Elia Alberti
Published in EliaAlberti/cpr-compress-preserve-resume. Publisher page
525 GitHub stars
What it is
Persistent memory for Claude Code, packaged as a plugin. Save, search, and restore conversation context across sessions.
AutoGineer overview, from the brain’s own files
CPR (Compress, Preserve & Resume) is a plugin for Claude Code designed to solve the problem of context loss between sessions. It enables AI agents to maintain a persistent state of work by saving structured session logs, updating project instructions, and restoring context when starting new sessions. By utilizing hooks that trigger during session starts and before compactions, it ensures that raw transcripts are archived and key summaries are readily available, significantly reducing the token costs associated with re-explaining project history.
How it works
Memory model: Key-value store
AutoGineer overview, from the brain’s own files
The system uses three slash commands and two automated hooks. /cpr:compress creates a structured markdown log of the session. /cpr:preserve updates the project's CLAUDE.md file with key learnings. /cpr:resume allows users to search past session summaries and restore context. The PreCompact hook automatically saves the raw transcript before any compaction occurs, while the SessionStart hook injects a memory brief into the agent's context at the beginning of a new session.
| Folder | Role | Files |
|---|---|---|
| docs | docs | 1 |
| examples | examples | 1 |
| hooks | hooks | 1 |
| scripts | scripts | 6 |
| skills | agent-instructions | 3 |
| tests | tests | 1 |
| .claude-plugin | folder | 2 |
| videos | folder | 4 |
The agent writes
- scripts/dump_transcript.py evidence: README.md
Requirements
Databases: Redis
Works with: Claude Code
Set it up
This brain runs code automatically: 2 hooks (claude-code). Review hooks/hooks.json before opening the folder in Claude Code. No step below turns a hook on for you.
hooks/hooks.json:python3 "${CLAUDE_PLUGIN_ROOT}/scripts/precompact_save.py"hooks/hooks.json:python3 "${CLAUDE_PLUGIN_ROOT}/scripts/session_start.py"
- Not scanned by AutoGineerThe author’s README also describes installing it as a Claude Code plugin marketplace. Read its install section: AutoGineer did not scan that path. https://github.com/EliaAlberti/cpr-compress-preserve-resume/blob/cfd1e77e07d2b3698591688e7e151d83d3ef51c3/README.md#installation
- Not scanned by AutoGineerThe author’s README also describes installing it from a clone of its repository. Read its install section: AutoGineer did not scan that path. https://github.com/EliaAlberti/cpr-compress-preserve-resume/blob/cfd1e77e07d2b3698591688e7e151d83d3ef51c3/README.md#installation
Created by Elia Alberti. Published in EliaAlberti/cpr-compress-preserve-resume. Licence: MIT License.
Usage
AutoGineer overview, from the brain’s own files
- Save session context before closing
- Update project documentation with recent decisions
- Restore context from previous sessions
- Search historical session logs by topic
- Automate transcript backups during compaction
- “/cpr:compress”
- The agent prompts the user to select key learnings and decisions to save, then generates a structured markdown log file in the CC-Session-Logs directory.
- “/cpr:resume auth”
- The agent displays a summary of recent sessions and lists related past sessions that match the topic 'auth'.
Documentation by Elia Alberti
<p align="center"> <img src="https://img.shields.io/badge/Claude%20Code-Plugin-5A67D8?style=for-the-badge&logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCI+PHBhdGggZmlsbD0id2hpdGUiIGQ9Ik0xMiAyQzYuNDggMiAyIDYuNDggMiAxMnM0LjQ4IDEwIDEwIDEwIDEwLTQuNDggMTAtMTBTMTcuNTIgMiAxMiAyem0wIDE4Yy00LjQxIDAtOC0zLjU5LTgtOHMzLjU5LTggOC04IDggMy41OSA4IDgtMy41OSA4LTggOHoiLz48L3N2Zz4=&logoColor=white" alt="Claude Code Plugin" /> <img src="https://img.shields.io/badge/Version-2.0.0-E74C3C?style=for-the-badge" alt="Version 2.0.0" /> <img src="https://img.shields.io/badge/Skills-3%20%2B%202%20hooks-blue?style=for-the-badge" alt="3 skills and 2 hooks" /> <img src="https://img.shields.io/badge/License-MIT-yellow?style=for-the-badge" alt="MIT License" /> <img src="https://img.shields.io/badge/Token%20Savings-~66%25%20median-brightgreen?style=for-the-badge" alt="Token Savings ~66% median" /> </p>
<h1 align="center">🩺 CPR for Claude Code</h1> <h3 align="center"><em>Compress, Preserve & Resume</em></h3>
<p align="center"> <strong>Persistent memory across sessions. Never lose context again.</strong><br> <em>Estimated ~66% reduction in session-restart token cost (analytical model, range 51-74%).</em> </p>
<table> <tr> <td align="center" width="33%"> <strong>/cpr:preserve</strong><br> <sub>Save key learnings to CLAUDE.md</sub><br><br> <video src="https://github.com/user-attachments/assets/3c7e0f30-dea0-4c67-a990-021db84b6d81" width="100%" controls></video> </td> <td align="center" width="33%"> <strong>/cpr:compress</strong><br> <sub>Capture the full session to a searchable log</sub><br><br> <video src="https://github.com/user-attachments/assets/a31fe4b7-483e-47c1-8d78-01850482244f" width="100%" controls></video> </td> <td align="center" width="33%"> <strong>/cpr:resume</strong><br> <sub>Restore context from past sessions</sub><br><br> <video src="https://github.com/user-attachments/assets/1a3aff44-904d-463a-8f4e-6af6925e8a7a" width="100%" controls></video> </td> </tr> </table>
<p align="center"> Three skills and two hooks that save, search, and restore your conversation context, so you can pick up exactly where you left off. </p>
<p align="center"> <a href="#is-cpr-for-me">Is it for me?</a> • <a href="#the-problem">Problem</a> • <a href="#the-solution">Solution</a> • <a href="#why-it-saves-tokens">Why It Saves Tokens</a> • <a href="#installation">Installation</a> • <a href="#usage">Usage</a> • <a href="#recommended-workflow">Workflow</a> • <a href="#upgrading-from-v1">Upgrading</a> • <a href="#faq">FAQ</a> </p>
What Is CPR?
CPR is a Claude Code plugin. It adds three slash commands and two hooks:
| Piece | What it does |
|---|---|
/cpr:compress | Writes a structured, searchable session log. A script appends the raw transcript. |
/cpr:preserve | Updates CLAUDE.md with the learnings every future session should start with. |
/cpr:resume | Loads recent session summaries and searches past sessions by topic. |
| PreCompact hook | Saves the raw transcript before every compaction, manual or automatic. |
| SessionStart hook | Hands the model a short memory brief when a session starts or compacts. |
No build step, no dependencies beyond Python 3.10, and every file is plain markdown or a small script you can read.
Is CPR For Me?
Yes if you work on the same project across several Claude Code sessions and find yourself re-explaining what happened last time, or if you want the full conversation kept on disk and searchable by topic rather than flattened into a compaction summary.
No if your sessions are one-off fixes or throwaway scripts. There is no next session to pay the save back.
CPR sits next to CLAUDE.md and Claude Code's auto memory rather than replacing them. CLAUDE.md holds instructions, auto memory holds preferences, CPR holds the state of the work. Install takes one line, and removing it is /plugin uninstall cpr@cpr.
The Problem
Claude Code has no memory of the work between sessions. When you close a conversation, the decisions, the fixes, the paths and the reasons go with it.
It gets worse:
| Problem | Impact |
|---|---|
| Compaction flattens details | When the context window fills up, history is summarised and specific values, file paths and nuanced decisions get lost |
| Long sessions lose early context | That critical decision from the first 10 minutes? Gone by hour two |
| New session = blank slate | Re-explaining your project, re-discovering paths, re-making decisions every time |
| Past work is unsearchable | No way to look up what you discussed three sessions ago |
| CLAUDE.md and auto memory aren't enough | They hold instructions and preferences, not the state of the work, the errors, or the solutions |
The Solution
During work ──> PreCompact hook ──> raw transcript autosaved before any compaction
End session ──> /cpr:preserve ──> CLAUDE.md updated (optional)
/cpr:compress ──> curated session log saved
New session ──> SessionStart hook──> latest Quick Resume Context injected automatically
/cpr:resume ──> last N summaries + topic search ──> full context restoredThe skills are where the curated summaries come from. The hooks are the safety net for the sessions you forget to save.
CPR next to Claude Code's own memory
Claude Code now has auto memory and re-injects CLAUDE.md after compaction. CPR is built to sit next to both, not replace them:
| CLAUDE.md | Auto memory | CPR session logs | |
|---|---|---|---|
| Holds | Instructions and conventions | Preferences and corrections | Decisions, fixes, errors, pending work, the full transcript |
| Written by | You (and /cpr:preserve) | Claude Code | /cpr:compress and the hooks |
| Shared with the team | Yes, via git | No, machine-local | Yes, if you commit CC-Session-Logs/ |
| Searchable by topic | No | No | Yes, /cpr:resume <topic> |
Works With Auto-Compact
Earlier versions of CPR told you to disable auto-compact. You no longer need to. The PreCompact hook runs before both /compact and automatic compaction, receives the transcript path from Claude Code, and writes one autosave log per session into CC-Session-Logs/. After compaction, the SessionStart hook puts the latest Quick Resume Context back into context.
You still get the best results by running /cpr:compress before /compact, because that is where the curated summary comes from. The autosave only guarantees you never lose the raw conversation.
Why It Saves Tokens
Re-establishing context at the start of every session is expensive. The user re-explains the project, Claude re-reads files, prior decisions get re-derived, and conversations rebuild from scratch. CPR replaces that with a compact log of what mattered.
Across the modelled range, session-restart token cost drops by 51% in the low case, 66% in the median case, and 74% in the high case. On a 10-session project that's roughly ~99,450 tokens saved at the median. On a 20-session, high-context project it's ~579,500 tokens saved.
| Case | Without CPR | With CPR | Savings | % saved |
|---|---|---|---|---|
| Low | 4,850 | 2,400 | 2,450 | 51% |
| Median | 16,750 | 5,700 | 11,050 | 66% |
| High | 41,200 | 10,700 | 30,500 | 74% |
Two things make v2.0 cheaper than v1. The raw archive is appended by script, and the PreCompact hook does the same before any compaction, so none of it is model output. And /cpr:resume no longer opens files or re-reads CLAUDE.md, which Claude Code already loads: a script injects the summaries straight into the skill, and the session-start brief costs about 200 tokens.
These are analytical estimates, not telemetry. CPR is net positive for multi-session projects with cross-session context, and net negative for one-off bug fixes or single-session work. The breakeven is reached when the next session would otherwise repeat ~2,400 tokens of context-rebuild work, which most multi-session projects cross by session #2.
Full methodology, baseline scenarios, and per-component cost breakdown: docs/token-savings-analysis.md.
The Session Log System
Every /cpr:compress creates a structured markdown file in CC-Session-Logs/ at your project root. The hooks add autosave files to the same folder.
Filename format: YYYY-MM-DD-HH_MM-topic-name.md, so files sort chronologically in any listing.
<details> <summary><strong>Log structure (click to expand)</strong></summary>
# Session Log: 2026-03-05 14:20 - api-auth-refactor
## Quick Reference (for AI scanning)
**Confidence keywords:** auth, JWT, refresh-tokens, middleware
**Projects:** my-saas-app
**Outcome:** Replaced cookie-based auth with JWT + refresh tokens
## Decisions Made
- JWT over session cookies, stateless scales better
## Key Learnings
- Redis EX flag is cleaner than separate EXPIRE calls
## Solutions & Fixes
- Login race condition fixed with SETNX
## Files Modified
- `src/middleware/auth.ts`: JWT verification
## Pending Tasks
- [ ] Add refresh token rotation
---
## Quick Resume Context
2-3 sentence summary. This is what the SessionStart hook shows next time.
---
## Raw Session Log
{Full conversation archive, appended by script, searchable but never loaded by /cpr:resume}</details>
The key insight: /cpr:resume only reads the summary sections (everything above "Raw Session Log"). The raw conversation is there for searchability, but it never wastes tokens during context loading.
And it's free to write, too. The raw log is appended by scripts/dump_transcript.py, which reads the Claude Code transcript straight from ~/.claude/projects/. Only the structured sections are model output.
See examples/session-log-example.md for a complete example.
Installation
Prerequisites
Claude Code with plugin support. Verified on v2.1.266.
Python 3.10 or newer on your PATH as
python3
Option A: plugin marketplace (recommended)
Inside Claude Code:
/plugin marketplace add EliaAlberti/cpr-compress-preserve-resume
/plugin install cpr@cprOr from your shell:
claude plugin marketplace add EliaAlberti/cpr-compress-preserve-resume
claude plugin install cpr@cprThe install wires the skills and both hooks. Run /reload-plugins or restart Claude Code if you installed from inside a session. Updates arrive when the plugin version is bumped; /plugin shows what is installed and lets you update or uninstall.
Option B: skills directory
Clone the repo into your personal skills folder and Claude Code loads it as a plugin on the next start, hooks included:
git clone https://github.com/EliaAlberti/cpr-compress-preserve-resume.git ~/.claude/skills/cprgit pull in that folder updates it. Edits to a SKILL.md apply immediately; changes to the hooks need /reload-plugins or a restart. If you prefer to keep a development clone elsewhere, a symlink at ~/.claude/skills/cpr pointing at it works the same way.
Option C: try it without installing
claude --plugin-dir /path/to/cpr-compress-preserve-resumeThe skills and hooks are active for that session only. Pass the flag again next time.
Check it works
You: /cpr:compressIf the "What to preserve" selector appears, it's working. The hooks are active whenever the plugin is enabled: the next time you start a session in a project that already has logs, the memory brief is there before your first message.
One detail: the skills are user-invoked only, so they don't appear when you ask the model to list its skills. Type them.
Model
The skills run on whatever model your session uses. CPR is written for the current Claude 5 family and does not pin a model.
Usage
End of session: save your work
You: /cpr:compress
Claude: What would you like to preserve? [multi-select]
You: Key Learnings, Solutions & Fixes, Decisions Made, Files Modified
Claude: Anything specific to highlight? [Skip / Add a custom note]
You: Skip
Claude: Topic name: "api-auth-refactor" [Accept / Provide a different name]
You: Accept
Claude: Session Saved
CC-Session-Logs/2026-03-05-17_30-api-auth-refactor.md
Raw log: 84 turns appendedIn a hurry? /cpr:compress quick skips the questions and saves every section that has content.
Update CLAUDE.md: preserve key learnings
You: /cpr:preserve
Claude: What should be preserved? [multi-select]
You: Key Decisions, Next Steps
Claude: CLAUDE.md updated
- Added JWT auth decision rationale
- Updated next steps with token rotation
CLAUDE.md is now 185 lines (target: under 200)Starting a new session: restore context
The moment a session starts, the SessionStart hook has already added the latest log's Quick Resume Context and pending tasks. For the full picture:
You: /cpr:resume
Claude:
══════════════════════════════════════════════
RESUMING: my-saas-app
══════════════════════════════════════════════
CONTEXT:
- JWT auth flow implemented, tests passing
- Redis used for refresh token storage
MOST RECENT SESSION: 2026-03-05 17:30
Topic: api-auth-refactor
...
READY TO:
- Add refresh token rotation
- Set up token blacklist for logout
══════════════════════════════════════════════Search past sessions by topic
You: /cpr:resume auth
Claude: [Shows recent sessions + RELATED SESSIONS matching "auth"]
══════════════════════════════════════════════
RELATED SESSIONS (topic: "auth")
══════════════════════════════════════════════
- 2026-03-05: api-auth-refactor, JWT + refresh tokens
- 2026-02-28: oauth-google-setup, Google OAuth integration
══════════════════════════════════════════════/cpr:resume 10 migration reads the last 10 sessions and searches for "migration". Topic search covers the raw logs too, so a detail you only mentioned in passing is still findable.
Recommended Workflow
┌──────────────────────────────────────────────────────────┐
│ 1. Start session │
│ └── (brief injected) then /cpr:resume if you need │
│ the last few sessions in full │
│ │
│ 2. Do work... │
│ └── compaction happens? the PreCompact hook has │
│ already saved the raw transcript │
│ │
│ 3. Before ending or before /compact │
│ ├── /cpr:preserve Update CLAUDE.md (optional) │
│ └── /cpr:compress Save the curated session log │
└──────────────────────────────────────────────────────────┘When to /cpr:preserve:
After making important architectural decisions
When you discover patterns you'll need in future sessions
When project phase or status changes
When to /cpr:compress:
Before ending a session
Before
/compact, so the summary is written from the full conversationAfter completing a significant chunk of work
Customisation
<details> <summary><strong>Session log storage path and mirroring</strong></summary>
By default, logs go to {project_root}/CC-Session-Logs/. The project root is the nearest parent directory containing CLAUDE.md or .git, falling back to the current directory.
To route logs elsewhere for some projects, or mirror them to a second folder, create ~/.claude/cpr.json:
{
"routes": [
{
"when_cwd_startswith": "/Users/me/vault",
"logs_dir": "/Users/me/Desktop/Session Logs",
"mirror_to": ["/Users/me/vault/Areas/CC-Session-Logs"]
}
]
}The longest matching prefix wins. Every skill and hook honours it. Set CPR_CONFIG to use a different config file.
</details>
<details> <summary><strong>CLAUDE.md line target</strong></summary>
/cpr:preserve aims to keep CLAUDE.md under 200 lines, which is what Claude Code recommends for adherence. Change the number in skills/preserve/SKILL.md.
</details>
<details> <summary><strong>Protected and archivable sections</strong></summary>
Mark any section in your CLAUDE.md as immune to archiving:
## My Important Section (PROTECTED)Or mark sections as safe to archive:
## Old Notes (ARCHIVABLE)Archived content goes to CLAUDE-Archive.md next to your CLAUDE.md.
</details>
<details> <summary><strong>Turning the hooks off</strong></summary>
Delete the entry you don't want from hooks/hooks.json in your installed copy, or disable the plugin with /plugin. The skills work without the hooks.
</details>
Upgrading From v1
Your logs keep working.
/cpr:resumereads the oldDD-MM-YYYYfilenames and the new ISO ones, and sorts them by real date.Remove the old command files. Delete
compress.md,preserve.mdandresume.mdfrom~/.claude/commands/(or.claude/commands/) and the~/.claude/scripts/dump_transcript.pycopy. Otherwise you have two of each.The commands are namespaced now.
/cpr:compress,/cpr:preserve,/cpr:resume. Claude Code ships its own/resumesession picker, which is why CPR's version moved.You can turn auto-compact back on. See Works With Auto-Compact.
How It Scales
| Session logs | Behaviour |
|---|---|
| Any count | /cpr:resume reads summaries only, never raw logs, so it stays cheap at any scale |
| Any count | Topic search is done by a script, across summaries first and raw logs second, capped at 10 matches |
| Autosaves | One file per session, refreshed on each compaction, so they never pile up |
FAQ
<details> <summary><strong>Do I need all three skills?</strong></summary>
/cpr:compress + /cpr:resume is the minimum viable setup. /cpr:preserve is optional but recommended. It keeps your CLAUDE.md up to date without manual editing. The hooks come with the plugin and need no setup.
</details>
<details> <summary><strong>Where are logs stored?</strong></summary>
{project_root}/CC-Session-Logs/. Project root is the nearest parent directory containing CLAUDE.md or .git. If neither is found, it falls back to the current working directory. See Customisation for routing.
</details>
<details> <summary><strong>Will this work with any project?</strong></summary>
Yes. The skills auto-detect your project root and create the CC-Session-Logs/ folder on first use. No configuration needed.
</details>
<details> <summary><strong>How big do logs get?</strong></summary>
A full session log with the raw conversation can be several hundred KB. But the raw part is appended by script, not generated as model output, and /cpr:resume only reads the summary header (typically 30-80 lines), so token usage stays low regardless of log size.
</details>
<details> <summary><strong>Should I commit session logs to git?</strong></summary>
Up to you. They're useful for team knowledge sharing but can be large. Consider adding CC-Session-Logs/ to .gitignore if you prefer to keep them local.
</details>
<details> <summary><strong>What if I forget to /cpr:compress before /compact?</strong></summary>
The PreCompact hook saved the raw transcript for you. You lose the curated summary for that stretch, but the conversation is on disk and /cpr:resume <topic> can search it. Run /cpr:compress after compaction to write a summary from what remains in context.
</details>
<details> <summary><strong>Does the transcript parsing break when Claude Code changes?</strong></summary>
It can. Claude Code documents the transcript format as internal. CPR reads it defensively, takes the path from the hook input rather than guessing, and skips anything it doesn't recognise. If a release changes the layout, the raw log may come out shorter until the parser is updated. The curated summary never depends on it.
</details>
<details> <summary><strong>Can I use this with CLAUDE.md files in subdirectories?</strong></summary>
The skills look for CLAUDE.md at the project root. If you have multiple CLAUDE.md files (e.g., monorepo), run from the relevant subdirectory.
</details>
Development
llms.txt at the repo root is the AI-readable summary of the project. Keep it in step with this README.
python3 -m unittest discover -s tests -v # script tests
claude plugin validate . # manifest check
claude --plugin-dir . # try the working copyCredits
Created by Elia Alberti. Built with and for Claude Code.
License
MIT. See LICENSE.
docs/token-savings-analysis.md
Token Savings Analysis
This document models the token cost of working on a typical software project across multiple Claude Code sessions, with and without CPR, and quantifies the savings.
The numbers are analytical estimates, not telemetry. All assumptions are stated explicitly so you can substitute your own values.
TL;DR
Under the modelled assumptions below, CPR saves ~51% of session-transition tokens in the low case, ~66% in the median case, and ~74% in the high case. On a 10-session project, that translates to roughly ~99,450 tokens saved at the median, rising to ~579,500 tokens in the largest modelled case (20 sessions, high-context profile).
CPR is net negative under the modelled assumptions for single-session work or trivial one-off bugs. The breakeven point, where avoided rework exceeds CPR's own overhead, is reached as soon as a follow-up session would otherwise repeat ~2,400 tokens of context-rebuild work. For most multi-session projects this happens by session #2, but it depends on how much cross-session context exists.
How the headline numbers are derived: the percentages come directly from the per-transition Savings table further down (
Savings ÷ Without-CPR cost). The project totals come fromSavings per transition × (Sessions − 1). All inputs are stated as low/median/high ranges, not point estimates. Substitute your own values to recompute.
What this analysis excludes:
Human time saved (or added) by CPR's prompts at session boundaries.
Any overlap with Claude Code's built-in
/compactsummarisation and auto memory.Savings lost to stale, incomplete, or topic-misaligned CPR logs.
Baseline Scenario
A typical multi-session software project:
| Variable | Low | Median | High |
|---|---|---|---|
| Sessions over 1-4 weeks | 5 | 10 | 20 |
| Session length | 45 min | 90 min | 120 min |
| Active files | 20 | 40 | 80 |
| Prior-context depth (sessions back) | 1 | 2 | 3 |
The cost we're modelling is session transition: what it costs to move from one session to the next. The cost of the actual work inside each session is roughly equal in both cases and is not part of the comparison. CLAUDE.md is loaded by Claude Code at the start of every session in both cases, so it is not counted on either side.
Without CPR: Session-Restart Cost
Each new session, the user has no durable memory of prior sessions. They must rebuild context from scratch.
| Cost component | Low | Median | High |
|---|---|---|---|
| User re-explains goals, constraints, prior progress (chat input) | 150 | 450 | 1,200 |
| Claude re-reads relevant source files | 3,000 | 12,000 | 30,000 |
| Claude re-derives architecture, invariants, prior decisions | 500 | 2,000 | 5,000 |
| Conversation rebuild + back-and-forth clarification | 1,000 | 1,500 | 2,500 |
| Repetition: forgotten conventions, prior rejected approaches | 200 | 800 | 2,500 |
| Total per transition | 4,850 | 16,750 | 41,200 |
Notes on each component
Re-explanation assumes ~150 words at the low end (a quick reminder), ~300 words at median (a focused brief), ~800 words at high end (a full context dump). Tokens estimated at ~1.5 per word.
Re-reading files assumes 3-5 small files at low, 8-12 medium files at median, 15-25 files at high. Average source file ≈ 200-500 lines ≈ 1,000-3,000 tokens.
Re-deriving captures the inference cost of Claude rebuilding its mental model: invariants, design choices, debugging hypotheses already worked through.
Conversation rebuild captures questions Claude has to ask the user that prior sessions had already answered, plus the tokens to handle those answers.
Repetition captures cases where the same convention or a previously-rejected approach gets re-tried because it was forgotten.
With CPR: Session-Transition Cost
Each transition costs /cpr:compress at the end of the previous session, and /cpr:resume at the start of the next.
| Cost component | Low | Median | High |
|---|---|---|---|
/cpr:compress at end of prior session (summarisation + write + AskUserQuestion) | 1,500 | 2,500 | 4,000 |
/cpr:preserve durable learnings write (occasional, amortised) | 0 | 500 | 1,500 |
/cpr:resume at start of next session (session-start brief + 1-3 log summaries injected) | 700 | 2,200 | 4,700 |
| Reconciliation, light search, parse | 200 | 500 | 500 |
| Total per transition | 2,400 | 5,700 | 10,700 |
Notes on each component
/cpr:compress runs once at end of session: it summarises the conversation, asks the user what to preserve, writes the structured log. Most of the cost is inference (summarisation), not file I/O. The raw conversation archive is appended by
scripts/dump_transcript.pyfrom the Claude Code transcript on disk, and the PreCompact hook does the same automatically before any compaction, so the archive costs zero model output tokens. Measured across 42 real sessions of 20+ turns, that archive is ~2,900 / ~4,300 / ~9,900 tokens at the lower quartile / median / upper quartile (largest ~640,000), all of which the model would otherwise have generated./cpr:preserve is optional and used less often than
/cpr:compress, usually only when a durable project-level learning emerges. Cost amortised./cpr:resume costs the SessionStart brief (~200 tokens, the latest log's Quick Resume Context and pending tasks) plus 1-3 recent log summaries (500-1,500 tokens each) that a script injects into the skill. The model makes no tool calls and does not re-read CLAUDE.md, which Claude Code has already loaded.
Reconciliation covers any extra tokens needed when log content needs to be reconciled with current code state.
Savings
Savings per transition = Without-CPR cost − With-CPR cost| Case | Without CPR | With CPR | Savings | % saved |
|---|---|---|---|---|
| Low | 4,850 | 2,400 | 2,450 | 51% |
| Median | 16,750 | 5,700 | 11,050 | 66% |
| High | 41,200 | 10,700 | 30,500 | 74% |
Across a project
A project has (N − 1) transitions for N sessions.
| Project size | Sessions | Transitions | Median savings |
|---|---|---|---|
| Small | 5 | 4 | ~44,200 tokens |
| Medium | 10 | 9 | ~99,450 tokens |
| Large | 20 | 19 | ~209,950 tokens (median) / ~579,500 tokens (high) |
What changed between versions
| Version | Low | Median | High | Why |
|---|---|---|---|---|
| v1.1.0 as modelled | 24% | 55% | 68% | Assumed a free raw log and counted a re-read of CLAUDE.md in /resume |
| v1.1.0 real | net negative | 30% | 44% | Model re-typed the raw archive on every /compress |
| v1.2.0 | 24% | 55% | 68% | Raw archive appended by script |
| v2.0.0 | 51% | 66% | 74% | /cpr:resume no longer re-reads CLAUDE.md or opens files; summaries are injected by script |
Breakeven and When CPR Doesn't Help
CPR has a fixed cost per transition (the /cpr:compress + /cpr:resume pair). Savings appear only when the avoided rework exceeds that cost.
CPR is net negative for:
Single-session projects, where there's no next session to amortise the
/cpr:compresscost into.One-off bug fixes completed in a single session.
Throwaway scripts with no cross-session continuity.
Projects where
CLAUDE.mdand session logs become stale or incorrect. Wrong context can cost more than no context.
Under the modelled assumptions, CPR tends to be net positive for:
Multi-session features spanning 3+ sessions.
Long-running refactors with accumulated decisions.
Projects with conventions that need consistent enforcement across sessions.
Onboarding work where prior decisions and rejected approaches matter.
The breakeven is reached as soon as the next session avoids ~2,400 tokens of context-rebuild work, which is roughly the cost of re-reading one source file plus a brief user re-explanation. Most multi-session projects cross this threshold by session #2, but the actual breakeven point depends on the specific work, file sizes, and how much context is preserved between sessions.
Caveats
These are estimates, not measurements. Real-world variance is wide. Substitute your own component values to model your specific workflow.
Token costs vary with file size, language, and conversation style. A Markdown-heavy doc project will read differently than a Rust codebase.
Quality of
/cpr:compressand/cpr:resumeoutput matters. Bad summaries can cost more than they save. The structured log format and the confidence-keyword search are designed to keep summaries useful.CPR adds friction at session boundaries.
/cpr:compressasks the user three questions before saving, about 30 seconds of human time per transition./cpr:compress quickskips them.The numbers above don't account for
/compactor auto memory. Claude Code's/compactsummarises the current conversation but doesn't persist across sessions, and auto memory holds preferences and corrections rather than the state of the work. CPR sits alongside both, not as a replacement.
Methodology
The cost ranges in this analysis come from the following heuristics:
Token-per-word ratio: ~1.3-1.5 for English prose, used for chat-input estimates.
Token-per-line ratio: ~5-8 for typical source code, used for file-read estimates.
Inference cost for summarisation: estimated at 1.5-2× the size of the output, since the model reads the full conversation to produce the summary. The raw log is excluded: it is copied from disk by script, not generated.
Raw log size: measured with
scripts/dump_transcript.pyover 42 local Claude Code sessions of 20+ turns, at ~4 characters per token.Session log summary size: based on observed sizes in real CPR-using projects (500-1,500 tokens per log summary section). The session-start brief is the Quick Resume Context plus up to five pending tasks, ~200 tokens.
All estimates are stated as Low / Median / High ranges to avoid single-point claims. For your own project, plug in the values that match your context and recompute.
Last updated alongside CPR v2.0.0. Methodology may evolve as real-world usage data becomes available.
25 files · 3 not served here
- .claude-plugin/marketplace.json
- .claude-plugin/plugin.json
- .gitignore
- ATTRIBUTION.md
- AUTOGINEER-RUNS.md
- LICENSE
- README.md
- docs/token-savings-analysis.md
- examples/session-log-example.md
- hooks/hooks.json
- llms.txt
- scripts/cpr_common.py
- scripts/cpr_paths.py
- scripts/dump_transcript.py
- scripts/precompact_save.py
- scripts/resume_context.py
- scripts/session_start.py
- skills/compress/SKILL.md
- skills/preserve/SKILL.md
- skills/resume/SKILL.md
- tests/test_scripts.py
- videos/README.md
- videos/compress-demo.mp4 (not served here)
- videos/preserve-demo.mp4 (not served here)
- videos/resume-demo.mp4 (not served here)
Advantages
- Reduces token costs by providing a compact summary of past work instead of re-explaining project history. evidence: README.md
- Ensures no data loss by automatically saving raw transcripts before session compaction. evidence: README.md
Limitations
- Not beneficial for one-off tasks or single-session work where no future context is needed. evidence: README.md
Security
Risk level: Low risk
This brain runs
Hooks (2)
hooks/hooks.json(PreCompact):python3 "${CLAUDE_PLUGIN_ROOT}/scripts/precompact_save.py"hooks/hooks.json(SessionStart):python3 "${CLAUDE_PLUGIN_ROOT}/scripts/session_start.py"
Agent instructions that run or fetch something (7)
skills/compress/SKILL.md:Run it before `/compact` or before ending the session.skills/compress/SKILL.md:!`python3 "${CLAUDE_PLUGIN_ROOT}/scripts/cpr_paths.py"`skills/compress/SKILL.md:Empty: run all three questions.skills/compress/SKILL.md:After the file is saved, run:skills/compress/SKILL.md:python3 "${CLAUDE_PLUGIN_ROOT}/scripts/dump_transcript.py" "{logs_dir}/{filename}" ${CLAUDE_SESSION_ID}skills/preserve/SKILL.md:!`python3 "${CLAUDE_PLUGIN_ROOT}/scripts/cpr_paths.py"`skills/resume/SKILL.md:!`python3 "${CLAUDE_PLUGIN_ROOT}/scripts/resume_context.py" $ARGUMENTS`
- Low risk: scripts-present (scripts/precompact_save.py)
- Low risk: scripts-present (scripts/session_start.py)
Attribution and licence
- Created by
- Elia Alberti
- Declared authors
- Elia Alberti (declared in .claude-plugin/plugin.json)
- Publisher
- Elia Alberti (Community)
- Source
- EliaAlberti/cpr-compress-preserve-resume · commit cfd1e77
- Licence
- MIT License (files served here)
- ATTRIBUTION.md (written by AutoGineer)
- Synced
AutoGineer is not affiliated with or endorsed by Elia Alberti.
Install from source
3 of its files are not served here, so there is no ZIP. EliaAlberti/cpr-compress-preserve-resume at cfd1e77