Persistent memory across sessions. Never lose context again.
Estimated ~55% reduction in session-restart token cost (analytical model, range 24-68%).
|
/preserve Save key learnings to CLAUDE.md PRESERVE.mp4 |
/compress Capture the full session to a searchable log COMPRESS.mp4 |
/resume Restore context from past sessions RESUME.mp4 |
Three custom skills that save, search, and restore your conversation context, so you can pick up exactly where you left off.
Problem • Solution • Why It Saves Tokens • Installation • Usage • Workflow • Scaling • FAQ
Skills are custom slash commands for Claude Code. You type /preserve, /compress, or /resume in your conversation and Claude follows the instructions defined in a markdown file. No code, no plugins, just a .md file in the right folder.
Claude Code loads skills from two locations:
| Location | Scope |
|---|---|
~/.claude/commands/*.md |
Global, available in every project |
{project}/.claude/commands/*.md |
Per-project, available only in that project |
Each .md file becomes a /command you can run. That's it. CPR is three of these files.
Claude Code has no memory between sessions. When you close a conversation, everything is gone: decisions, solutions, context, all of it.
It gets worse:
| Problem | Impact |
|---|---|
| Auto-compacting loses details | Context window fills up and Claude silently compresses history, flattening specific values, file paths, and nuanced decisions |
| 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 isn't enough | Static file that doesn't capture the flow of decisions, errors, or solutions |
Three skills that work together to give Claude Code a memory:
Session Work ──> /preserve ──> CLAUDE.md updated
/compress ──> Session Log saved
|
/compact ──> Context compressed (always LAST)
|
New Session ──> /resume ──> Loads CLAUDE.md + recent logs ──> Full context restored
| Skill | What it does |
|---|---|
/preserve |
Updates CLAUDE.md with key learnings from the session. Keeps it lean (under 280 lines) with automatic archiving when it gets too long. |
/compress |
Captures the full session (decisions, solutions, files, errors) into a structured, searchable log file. |
/resume |
Loads CLAUDE.md + last N session log summaries when starting a new session. Supports topic search across all past sessions. |
Run /preserve and /compress (in any order) BEFORE /compact. /compact clears the entire context window, so always run it last.
Claude Code's auto-compact feature automatically compresses your conversation when the context window fills up. This is the enemy, throwing away details before you can save them.
Disable it:
- Type
/configinside Claude Code - Set Auto-Compact to false (it's the first option)
Or via CLI:
claude config set --global autoCompact falseWith auto-compact off, you control when compression happens:
/preserve: update CLAUDE.md with key learnings/compress: save the session log (preserves everything)/compact: compress the context (always last, because you already saved)
This gives you a clean, explicit workflow instead of silent data loss.
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 24% in the low case, 55% in the median case, and 68% in the high case. On a 10-session project that's roughly ~83,250 tokens saved at the median. On a 20-session, high-context project it's ~535,800 tokens saved.
| Case | Without CPR | With CPR | Savings | % saved |
|---|---|---|---|---|
| Low | 4,850 | 3,700 | 1,150 | 24% |
| Median | 16,750 | 7,500 | 9,250 | 55% |
| High | 41,200 | 13,000 | 28,200 | 68% |
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 ~3,700 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.
Every /compress creates a structured markdown file in CC-Session-Logs/ at your project root.
Filename format: DD-MM-YYYY-HH_MM-topic-name.md
Log structure (click to expand)
# Session Log: 05-03-2026 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 for fast loading in /resume.
---
## Raw Session Log
{Full conversation archive, searchable but never loaded by /resume}The key insight: /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.
See examples/session-log-example.md for a complete example.
git clone https://github.com/eliaalberti/cpr-compress-preserve-resume.git
cd cpr-compress-preserve-resumeSkills are .md files that go in a commands/ folder. Pick one:
Global install (available in all projects):
mkdir -p ~/.claude/commands
cp commands/*.md ~/.claude/commands/Per-project install (available only in that project):
mkdir -p /path/to/your/project/.claude/commands
cp commands/*.md /path/to/your/project/.claude/commands/Skills are loaded at startup. Restart for the new /preserve, /compress, and /resume commands to appear.
All three skills default to Claude Opus (model: opus in frontmatter) for maximum context understanding and output quality. If you don't have Opus access, change model: opus to model: sonnet in each file's frontmatter. Sonnet 4.6 works well as a fallback.
Type /config inside Claude Code and set Auto-Compact to false (first option).
Or via CLI:
claude config set --global autoCompact falseThis step is critical. Without it, Claude Code will silently compress your context before you get a chance to save it with /preserve or /compress.
You: /compress
If you see the preservation question, it's working.
You: /preserve
Claude: What should be preserved? [multi-select]
You: 2, 6 (Key Decisions, Next Steps)
Claude: CLAUDE.md Updated
Preserved:
- Added JWT auth decision rationale
- Updated next steps with token rotation
CLAUDE.md is now 185 lines (target: <280)
You: /compress
Claude: What would you like to preserve? [multi-select]
1. Key Learnings
2. Solutions & Fixes
3. Decisions Made
4. Files Modified
...
You: 1, 2, 3, 4
Claude: Anything specific to highlight? (Type 'skip' to continue)
You: skip
Claude: Suggested topic: api-auth-refactor. Accept or type your own:
You: ok
Claude: Session saved to CC-Session-Logs/05-03-2026-17_30-api-auth-refactor.md
Run /compact to compress context.
You: /resume
Claude:
══════════════════════════════════════════════
RESUMING: my-saas-app
══════════════════════════════════════════════
CONTEXT:
- JWT auth flow implemented, tests passing
- Redis used for refresh token storage
MOST RECENT SESSION: 05-03-2026 17:30
Topic: api-auth-refactor
...
READY TO:
- Add refresh token rotation
- Set up token blacklist for logout
══════════════════════════════════════════════
You: /resume auth
Claude: [Shows recent sessions + RELATED SESSIONS matching "auth"]
══════════════════════════════════════════════
RELATED SESSIONS (Topic: "auth")
══════════════════════════════════════════════
- 05-03-2026: api-auth-refactor, JWT + refresh tokens
- 28-02-2026: oauth-google-setup, Google OAuth integration
══════════════════════════════════════════════
┌──────────────────────────────────────────────────────┐
│ 1. Start session │
│ └── /resume Load context │
│ │
│ 2. Do work... │
│ └── (normal Claude Code usage) │
│ │
│ 3. Before ending or when context is filling up │
│ ├── /preserve Update CLAUDE.md (optional) │
│ ├── /compress Save session log │
│ └── /compact Compress context (LAST) │
└──────────────────────────────────────────────────────┘
When to /preserve:
- After making important architectural decisions
- When you discover patterns you'll need in future sessions
- When project phase/status changes
When to /compress:
- Before ending a session
- Before context fills up (if you notice responses getting less specific)
- After completing a significant chunk of work
Session log storage path
By default, logs go to {project_root}/CC-Session-Logs/. The project root is detected by walking up from your current directory looking for CLAUDE.md or .git.
To change this, edit the path detection logic in commands/compress.md and commands/resume.md (Step 5 / Step 3 respectively).
CLAUDE.md line target
The default target is 280 lines. Change this in commands/preserve.md (Step 6) by modifying the threshold value.
Protected sections
Mark any section in your CLAUDE.md as immune to archiving:
## My Important Section (PROTECTED)
This will never be suggested for archiving.Or mark sections as safe to archive:
## Old Notes (ARCHIVABLE)
This will be auto-suggested for archiving when CLAUDE.md gets too long.Core sections
Edit the "CORE Sections" list in commands/preserve.md to match your CLAUDE.md structure. These sections are never suggested for archiving.
| Session Logs | Behaviour |
|---|---|
| < 100 | Direct file listing + grep search, fast and simple |
| >= 100 | Grep-based search for topic matching, still fast |
| Any count | /resume reads summaries only, never raw logs, token-efficient at any scale |
The raw session logs can grow large (full conversation archives), but /resume never reads past the ## Raw Session Log marker. Only the structured summary header is loaded.
Do I need all three skills?
/compress + /resume is the minimum viable setup. /preserve is optional but recommended. It keeps your CLAUDE.md up to date without manual editing.
Where are logs stored?
{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.
Will this work with any project?
Yes. The skills auto-detect your project root and create the CC-Session-Logs/ folder on first use. No configuration needed.
How big do logs get?
A full session log with the raw conversation can be several hundred KB. But /resume only reads the summary header (typically 30-80 lines), so token usage stays low regardless of log size.
Should I commit session logs to git?
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.
What if I forget to /preserve or /compress before /compact?
The compacted context will still work, but you'll lose the detailed session log and CLAUDE.md updates. Always run /preserve and/or /compress before /compact, since /compact clears the entire context window.
Can I use this with CLAUDE.md files in subdirectories?
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.
Created by Elia Alberti. Built with and for Claude Code.
MIT. See LICENSE.