capy-cortex — Claude Code skill: agent memory that learns from errors
capy-cortex keeps a local base of rules, anti-patterns and preferences, then feeds the matching ones into context through hooks. Useful when an agent keeps repeating the same mistakes.
MIT ★ 138 updated 2026-09-03
npx skills add happycapy-ai/Happycapy-skills --skill capy-cortex -a claude-codeWhat capy-cortex does
Under the hood it is a local SQLite file with an FTS5 index plus a TF-IDF model built with sklearn. Hooks read from it without being asked: session start brings in anti-patterns, preferences and principles, and each prompt pulls rules that match the current task.
Learning happens while you work. A failed tool call is filed as an anti-pattern, the Stop hook mines the conversation for corrections and preferences, reflect.py goes through session transcripts, consolidate.py clusters similar rules into principles, decay fades the ones nobody reinforced. The PreToolUse(Bash) hook also blocks bash commands it has been taught to treat as dangerous, which changes agent behaviour beyond memory alone.
Everything runs through python3, and the database sits at ~/.claude/skills/capy-cortex/cortex.db. Clustering depends on sklearn, so that library has to be present in the same Python environment or consolidate.py fails. Hooks fire on their own; calling them by hand is not part of the flow.
What it helps with
- stop the agent from repeating a command that already failed
- pull stack-specific rules before starting a task
- turn scattered user corrections into general principles
- block a bash command the agent has broken things with
- inspect what the knowledge base has collected so far
Example prompts for the agent
- Show me which rules you already have for React and TypeScript
- Add an anti-pattern: never force push to main
- Run consolidation and list the principles it produced
How to install capy-cortex
1Skills CLI (Vercel)
npx skills add happycapy-ai/Happycapy-skills --skill capy-cortex -a claude-code2Manually: put the files in place
~/.claude/skills/capy-cortex/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/capy-cortex/
1Skills CLI (Vercel)
npx skills add happycapy-ai/Happycapy-skills --skill capy-cortex -a codex2Manually: put the files in place
.agents/skills/capy-cortex/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add happycapy-ai/Happycapy-skills --skill capy-cortex -a cursor2Manually: put the files in place
.cursor/skills/capy-cortex/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install happycapy-ai/Happycapy-skills skills/capy-cortex2Manually: put the files in place
.github/skills/capy-cortex/SKILL.md1Skills CLI (Vercel)
npx skills add happycapy-ai/Happycapy-skills --skill capy-cortex -a gemini-cli2Platform CLI
gemini skills install https://github.com/happycapy-ai/Happycapy-skills --path skills/capy-cortexManually: put the files in place
.devin/skills/capy-cortex/SKILL.mdThe legacy .windsurf/skills/ path still works
Claude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about capy-cortex
How do I install capy-cortex in Claude Code?
Run npx skills add happycapy-ai/Happycapy-skills --skill capy-cortex -a claude-code. The skill then sits at ~/.claude/skills/capy-cortex/SKILL.md.
What does capy-cortex do?
It stores rules, preferences and anti-patterns in SQLite and loads the relevant ones through hooks. Errors and corrections from the conversation end up in that store too.
What does rule consolidation need?
consolidate.py clusters entries with sklearn, so the library must live in the same Python environment as the other scripts. Without it the consolidation step does not run.
Source text
SKILL.md · MIT
--- name: capy-cortex description: "Autonomous learning system - learns from mistakes, reflects on sessions, and gets smarter over time. The AI brain." --- # Capy Cortex - Autonomous Learning System You have a persistent learning brain powered by SQLite + FTS5 + sklearn TF-IDF. Knowledge is automatically loaded via hooks. This file describes manual operations. ## Architecture - **Database**: `~/.claude/skills/capy-cortex/cortex.db` (SQLite + FTS5 + WAL) - **Hooks** (automatic, never call manually): - SessionStart: Loads anti-patterns, preferences, principles - UserPromptSubmit: Retrieves task-relevant rules via FTS5 - PreToolUse(Bash): Blocks known dangerous commands - PostToolUseFailure: Records errors as anti-patterns - Stop: Extracts corrections and preferences from conversation - **Scripts** (for manual/scheduled use): - `cortex.py`: Core engine (retrieve, add rules, stats) - `reflect.py`: Deep session analysis - `consolidate.py`: Cluster rules into principles (sklearn) - `bootstrap.py`: Mine historical sessions ## Manual Commands ```bash # Check system health python3 ~/.claude/skills/capy-cortex/scripts/cortex.py stats # Retrieve rules for a topic python3 ~/.claude/skills/capy-cortex/scripts/cortex.py retrieve "react typescript" # Add a rule manually python3 ~/.claude/skills/capy-cortex/scripts/cortex.py add-rule "Always use TypeScript strict mode" "best_practice" # Add an anti-pattern python3 ~/.claude/skills/capy-cortex/scripts/cortex.py add-ap "Never force push to main" "critical" # Add a preference python3 ~/.claude/skills/capy-cortex/scripts/cortex.py add-pref "User prefers functional components over class components" # Run consolidation (clusters rules into principles) python3 ~/.claude/skills/capy-cortex/scripts/consolidate.py # Retrain TF-IDF model python3 ~/.claude/skills/capy-cortex/scripts/cortex.py retrain # Apply confidence decay python3 ~/.claude/skills/capy-cortex/scripts/cortex.py decay ``` ## How It Learns 1. **Automatic** (via hooks): Errors are captured, corrections noted, preferences extracted 2. **Reflection**: Deep analysis of session transcripts extracts patterns 3. **Consolidation**: sklearn clustering groups similar rules into principles 4. **Decay**: Old, unreinforced rules fade; validated rules strengthen 5. **Retrieval**: Two-stage FTS5 + TF-IDF returns only relevant knowledge (O(1) context)
© happycapy-ai · MIT · happycapy-ai/Happycapy-skills