Local-first observability and memory for Claude Code
Code Agent Insights helps developers build persistent memory and understanding across Claude Code sessions. Index your coding sessions to:
- 🔍 Search past sessions ("how did I fix that auth bug?")
- 🧠 Extract learnings automatically from sessions
- 📊 Track patterns, errors, and outcomes
- 💡 Build persistent memory across sessions
- 📈 Understand which Claude Code features (skills, sub-agents, modes) work best
- Automatically discover and index sessions from
~/.claude/ - Support for JSONL and JSON formats
- Robust parsing with graceful error handling
- Filter by date with
--sinceflag (7d, 2w, 1m, YYYY-MM-DD)
- Search across all sessions with FTS5
- Filter by project, limit results
- Optional AI-powered summarization
- Overall metrics - Sessions, tokens, errors, success rates
- Trends analysis - Productivity trends over time with period grouping
- Tool effectiveness - Which tools/features work best vs baseline
- Error analysis - Recurring errors, resolution rates, documented fixes
- Comprehensive reports - Manager-friendly summaries with period comparison
- Mode comparison - Plan mode, thinking, sub-agents effectiveness
- Skill usage breakdown - Track skill invocations and ROI
- Tool pattern analysis - Common tool sequences and success rates
- Sub-agent effectiveness - Delegation outcomes and token efficiency
- Auto-extract learnings via Claude API
- Manual learning creation
- Interactive review interface
- Duplicate detection and cleanup
- Low-confidence filtering
- recall - Search past learnings and session summaries during coding
- remember - Save learnings in real-time during sessions
- similar_errors - Find past error resolutions
- file_history - Get session history for files
- session_search - Search sessions by content, date, or outcome (NEW!)
- Seamless integration with Claude Code
- Session-commit correlation - Match sessions to commits with confidence scoring
- Project overview - List all tracked projects with stats
- CLAUDE.md sync - Push learnings to project documentation
- Smart merging with idempotency and dry-run mode
- Filter by global/project scope and confidence levels
- Automatic session summaries - Claude API generates structured summaries
- Tracks work done, files changed, errors, and key decisions
- Searchable summaries -
cai searchand MCP recall tool display session summaries - Auto-summarize via hooks - Automatic summarization after session completion
- Dry-run mode and force re-summarization options
- User preferences - YAML-based config at
~/.code-agent-insights/config.yaml - Session hooks - Automatic indexing, summarization, and sync after sessions
- Auto-sync triggers - Event-driven sync after review/clean operations
- Configurable thresholds - Control auto-summarize, sync options, and confidence levels
- Handles malformed JSONL/JSON gracefully
- Skips invalid lines while preserving valid data
- Detailed warnings with
--verboseflag - Support for all Claude Code event types
Note: Package is not yet published to npm. Install from source for now.
- Node.js 20+ and pnpm (or npm)
- Claude Code installed
- Git
# Clone the repository
git clone https://github.com/numiadata/code-agent-insights.git
cd code-agent-insights
# Install dependencies
pnpm install
# Build all packages
pnpm build
# Link CLI globally
cd packages/cli
pnpm link --global
# Verify installation
cai --version
# Setup MCP server for Claude Code integration
cai setup-mcp
# Restart Claude Code to load MCP serverFor learning extraction and embeddings:
cd packages/extractor
pip install -e .To use AI-powered features (cai summarize, cai index --extract), set your Anthropic API key:
# Add to your ~/.bashrc, ~/.zshrc, or equivalent
export ANTHROPIC_API_KEY=sk-ant-...Important:
- Get your API key from Anthropic Console
- Ensure your account has credits at Billing
- Without the API key, only basic indexing and search will work
# Index your Claude Code sessions
cai index
# Install session hooks for automatic indexing
cai hooks install
# Search for specific topics
cai search "authentication bug"
# View statistics
cai stats
# See mode effectiveness
cai stats --modes
# Review learnings interactively
cai review --limit 10
# Clean up duplicates (dry run)
cai clean --duplicates --dry-runNote: After running cai hooks install, your sessions will be automatically indexed, summarized, and synced after each Claude Code session ends.
The MCP server provides in-session memory tools for Claude Code:
- recall - Search past learnings and session summaries during coding
- remember - Save learnings in real-time during sessions
- similar_errors - Find past error resolutions
- file_history - Get session history for files
- session_search - Search sessions by content, date, or outcome
# After installing code-agent-insights, run:
cai setup-mcp
# Then restart Claude CodeThis automatically configures the MCP server globally for all your Claude Code sessions.
If you prefer manual configuration, add to ~/.claude.json:
claude mcp add --transport stdio --scope user code-agent-insights -- cai-mcpImportant: Always restart Claude Code after configuration changes for the tools to become available.
Once configured, these tools become available in Claude Code:
mcp__code-agent-insights__recall- Search learnings and session summariesmcp__code-agent-insights__remember- Save new learningsmcp__code-agent-insights__similar_errors- Find past errorsmcp__code-agent-insights__file_history- Get file session historymcp__code-agent-insights__session_search- Search sessions by content, date, or outcome
See MCP_TESTING_GUIDE.md for detailed testing instructions.
Index coding agent sessions from ~/.claude/
cai index # Index all new sessions
cai index --since 7d # Only last 7 days
cai index --since 2025-01-01 # Since specific date
cai index --embed # Generate embeddings
cai index --extract # Extract learnings (requires API key)
cai index --verbose # Show parse warningsFull-text search across sessions and learnings. Displays session summaries when available.
cai search "react hooks"
cai search "error handling" -n 20
cai search "database" -p ./my-project
cai search "async await" --summarize # Add AI-powered summary of findings
cai search "authentication" --since 7d # Last 7 days
cai search "bug fix" --since 2025-01-01 # Since specific dateOutput includes:
- Matching learnings with tags
- Related sessions with summaries (from
cai summarize) - Session metadata (date, turns, outcome, features used)
View analytics and statistics
cai stats # Overall statistics
cai stats --skills # Skill usage breakdown
cai stats --tools # Tool pattern analysis
cai stats --agents # Sub-agent effectiveness
cai stats --modes # Mode comparison
cai stats --json # JSON outputManually add a learning
cai learn "Always use pnpm in this repo"
cai learn "Auth bugs usually in middleware" -t pattern -s global
cai learn "Use --break-system-packages for pip" --tags python,pipExtract learnings from past sessions using AI
ANTHROPIC_API_KEY environment variable
# Extract from sessions without learnings
cai extract # Process 10 sessions (default)
cai extract --all # Process ALL sessions without learnings
cai extract --limit 20 # Process up to 20 sessions
cai extract --since 30d # Extract from last 30 days
cai extract --session-id <id> # Extract from specific session
cai extract --force --limit 5 # Re-extract from 5 recent sessions
cai extract --dry-run # Preview without API callsUse cases:
- First-time setup: Extract learnings from all past sessions with
cai extract --all - Regular extraction: Process recent sessions with
cai extract --since 7d - Selective extraction: Target specific sessions with
--session-id
Note: For new sessions going forward, enable automatic extraction with hooks (cai hooks install).
Clean up learnings database
cai clean --duplicates --dry-run # Preview duplicate removal
cai clean --type context # Remove all context learnings
cai clean --low-confidence --threshold 0.6 # Remove low-confidenceInteractive learning review
cai review # Review all learnings
cai review --unreviewed # Only unreviewed
cai review --type pattern # Filter by type
cai review --limit 50 # Limit count
cai review -p ./my-project # Filter by projectActions: (k)eep | (d)elete | (e)dit | (s)kip | (q)uit
Generate AI-powered session summaries
ANTHROPIC_API_KEY environment variable and account credits
# First time setup
export ANTHROPIC_API_KEY=sk-ant-... # Get from https://console.anthropic.com/settings/keys
# Summarize sessions
cai summarize --last-session # Summarize most recent session
cai summarize --all # Summarize ALL sessions without summaries (no limit)
cai summarize --limit 10 # Summarize up to 10 sessions without summaries
cai summarize --session-id <id> # Summarize specific session
cai summarize --force --limit 20 # Re-summarize existing (use with --limit)
cai summarize --dry-run # Preview without calling API
# Regenerate ALL summaries for all sessions (useful after API issues are fixed)
cai summarize --all
# Check if summaries exist
sqlite3 ~/.code-agent-insights/insights.db "SELECT COUNT(*) FROM session_summaries"
sqlite3 ~/.code-agent-insights/insights.db "SELECT COUNT(*) FROM sessions"Manage configuration settings
cai config show # Show all config
cai config get summarization.autoSummarize # Get specific value
cai config set sync.autoSync true # Set config value
cai config edit # Open in editor
cai config reset # Reset to defaults
cai config path # Show config file pathManage session hooks for automation
cai hooks install # Install and configure post-session hook
cai hooks uninstall # Remove post-session hook
cai hooks status # Check hook installation and activity
cai hooks logs # Show recent hook execution logs
cai hooks logs -f # Follow hook logs in real-time (great for debugging!)
cai hooks logs -n 50 # Show last 50 linesWhat cai hooks install does:
- Creates
~/.claude/hooks/post-session.shscript - Automatically configures
~/.claude/settings.jsonto enable the hook - No manual configuration needed!
The post-session hook automatically runs after each session and:
- Indexes new sessions (
cai index --since 6h- wider window to avoid timezone issues) - Generates AI summaries (if
ANTHROPIC_API_KEYis set) - Syncs learnings to CLAUDE.md (if
autoSync: truein config) - Logs detailed execution info to
~/.code-agent-insights/hooks.log
For other users: When sharing this project, users just need to run cai hooks install - it will automatically configure their Claude Code installation.
Debugging hooks: If hooks aren't running automatically or stats aren't updating:
-
Watch hook execution in real-time:
# In a separate terminal, run: cai hooks logs -f # Then end your Claude Code session and watch the logs
-
Check hook status:
cai hooks status # Shows installation status and recent activity -
View recent logs:
cai hooks logs -n 30 # Show last 30 log lines -
Manually test the hook:
~/.claude/hooks/post-session.sh # Should index recent sessions
-
Verify Claude Code configuration: Check
~/.claude/settings.jsoncontains the correct format (see below)
The correct hook configuration in ~/.claude/settings.json should be:
{
"hooks": {
"SessionEnd": [
{
"hooks": [
{
"type": "command",
"command": "/Users/your-username/.claude/hooks/post-session.sh"
}
]
}
]
}
}Note: Versions prior to v0.3.5 used an incorrect postSession format. If you installed hooks before this version, run cai hooks install again to update to the correct SessionEnd format.
Get personalized feature recommendations
cai recommend
cai recommend -p ./my-projectList all tracked projects
cai projects # Show all projects with stats
cai projects --json # JSON output for scripting
cai projects --with-learnings # Include learning countsSync learnings to project CLAUDE.md files
cai sync # Sync all projects
cai sync --dry-run # Preview changes
cai sync -p /path/to/project # Sync specific project
cai sync --min-confidence 0.9 # Only high-confidence learnings
cai sync --no-global # Exclude global learnings
cai sync --reviewed-only # Only reviewed/manual learningsCorrelate coding sessions with git commits
cai correlate # Analyze current project (last 30 days)
cai correlate -p /path/to/project # Analyze specific project
cai correlate --since 7d # Last 7 days only
cai correlate --since 2025-01-01 # Since specific date
cai correlate --insights # Show detailed impact analysisAnalyze productivity trends over time
cai trends # Last 30 days (default)
cai trends --since 7d # Last 7 days
cai trends --since 30d --group-by week # Group by week
cai trends --json # JSON outputAnalyze tool and feature effectiveness
cai effectiveness # All tools (last 30 days)
cai effectiveness --since 7d # Last 7 days
cai effectiveness --category modes # Filter by category
cai effectiveness --min-sessions 2 # Lower threshold
cai effectiveness --json # JSON outputCategories: modes, agents, skills, file_ops, execution, search, mcp, navigation, notebook, other
Analyze error patterns and resolution rates
cai errors # Last 30 days (default)
cai errors --since 7d # Last 7 days
cai errors --limit 20 # Show top 20 error types
cai errors --json # JSON outputGenerate comprehensive analytics report
cai report # Weekly report (7 days)
cai report --since 30d # Monthly report
cai report --title "Q1 Summary" # Custom title
cai report --json # JSON output for APIInitialize conventions for a project
cai init # Initialize current project
cai init /path/to/project # Initialize specific project
cai init --force # Overwrite existing filesWhat it does:
- Updates/creates CLAUDE.md with conventions section
- Creates
.claude/skills/code-agent-insights/SKILL.mdfor Claude Code - Sets up best practices and workflow guidance
code-agent-insights/
├── packages/
│ ├── core/ # TypeScript - types, storage, parsers
│ ├── cli/ # TypeScript - CLI interface
│ ├── mcp-server/ # TypeScript - MCP server for in-session tools
│ └── extractor/ # Python - embeddings, LLM extraction
├── CLAUDE.md # Project overview and architecture
├── PROMPTS.md # Development prompts and tasks
└── MCP_TESTING_GUIDE.md # MCP server testing guide
- TypeScript - CLI, core library, MCP server
- Python - Embeddings (sentence-transformers) and LLM extraction
- SQLite - Local storage with FTS5 full-text search
- pnpm - Monorepo management
- better-sqlite3 - High-performance Node.js SQLite binding
- Commander.js - CLI framework
- @modelcontextprotocol/sdk - MCP server implementation
- Claude API - Learning extraction
sessions- Session metadata and statisticssession_summaries- AI-generated session summaries (NEW!)events- All events in sessions (with FTS)tool_calls- Tool invocationserrors- Errors encounteredlearnings- Extracted and manual learnings (with FTS)
skill_invocations- Skill file readssub_agent_invocations- Sub-agent spawnstool_sequences- Tool call patternssession_modes- Mode usage per session
Session Sources (Claude Code, Cursor, VS Code)
↓
TypeScript Parser
↓
SQLite Storage (~/.code-agent-insights/insights.db)
↓
Python Extractor (optional)
↓
┌──────┴──────┐
↓ ↓
CLI MCP Server
↓
Claude Code Session
# Install dependencies
pnpm install
# Build all packages
pnpm build
# Development mode
pnpm dev
# Install Python extractor
cd packages/extractor
pip install -e .Data is stored in ~/.code-agent-insights/:
insights.db- Main databaseembeddings.db- Vector storage (if using embeddings)config.yaml- User preferences (YAML format)hooks.log- Session hook execution log
Configuration options include:
- Summarization: Auto-summarize settings, model selection
- Sync: Auto-sync triggers, confidence thresholds, global/project scope
- Hooks: Enable/disable automatic session processing
ANTHROPIC_API_KEY=sk-... # Required for learning extraction and AI summariesThis is an early beta release. Here's what you should know:
Installation:
- ❌ Not yet published to npm/pnpm registries
- ✅ Install from source works well on macOS (tested)
⚠️ Linux/Windows not extensively tested yet
Compatibility:
- ✅ Claude Code sessions (primary focus)
- ❌ Cursor and VS Code not yet supported
Features:
- ✅ All core features working (indexing, search, analytics, MCP)
⚠️ Learning extraction quality depends on session content⚠️ Large session databases (1000+ sessions) may have slower searches
What we need:
- Beta testers on different platforms
- Feedback on installation experience
- Bug reports and feature requests
- Usage patterns and analytics that would be valuable
If you encounter issues, please open an issue with:
- Your OS and Node.js version
- Full error message
- Steps to reproduce
Contributions are welcome! Please read our contributing guidelines and submit pull requests.
MIT License - see LICENSE file for details
Built with ❤️ using:
- Claude Code - AI pair programmer
- better-sqlite3 - Fast SQLite for Node.js
- Commander.js - CLI framework
- sentence-transformers - Embeddings
🤖 Generated with Claude Code