Your AI coding agent learns from every session. Claude Recall captures patterns, corrections, and gotchas so you never repeat the same mistakes. It tracks multi-step work across sessions with handoffs, ensuring continuity when context resets.
Works with Claude Code, OpenCode, and other AI coding tools.
git clone https://github.com/prestonbrown/claude-recall.git
cd claude-recall
./install.shThat's it. The installer configures hooks automatically.
Install options
./install.sh --claude # Claude Code only
./install.sh --opencode # OpenCode onlyOnce installed, Claude Recall works automatically:
- Session start: Top lessons and active handoffs inject into context
- First prompt: Haiku scores all lessons for relevance, injects the most useful ones
- During work: Agent cites lessons (
[L001]) when applying them - citations boost lesson rankings - Session end: New lessons captured from
LESSON:commands, handoffs synced from TodoWrite - Weekly: Unused lessons decay in ranking, keeping your knowledge base fresh
You'll see lessons appear in your agent's context. Cite them to boost their ranking, or let unused ones fade naturally.
- Two-tier architecture: Project lessons (
[L###]) and system lessons ([S###]) - Smart injection: First prompt triggers Haiku-based relevance scoring for context-aware lessons
- Dual-dimension rating:
[uses|velocity]shows both total usage and recent activity - Automatic promotion: 50+ uses promotes project lessons to system level
- Velocity decay: Lessons lose momentum when not used, stay relevant
- AI-generated lessons: Agent can propose lessons (marked with robot emoji)
- Token tracking: Warns when context injection is heavy (>2000 tokens)
- TodoWrite sync: Use TodoWrite naturally - todos auto-sync to HANDOFFS.md for persistence
- Work tracking: Track ongoing tasks with tried steps and next steps
- Phases:
research→planning→implementing→review - Session continuity: Handoffs restore as TodoWrite suggestions on next session
- Completion workflow: Extract lessons when finishing work
- Command patterns:
HANDOFF:,HANDOFF UPDATE,HANDOFF COMPLETE
- Go performance layer: Citation processing uses Go binaries for ~10x faster hook execution
- TUI monitoring:
claude-recall watchfor real-time debug log monitoring - Alerting system:
claude-recall alerts checkandalerts digestfor system health - Debug logging: Structured JSON logs with configurable verbosity levels
The OpenCode adapter provides the same learning capabilities as the Claude Code adapter, with ~95% feature parity.
./install.sh --opencode- Lessons system (injection, capture, decay, reminders)
- Handoffs system (tracking, TodoWrite sync)
- Compaction support
- Debug logging
Create or edit ~/.config/claude-recall/config.json:
{
"enabled": true,
"topLessonsToShow": 5,
"relevanceTopN": 5,
"remindEvery": 12,
"decayIntervalDays": 7,
"debugLevel": 1
}See /lessons and /handoffs commands in OpenCode for more details.
Run the installer to automatically migrate:
./install.shThis migrates:
~/.config/coding-agent-lessons/→~/.config/claude-recall/.coding-agent-lessons/→.claude-recall/
Environment variables (all work, checked in order):
CLAUDE_RECALL_BASE(preferred)RECALL_BASE(legacy)LESSONS_BASE(legacy)
Type directly in your coding agent session:
LESSON: Always use spdlog - Never use printf or cout for logging
LESSON: pattern: XML event_cb - Use XML event_cb not lv_obj_add_event_cb()
SYSTEM LESSON: preference: Git commits - Use simple double-quoted strings
Format: LESSON: [category:] title - content
Categories: pattern, correction, decision, gotcha, preference
For multi-step work, just use TodoWrite - it auto-syncs to HANDOFFS.md:
[Agent uses TodoWrite naturally]
→ stop-hook captures todos to HANDOFFS.md
→ Next session: inject-hook restores as continuation prompt
Your todos map to handoff fields:
completedtodos →triedentries (success)in_progresstodo → checkpoint (current focus)pendingtodos → next steps
Manual handoff commands (for explicit control):
HANDOFF: Implement WebSocket reconnection
HANDOFF UPDATE hf-abc1234: tried fail - Simple setTimeout retry races with disconnect
HANDOFF UPDATE hf-abc1234: tried success - Event-based with AbortController
HANDOFF COMPLETE hf-abc1234
When entering plan mode, create a tracked handoff:
PLAN MODE: Implement user authentication
This creates a handoff with phase=research and agent=plan.
Use the /lessons slash command:
/lessons # List all lessons
/lessons search <term> # Search by keyword
/lessons category gotcha # Filter by category
/lessons stale # Show lessons uncited 60+ days
/lessons edit L005 "New text" # Edit a lesson's content
/lessons delete L003 # Delete a lesson
- Session Start: Top 3 lessons by stars + handoffs injected as context
- First Prompt: Smart injection scores all lessons against query via Haiku, injects most relevant
- Citation: Agent cites
[L001]when applying → uses/velocity increase - Decay: Weekly decay reduces velocity; stale lessons lose uses
- Promotion: 50+ uses → project lesson promotes to system level
[*----|-----] 1 use, no velocity (new)
[**---|+----] 3 uses, some recent activity
[****-|**---] 15 uses, moderate velocity
[*****|*****] 31+ uses, high velocity (very active)
Left side: Total uses (logarithmic scale) Right side: Recent velocity (decays over time)
Via TodoWrite (recommended):
- Use TodoWrite: Agent uses TodoWrite naturally with reminders
- Auto-sync: stop-hook captures final todo state to HANDOFFS.md
- Restore: Next session, inject-hook formats handoff as TodoWrite continuation
Via manual commands:
- Create:
HANDOFF: titleorPLAN MODE: title - Track: Update status, phase, tried steps, next steps
- Complete:
HANDOFF COMPLETE hf-abc1234triggers lesson extraction prompt - Archive: Completed handoffs move to archive, recent ones stay visible
The system can infer phases from tool usage:
| Tools Used | Inferred Phase |
|---|---|
| Read, Grep, Glob | research |
| Write to .md, AskUserQuestion | planning |
| Edit, Write to code files | implementing |
| Bash (test/build commands) | review |
~/.local/state/claude-recall/
├── LESSONS.md # System lessons (apply everywhere)
├── debug.log # Debug logs (XDG state directory)
├── .decay-last-run # Decay timestamp
├── .citation-state/ # Per-session checkpoints
└── relevance-cache.json # Haiku score cache
~/.config/claude-recall/
└── config.json # User configuration (optional)
<project>/.claude-recall/
├── LESSONS.md # Project-specific lessons
└── HANDOFFS.md # Active work tracking
claude-recall/
├── core/ # Python implementation
│ ├── cli.py # CLI entry point
│ └── ... # Manager, models, parsing
├── adapters/claude-code/ # Hook scripts
├── go/ # Go performance layer
└── tests/ # 1900+ tests
# Check version
python3 core/cli.py --version
# Lessons
python3 core/cli.py add pattern "Title" "Content"
python3 core/cli.py add --system pattern "Title" "Content" # System lesson
python3 core/cli.py cite L001
python3 core/cli.py list [--project|--system] [--category X]
python3 core/cli.py inject 5 # Top 5 by stars
python3 core/cli.py score-relevance "query" # Relevance scoring via Haiku
# Handoffs (work tracking)
python3 core/cli.py handoff add "Title" [--phase X]
python3 core/cli.py handoff update A001 --status in_progress
python3 core/cli.py handoff list
python3 core/cli.py handoff inject # For context injectionThe stop-hook recognizes these patterns in assistant output:
LESSON: title - content # Add project lesson
LESSON: category: title - content # Add with category
[L001]: Applied... # Citation (increments uses/velocity)
[S002]: Following... # System lesson citation
CLAUDE_RECALL_BASE=~/.config/claude-recall # System lessons location (preferred)
CLAUDE_RECALL_CONFIG=~/.config/claude-recall/config.json # Shared config override
RECALL_BASE=~/.config/claude-recall # Legacy alias
LESSONS_BASE=~/.config/claude-recall # Legacy alias
PROJECT_DIR=/path/to/project # Project root
CLAUDE_RECALL_DEBUG=0|1|2|3 # Debug logging level (preferred)
RECALL_DEBUG=0|1|2|3 # Legacy alias
LESSONS_DEBUG=0|1|2|3 # Legacy aliasEnable structured JSON logging:
export CLAUDE_RECALL_DEBUG=1 # 0=off, 1=info, 2=debug, 3=traceLogs written to ~/.local/state/claude-recall/debug.log (XDG state directory).
In ~/.config/claude-recall/config.json:
{
"enabled": true,
"debugLevel": 0,
"remindEvery": 12,
"topLessonsToShow": 5,
"relevanceTopN": 5,
"promotionThreshold": 50,
"decayIntervalDays": 7,
"maxLessons": 30
}When installed as a plugin, hooks are automatically configured via plugins/claude-recall/hooks/hooks.json:
| Hook | Scripts | Purpose |
|---|---|---|
SessionStart |
inject-hook.sh | Inject lessons + handoffs |
UserPromptSubmit |
capture-hook.sh, smart-inject-hook.sh, lesson-reminder-hook.sh | Capture prompt, relevance scoring, reminders |
Stop |
stop-hook.sh, session-end-hook.sh | Extract citations, sync handoffs |
PreCompact |
precompact-hook.sh | Preserve session progress |
PostToolUse:ExitPlanMode |
post-exitplanmode-hook.sh | Create handoff from plan |
PostToolUse:TodoWrite |
post-todowrite-hook.sh | Sync todos to handoffs |
See docs/ARCHITECTURE.md for the full hook registration format.
| Setting | Default | Description |
|---|---|---|
enabled |
true | Enable/disable the lessons system |
debugLevel |
0 | 0=off, 1=info, 2=debug, 3=trace |
remindEvery |
12 | Show lesson duty reminder every N prompts |
topLessonsToShow |
5 | Lessons injected at session start (with full content) |
relevanceTopN |
5 | Lessons injected by relevance scoring |
promotionThreshold |
50 | Uses before project→system promotion |
decayIntervalDays |
7 | Days between decay runs |
maxLessons |
30 | Max lessons per level before eviction |
When working with you, the agent will:
- CITE lessons when applying: "Applying [L001]: using XML event_cb..."
- PROPOSE lessons when corrected or discovering patterns
- TRACK handoffs for multi-step work
- UPDATE phase and status as work progresses
- EXTRACT lessons when completing handoffs
# Run all tests (1900+ tests)
./run-tests.sh
# Run specific test files
./run-tests.sh tests/test_lessons_manager.py -v # Lesson tests
./run-tests.sh tests/test_handoffs.py -v # Handoff tests
./run-tests.sh tests/test_tui/ -v # TUI testsSee docs/TESTING.md for detailed testing guide.
- DEVELOPMENT.md - Architecture and contributing
- docs/TESTING.md - Test framework
- docs/DEPLOYMENT.md - Installation and hooks
MIT License - see LICENSE