Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Enable an AI agent to iteratively improve its own skills and instructions based on task feedback.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/hooks-setup.md
1# Hook Setup Guide23Configure automatic self-improvement triggers for AI coding agents.45## Overview67Hooks enable proactive learning capture by injecting reminders at key moments:8- **UserPromptSubmit**: Reminder after each prompt to evaluate learnings9- **PostToolUse (Bash)**: Error detection when commands fail1011## Claude Code Setup1213### Option 1: Project-Level Configuration1415Create `.claude/settings.json` in your project root:1617```json18{19"hooks": {20"UserPromptSubmit": [21{22"matcher": "",23"hooks": [24{25"type": "command",26"command": "./skills/self-improvement/scripts/activator.sh"27}28]29}30],31"PostToolUse": [32{33"matcher": "Bash",34"hooks": [35{36"type": "command",37"command": "./skills/self-improvement/scripts/error-detector.sh"38}39]40}41]42}43}44```4546### Option 2: User-Level Configuration4748Add to `~/.claude/settings.json` for global activation:4950```json51{52"hooks": {53"UserPromptSubmit": [54{55"matcher": "",56"hooks": [57{58"type": "command",59"command": "~/.claude/skills/self-improvement/scripts/activator.sh"60}61]62}63]64}65}66```6768### Minimal Setup (Activator Only)6970For lower overhead, use only the UserPromptSubmit hook:7172```json73{74"hooks": {75"UserPromptSubmit": [76{77"matcher": "",78"hooks": [79{80"type": "command",81"command": "./skills/self-improvement/scripts/activator.sh"82}83]84}85]86}87}88```8990## Codex CLI Setup9192Codex uses the same hook system as Claude Code. Create `.codex/settings.json`:9394```json95{96"hooks": {97"UserPromptSubmit": [98{99"matcher": "",100"hooks": [101{102"type": "command",103"command": "./skills/self-improvement/scripts/activator.sh"104}105]106}107]108}109}110```111112## GitHub Copilot Setup113114Copilot doesn't support hooks directly. Instead, add guidance to `.github/copilot-instructions.md`:115116```markdown117## Self-Improvement118119After completing tasks that involved:120- Debugging non-obvious issues121- Discovering workarounds122- Learning project-specific patterns123- Resolving unexpected errors124125Consider logging the learning to `.learnings/` using the format from the self-improvement skill.126127For high-value learnings that would benefit other sessions, consider skill extraction.128```129130## Verification131132### Test Activator Hook1331341. Enable the hook configuration1352. Start a new Claude Code session1363. Send any prompt1374. Verify you see `<self-improvement-reminder>` in the context138139### Test Error Detector Hook1401411. Enable PostToolUse hook for Bash1422. Run a command that fails: `ls /nonexistent/path`1433. Verify you see `<error-detected>` reminder144145### Dry Run Extract Script146147```bash148./skills/self-improvement/scripts/extract-skill.sh test-skill --dry-run149```150151Expected output shows the skill scaffold that would be created.152153## Troubleshooting154155### Hook Not Triggering1561571. **Check script permissions**: `chmod +x scripts/*.sh`1582. **Verify path**: Use absolute paths or paths relative to project root1593. **Check settings location**: Project vs user-level settings1604. **Restart session**: Hooks are loaded at session start161162### Permission Denied163164```bash165chmod +x ./skills/self-improvement/scripts/activator.sh166chmod +x ./skills/self-improvement/scripts/error-detector.sh167chmod +x ./skills/self-improvement/scripts/extract-skill.sh168```169170### Script Not Found171172If using relative paths, ensure you're in the correct directory or use absolute paths:173174```json175{176"command": "/absolute/path/to/skills/self-improvement/scripts/activator.sh"177}178```179180### Too Much Overhead181182If the activator feels intrusive:1831841. **Use minimal setup**: Only UserPromptSubmit, skip PostToolUse1852. **Add matcher filter**: Only trigger for certain prompts:186187```json188{189"matcher": "fix|debug|error|issue",190"hooks": [...]191}192```193194## Hook Output Budget195196The activator is designed to be lightweight:197- **Target**: ~50-100 tokens per activation198- **Content**: Structured reminder, not verbose instructions199- **Format**: XML tags for easy parsing200201If you need to reduce overhead further, you can edit `activator.sh` to output less text.202203## Security Considerations204205- Hook scripts run with the same permissions as Claude Code206- Scripts only output text; they don't modify files or run commands207- Error detector reads `CLAUDE_TOOL_OUTPUT` environment variable208- Treat `CLAUDE_TOOL_OUTPUT` as potentially sensitive; do not log or forward it verbatim unless the user explicitly wants that detail209- All scripts are opt-in (you must configure them explicitly)210- Recommended default: enable `UserPromptSubmit` only, and add `PostToolUse` only when you want error-pattern reminders from command output211212## Disabling Hooks213214To temporarily disable without removing configuration:2152161. **Comment out in settings**:217```json218{219"hooks": {220// "UserPromptSubmit": [...]221}222}223```2242252. **Or delete the settings file**: Hooks won't run without configuration226