claude-lcm
Lossless Context Management for Claude Code — a native skill port of the LCM paper (Voltropy, Feb 2026).
Claude Code natively truncates older messages when the context window fills up. claude-lcm replaces that with a deterministic, lossless memory architecture: every message is persisted verbatim in SQLite, older messages are compacted into a hierarchical DAG of summaries, and the agent can always retrieve any prior state.
No OpenClaw required. Works natively in Claude Code as a skill.
What it does
When a session grows beyond comfortable context size, claude-lcm:
- Persists every message verbatim in SQLite — the immutable store
- Compacts older messages into leaf summary nodes using depth-aware LLM prompts
- Condenses summaries into higher-level DAG nodes as they accumulate
- Assembles active context each turn: summaries + recent raw messages (fresh tail)
- Provides retrieval tools (
lcm_grep, lcm_describe, lcm_expand_query) so the agent can search and recall details from compacted history
- Processes large datasets via
lcm_llm_map and lcm_agentic_map (operator-level recursion)
- Writes checkpoints for cross-session continuity
Nothing is lost. The agent that never forgets — because it doesn't.
Architecture
Inspired by the LCM paper and the lossless-claw OpenClaw plugin.
Raw messages → Leaf summaries (d0) → Condensed (d1) → Condensed (d2) → ...
↑ ↑
summary_messages summary_parents
Dual-state memory:
- Immutable Store — SQLite DB, verbatim message history, never modified
- Active Context — assembled from summary nodes + protected fresh tail
Three-level summarization escalation (guaranteed convergence):
- Detailed narrative (LLM)
- Bullet points, half target tokens (LLM)
- Deterministic truncation to 512 tokens (no LLM, never fails)
See .claude/skills/claude-lcm/references/architecture.md for the full schema and algorithms.
Installation
Via Claude Code Plugin Marketplace (recommended)
# In Claude Code, add the marketplace
/plugin marketplace add srikalyan/srikalyan-marketplace
# Install the plugin
/plugin install claude-lcm@srikalyan-marketplace
Manual installation
# Clone and run the install script
git clone https://github.com/srikalyan/claude-lcm.git
cd claude-lcm
./install.sh
Prerequisites
- Claude Code (with
claude CLI on PATH)
python3 (stdlib only, no pip installs needed)
Usage
Initialize a session
python3 scripts/lcm_init.py
source ~/.claude-lcm/session.env
Check context health
python3 scripts/lcm_status.py
Compact when context is filling up
python3 scripts/lcm_compact.py # full pass (leaf + condensation)
python3 scripts/lcm_compact.py --mode leaf # leaf only
python3 scripts/lcm_compact.py --dry-run # preview without writing
Search history
python3 scripts/lcm_grep.py "database migration"
python3 scripts/lcm_grep.py "API threshold" --scope summaries
python3 scripts/lcm_grep.py "config" --mode regex --limit 20
Inspect a summary or file
python3 scripts/lcm_describe.py sum_abc123
python3 scripts/lcm_describe.py file_xyz789
Answer a focused recall question
python3 scripts/lcm_expand_query.py \
--prompt "What was the final decision on the compaction threshold?" \
--query "compaction threshold"
Process a dataset (LLM-Map)
python3 scripts/lcm_llm_map.py \
--input data.jsonl \
--output results.jsonl \
--prompt "Extract entities from this text" \
--schema schema.json \
--concurrency 16
Process with multi-step reasoning (Agentic-Map)
python3 scripts/lcm_agentic_map.py \
--input tasks.jsonl \
--output results.jsonl \
--prompt "Analyze this repository" \
--concurrency 4 --read-only
Session handoff
# Before ending a long session
python3 scripts/lcm_checkpoint.py
# On next session start
python3 scripts/lcm_resume.py
Configuration
Set via environment variables before running scripts (or add to your shell profile):