From terraphim-engineering-skills
Automatic capture of failed commands as structured learning documents using Terraphim. PostToolUse hook intercepts bash command failures and records them with error context for later querying and correction. Builds an evolving knowledge base of developer mistakes and solutions to avoid repeating errors across sessions.
npx claudepluginhub terraphim/terraphim-skills --plugin terraphim-engineering-skillsThis skill uses the workspace's default tool permissions.
Use this skill when setting up, using, or troubleshooting Terraphim's automatic learning capture system that records failed commands and their context.
Mandates invoking relevant skills via tools before any response in coding sessions. Covers access, priorities, and adaptations for Claude Code, Copilot CLI, Gemini CLI.
Share bugs, ideas, or general feedback.
Use this skill when setting up, using, or troubleshooting Terraphim's automatic learning capture system that records failed commands and their context.
Terraphim learning capture automatically records bash command failures during AI-assisted development sessions. Each failure is stored as a structured Markdown document with the command, error output, exit code, working directory, and timestamp.
Key Capabilities:
~/.local/share/terraphim/learnings/┌─────────────────────────────────────────────────────────────┐
│ Claude Code (PostToolUse) │
│ Hook fires after every Bash tool call │
└───────────────────────┬─────────────────────────────────────┘
│ JSON: {tool_name, tool_input, tool_result}
▼
┌─────────────────────────────────────────────────────────────┐
│ ~/.claude/hooks/learning-capture.sh │
│ - Filters: only Bash tools, only non-zero exit codes │
│ - Skips: test commands (cargo test, npm test, etc.) │
│ - Fail-open: continues even if capture fails │
└───────────────────────┬─────────────────────────────────────┘
│ terraphim-agent learn capture ...
▼
┌─────────────────────────────────────────────────────────────┐
│ terraphim-agent learn capture │
│ Stores structured learning document with YAML frontmatter │
└───────────────────────┬─────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ ~/.local/share/terraphim/learnings/learning-*.md │
│ YAML frontmatter: id, command, exit_code, captured_at, tags │
│ Body: ## Command, ## Error Output sections │
└─────────────────────────────────────────────────────────────┘
# Install the PostToolUse hook for Claude Code automatically
terraphim-agent learn install-hook claude
# Or manually: add to ~/.claude/settings.json under hooks.PostToolUse
# See the hook script at ~/.claude/hooks/learning-capture.sh
Create ~/.claude/hooks/learning-capture.sh:
#!/bin/bash
# Read JSON from stdin, call terraphim-agent learn hook
INPUT=$(cat)
echo "$INPUT" | terraphim-agent learn hook
echo "$INPUT"
Add to ~/.claude/settings.json:
{
"hooks": {
"PostToolUse": [
{
"matcher": "Bash",
"hooks": [{"type": "command", "command": "~/.claude/hooks/learning-capture.sh"}]
}
]
}
}
# List recent captured failures
terraphim-agent learn list
# Search by command pattern
terraphim-agent learn query "cargo build"
terraphim-agent learn query "git push"
# Add a correction to an existing learning
terraphim-agent learn correct <id> "Use 'cargo build --release' instead"
Each captured learning is stored as:
---
id: <hash>-<timestamp>
command: <failed command>
exit_code: <non-zero code>
source: Global
captured_at: <ISO timestamp>
working_dir: <project directory>
tags:
- learning
- exit-<code>
---
## Command
`<command that failed>`
## Error Output
<stderr/stdout from the failure>
Query learnings to check if a similar command has failed before:
terraphim-agent learn query "<command keyword>"
If results exist, review the error patterns and corrections before proceeding.
Review recent learnings to identify recurring patterns:
terraphim-agent learn list
Enable debug output from the hook:
export TERRAPHIM_LEARN_DEBUG=true
install-hook)| Variable | Default | Description |
|---|---|---|
TERRAPHIM_LEARN_DEBUG | false | Enable debug logging from hook |
| Storage path | ~/.local/share/terraphim/learnings/ | Where learnings are stored |
| Agent | Install Command |
|---|---|
| Claude Code | terraphim-agent learn install-hook claude |
| OpenAI Codex | terraphim-agent learn install-hook codex |
| OpenCode | terraphim-agent learn install-hook opencode |