-Based Architecture
An advanced learning system that turns your Claude Code sessions into reusable knowledge through atomic "instincts" - small learned behaviors with confidence scoring.
v2.1 adds project-scoped instincts — React patterns stay in your React project, Python conventions stay in your Python project, and universal patterns (like "always validate input") are shared globally.
Featurev2.0v2.1StorageGlobal (~/.claude/homunculus/)Project-scoped (projects//)ScopeAll instincts apply everywhereProject-scoped + globalDetectionNonegit remote URL / repo pathPromotionN/AProject → global when seen in 2+ projectsCommands4 (status/evolve/export/import)6 (+promote/projects)Cross-projectContamination riskIsolated by default
Featurev1v2ObservationStop hook (session end)PreToolUse/PostToolUse (100% reliable)AnalysisMain contextBackground agent (Haiku)GranularityFull skillsAtomic "instincts"ConfidenceNone0.3-0.9 weightedEvolutionDirect to skillInstincts -> cluster -> skill/command/agentSharingNoneExport/import instincts
An instinct is a small learned behavior:
yaml
---
id: prefer-functional-style
trigger: "when writing new functions"
confidence: 0.7
domain: "code-style"
source: "session-observation"
scope: project
project_id: "a1b2c3d4e5f6"
project_name: "my-react-app"
---
# Prefer Functional Style
## Action
Use functional patterns over classes when appropriate.
## Evidence
- Observed 5 instances of functional pattern preference
- User corrected class-based approach to functional on 2025-01-15
Properties:
project (default) or globaltext
Session Activity (in a git repo)
|
| Hooks capture prompts + tool use (100% reliable)
| + detect project context (git remote / repo path)
v
+---------------------------------------------+
| projects/<project-hash>/observations.jsonl |
| (prompts, tool calls, outcomes, project) |
+---------------------------------------------+
|
| Observer agent reads (background, Haiku)
v
+---------------------------------------------+
| PATTERN DETECTION |
| * User corrections -> instinct |
| * Error resolutions -> instinct |
| * Repeated workflows -> instinct |
| * Scope decision: project or global? |
+---------------------------------------------+
|
| Creates/updates
v
+---------------------------------------------+
| projects/<project-hash>/instincts/personal/ |
| * prefer-functional.yaml (0.7) [project] |
| * use-react-hooks.yaml (0.9) [project] |
+---------------------------------------------+
| instincts/personal/ (GLOBAL) |
| * always-validate-input.yaml (0.85) [global]|
| * grep-before-edit.yaml (0.6) [global] |
+---------------------------------------------+
|
| /evolve clusters + /promote
v
+---------------------------------------------+
| projects/<hash>/evolved/ (project-scoped) |
| evolved/ (global) |
| * commands/new-feature.md |
| * skills/testing-workflow.md |
| * agents/refactor-specialist.md |
+---------------------------------------------+
The system automatically detects your current project:
CLAUDE_PROJECT_DIR env var (highest priority)git remote get-url origin -- hashed to create a portable project ID (same repo on different machines gets the same ID)git rev-parse --show-toplevel -- fallback using repo path (machine-specific)Each project gets a 12-character hash ID (e.g., a1b2c3d4e5f6). A registry file at ~/.claude/homunculus/projects.json maps IDs to human-readable names.
Add to your ~/.claude/settings.json.
If installed as a plugin (recommended):
json
{
"hooks": {
"PreToolUse": [{
"matcher": "*",
"hooks": [{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/skills/continuous-learning-v2/hooks/observe.sh"
}]
}],
"PostToolUse": [{
"matcher": "*",
"hooks": [{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/skills/continuous-learning-v2/hooks/observe.sh"
}]
}]
}
}
If installed manually to ~/.claude/skills:
json
{
"hooks": {
"PreToolUse": [{
"matcher": "*",
"hooks": [{
"type": "command",
"command": "~/.claude/skills/continuous-learning-v2/hooks/observe.sh"
}]
}],
"PostToolUse": [{
"matcher": "*",
"hooks": [{
"type": "command",
"command": "~/.claude/skills/continuous-learning-v2/hooks/observe.sh"
}]
}]
}
}
The system creates directories automatically on first use, but you can also create them manually:
bash
# Global directories
mkdir -p ~/.claude/homunculus/{instincts/{personal,inherited},evolved/{agents,skills,commands},projects}
# Project directories are auto-created when the hook first runs in a git repo
bash
/instinct-status # Show learned instincts (project + global)
/evolve # Cluster related instincts into skills/commands
/instinct-export # Export instincts to file
/instinct-import # Import instincts from others
/promote # Promote project instincts to global scope
/projects # List all known projects and their instinct counts
CommandDescription/instinct-statusShow all instincts (project-scoped + global) with confidence/evolveCluster related instincts into skills/commands, suggest promotions/instinct-exportExport instincts (filterable by scope/domain)/instinct-import <file>Import instincts with scope control/promote [id]Promote project instincts to global scope/projectsList all known projects and their instinct counts
Edit config.json to control the background observer:
json
{
"version": "2.1",
"observer": {
"enabled": false,
"run_interval_minutes": 5,
"min_observations_to_analyze": 20
}
}
KeyDefaultDescriptionobserver.enabled``falseEnable the background observer agentobserver.run_interval_minutes``5How often the observer analyzes observationsobserver.min_observations_to_analyze``20Minimum observations before analysis runs
Other behavior (observation capture, instinct thresholds, project scoping, promotion criteria) is configured via code defaults in instinct-cli.py and observe.sh.
text
~/.claude/homunculus/
+-- identity.json # Your profile, technical level
+-- projects.json # Registry: project hash -> name/path/remote
+-- observations.jsonl # Global observations (fallback)
+-- instincts/
| +-- personal/ # Global auto-learned instincts
| +-- inherited/ # Global imported instincts
+-- evolved/
| +-- agents/ # Global generated agents
| +-- skills/ # Global generated skills
| +-- commands/ # Global generated commands
+-- projects/
+-- a1b2c3d4e5f6/ # Project hash (from git remote URL)
| +-- project.json # Per-project metadata mirror (id/name/root/remote)
| +-- observations.jsonl
| +-- observations.archive/
| +-- instincts/
| | +-- personal/ # Project-specific auto-learned
| | +-- inherited/ # Project-specific imported
| +-- evolved/
| +-- skills/
| +-- commands/
| +-- agents/
+-- f6e5d4c3b2a1/ # Another project
+-- ...
Pattern TypeScopeExamplesLanguage/framework conventionsproject"Use React hooks", "Follow Django REST patterns"File structure preferencesproject"Tests in __tests__/", "Components in src/components/"Code styleproject"Use functional style", "Prefer dataclasses"Error handling strategiesproject"Use Result type for errors"Security practicesglobal"Validate user input", "Sanitize SQL"General best practicesglobal"Write tests first", "Always handle errors"Tool workflow preferencesglobal"Grep before Edit", "Read before Write"Git practicesglobal"Conventional commits", "Small focused commits"
When the same instinct appears in multiple projects with high confidence, it's a candidate for promotion to global scope.
Auto-promotion criteria:
How to promote:
bash
# Promote a specific instinct
python3 instinct-cli.py promote prefer-explicit-errors
# Auto-promote all qualifying instincts
python3 instinct-cli.py promote
# Preview without changes
python3 instinct-cli.py promote --dry-run
The /evolve command also suggests promotion candidates.
Confidence evolves over time:
ScoreMeaningBehavior0.3TentativeSuggested but not enforced0.5ModerateApplied when relevant0.7StrongAuto-approved for application0.9Near-certainCore behavior
Confidence increases when:
Confidence decreases when:
"v1 relied on skills to observe. Skills are probabilistic -- they fire ~50-80% of the time based on Claude's judgment."
Hooks fire 100% of the time, deterministically. This means:
v2.1 is fully compatible with v2.0 and v1:
~/.claude/homunculus/instincts/ still work as global instincts~/.claude/skills/learned/ skills from v1 still workInstinct-based learning: teaching Claude your patterns, one project at a time.