- Relocate runtime/skills -> skills/; runtime_skills_root() prefers oclaw/skills with fallback to legacy runtime/skills for unmigrated trees. - session-bootstrap hook handler resolves repo root via PROJECT_ROOT. - Update architecture/migration docs and in-tree skill references. Co-authored-by: Cursor <cursoragent@cursor.com>
5.1 KiB
Hook Setup Guide
Configure automatic self-improvement triggers for AI coding agents.
概览
Hooks enable proactive learning capture by injecting reminders at key moments:
- UserPromptSubmit: Reminder after each prompt to evaluate learnings
- PostToolUse (Bash): Error detection when commands fail
Claude Code Setup
Option 1: Project-Level Configuration
Create .claude/settings.json in your project root:
{
"hooks": {
"UserPromptSubmit": [
{
"matcher": "",
"hooks": [
{
"type": "command",
"command": "./skills/self-improvement/scripts/activator.sh"
}
]
}
],
"PostToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "./skills/self-improvement/scripts/error-detector.sh"
}
]
}
]
}
}
Option 2: User-Level Configuration
Add to ~/.claude/settings.json for global activation:
{
"hooks": {
"UserPromptSubmit": [
{
"matcher": "",
"hooks": [
{
"type": "command",
"command": "~/.claude/skills/self-improvement/scripts/activator.sh"
}
]
}
]
}
}
Minimal Setup (Activator Only)
For lower overhead, use only the UserPromptSubmit hook:
{
"hooks": {
"UserPromptSubmit": [
{
"matcher": "",
"hooks": [
{
"type": "command",
"command": "./skills/self-improvement/scripts/activator.sh"
}
]
}
]
}
}
Codex CLI Setup
Codex uses the same hook system as Claude Code. Create .codex/settings.json:
{
"hooks": {
"UserPromptSubmit": [
{
"matcher": "",
"hooks": [
{
"type": "command",
"command": "./skills/self-improvement/scripts/activator.sh"
}
]
}
]
}
}
GitHub Copilot Setup
Copilot doesn't support hooks directly. Instead, add guidance to .github/copilot-instructions.md:
## 自我改进
After completing tasks that involved:
- Debugging non-obvious issues
- Discovering workarounds
- Learning project-specific patterns
- Resolving unexpected errors
Consider logging the learning to Wiki (`improvement/learnings.md`, `improvement/errors.md`, `improvement/feature-requests.md`) using the format from the self-improvement skill.
For high-value learnings that would benefit other sessions, consider skill extraction.
Verification
Test Activator Hook
- Enable the hook configuration
- Start a new Claude Code session
- Send any prompt
- Verify you see
<self-improvement-reminder>in the context
Test Error Detector Hook
- Enable PostToolUse hook for Bash
- Run a command that fails:
ls /nonexistent/path - Verify you see
<error-detected>reminder
Dry Run Extract Script
./skills/self-improvement/scripts/extract-skill.sh test-skill --dry-run
Expected output shows the skill scaffold that would be created.
Troubleshooting
Hook Not Triggering
- Check script permissions:
chmod +x scripts/*.sh - Verify path: Use absolute paths or paths relative to project root
- Check settings location: Project vs user-level settings
- Restart session: Hooks are loaded at session start
Permission Denied
chmod +x ./skills/self-improvement/scripts/activator.sh
chmod +x ./skills/self-improvement/scripts/error-detector.sh
chmod +x ./skills/self-improvement/scripts/extract-skill.sh
Script Not Found
If using relative paths, ensure you're in the correct directory or use absolute paths:
{
"command": "/absolute/path/to/skills/self-improvement/scripts/activator.sh"
}
Too Much Overhead
If the activator feels intrusive:
- Use minimal setup: Only UserPromptSubmit, skip PostToolUse
- Add matcher filter: Only trigger for certain prompts:
{
"matcher": "fix|debug|error|issue",
"hooks": [...]
}
Hook Output Budget
The activator is designed to be lightweight:
- Target: ~50-100 tokens per activation
- Content: Structured reminder, not verbose instructions
- Format: XML tags for easy parsing
If you need to reduce overhead further, you can edit activator.sh to output less text.
Security Considerations
- Hook scripts run with the same permissions as Claude Code
- Scripts only output text; they don't modify files or run commands
- Error detector reads
CLAUDE_TOOL_OUTPUTenvironment variable - Treat
CLAUDE_TOOL_OUTPUTas potentially sensitive; do not log or forward it verbatim unless the user explicitly wants that detail - All scripts are opt-in (you must configure them explicitly)
- Recommended default: enable
UserPromptSubmitonly, and addPostToolUseonly when you want error-pattern reminders from command output
Disabling Hooks
To temporarily disable without removing configuration:
- Comment out in settings:
{
"hooks": {
// "UserPromptSubmit": [...]
}
}
- Or delete the settings file: Hooks won't run without configuration