| name | hooks-automation |
| description | Enhanced pre/post operation hooks with learning capabilities. Extends Claude Code's native hooks with task-aware pre-validation, post-execution learning, memory coordination, and session lifecycle management. Use when: configuring hooks, debugging hook failures, adding new automation triggers. Skip when: hooks are already working correctly.
|
| tags | ["automation","hooks","orchestration"] |
| triggers | ["hooks automation","use hooks automation","run hooks automation"] |
Hooks Automation — Intelligent Operation Lifecycle
Purpose: Claude Code hooks are powerful but limited to simple regex matching.
This skill defines the full hook lifecycle: what happens before, during, and after
every operation type, including learning and pattern extraction.
Current Hooks (.claude/settings.local.json)
These are the native Claude Code hooks already active:
| Event | Matcher | Action |
|---|
| PreToolUse (Edit/Write) | .env* files | BLOCK — credentials are manual-only |
| PreToolUse (Bash) | destructive commands | BLOCK — rm -rf, force push, DROP TABLE |
| PostToolUse (Bash) | git/npm/vercel commands | AUDIT LOG → tmp/hook_audit.log |
| Notification | all | Windows desktop alert on input needed |
Enhanced Hook Definitions
Beyond the native hooks, these are the logical hooks that agents should follow:
Pre-Operation Hooks
pre-edit: File Validation
Before modifying any file:
- Check agent permissions (see
skills/agent-permissions/SKILL.md)
- Verify file is not in blocked patterns list
- Read the file first (mandatory — never edit blind)
- If file is in
brain/ — check mutability level (SOUL.md = IMMUTABLE)
pre-bash: Command Safety
Before executing any shell command:
- Check against blocked command patterns
- Verify the command doesn't expose secrets (no
echo $API_KEY)
- For destructive commands (rm, git reset) — require CC confirmation
- Log command intent to session context
pre-task: Context Loading
Before starting any non-trivial task:
- Run task routing (see
skills/task-routing/SKILL.md)
- Load relevant memory (BRAIN_LOOP Step 2: RECALL)
- Check ACTIVE_TASKS.md for conflicts or related work
- Verify agent has required permissions
pre-commit: Quality Gate
Before any git commit:
- Run
git diff --staged — review all changes
- Check for hardcoded secrets (grep for API keys, tokens, passwords)
- Verify no
.env files are staged
- For MODERATE+ changes: run code review skill
- Verify commit message follows conventional format
pre-deploy: Build Verification
Before pushing to remote:
npm run build must pass with zero errors
- All tests must pass
- No CRITICAL code review issues outstanding
- CHANGELOG.md updated (for feature/fix commits)
Post-Operation Hooks
post-edit: Change Tracking
After modifying any file:
- Track which files were modified (for anti-drift scope monitoring)
- If a markdown file in
brain/ or memory/ was edited — update timestamps
- If the edit introduced a new pattern — flag for PATTERNS.md consideration
post-bash: Execution Logging
After executing any shell command:
- If command failed — log to session context for debugging
- If command was git push/commit — log to SESSION_LOG.md
- If command was npm build/test — note pass/fail status
- Append to
tmp/hook_audit.log for audit trail
post-task: Learning Extraction
After completing any non-trivial task:
- Did the task succeed? Log outcome to SESSION_LOG.md
- Did anything unexpected happen? Flag for PATTERNS.md or MISTAKES.md
- Update ACTIVE_TASKS.md with completion status
- If task used a new approach — tag as
[PROBATIONARY] pattern
- Run anti-drift final check (actual scope vs. planned scope)
post-commit: State Sync
After any git commit:
- Update SESSION_LOG.md with commit hash and summary
- Update brain/STATE.md if operational state changed
- Notify via desktop notification (already handled by native hook)
post-deploy: Smoke Test
After deployment completes:
- Visit production URL with Playwright
- Check for console errors
- Verify the deployed feature works
- If smoke test fails — create hotfix branch immediately
Session Lifecycle Hooks
session-start:
- Load brain/ files (SOUL, STATE, USER)
- Read ACTIVE_TASKS.md for pending work
- Check MCP server connectivity
- Run memory health check (SESSION_LOG.md size, stale tasks)
- Load
.agents/config.toml for current settings
session-end:
- Update brain/STATE.md with final operational state
- Update memory/ACTIVE_TASKS.md with task status
- Append session summary to memory/SESSION_LOG.md
- Flush traces to Supabase (if available)
- Git commit if uncommitted changes exist:
bravo: sync — session YYYY-MM-DD
Memory Coordination Hooks
memory-write:
Before writing to any memory file:
- Check the Five-Gate Knowledge Filter (see
skills/memory-management/SKILL.md)
- Verify no duplicate entry exists
- Add confidence score and timestamp
- If writing to brain/ file — verify mutability permits the change
memory-read:
When accessing memory files:
- Log access for activation scoring (recency bump)
- Check freshness — flag stale entries (>30 days without verification)
- Cross-reference with Supabase for any newer data from other agents
Learning Hooks
train-on-success:
After a task completes successfully:
- Extract the approach as a candidate pattern
- Check if this pattern already exists in PATTERNS.md
- If new — add as
[PROBATIONARY] with confidence 0.6
- If existing — increment usage count, bump confidence
train-on-failure:
After a task fails:
- Generate Reflexion entry (BRAIN_LOOP Step 7)
- Check MISTAKES.md for similar failures
- If repeat failure — escalate to SOP creation
- Store failure context for future RECALL
Adding New Hooks
To add a new native Claude Code hook, edit .claude/settings.local.json:
{
"hooks": {
"PreToolUse": [
{
"matcher": "pattern to match",
"hook": "command to run",
"timeout": 10000
}
]
}
}
For logical hooks (enforced by agent behavior, not Claude Code runtime):
- Add the hook definition to this skill file
- Reference it in the relevant skill that should trigger it
- Update
.agents/config.toml [hooks] section
Config Reference
Hook settings in .agents/config.toml:
[hooks.pre] — Which pre-operation hooks are enabled
[hooks.post] — Which post-operation hooks are enabled
[hooks.learning] — Learning trigger settings
Obsidian Links
- [[brain/CAPABILITIES]] | [[skills/task-routing/SKILL]]
- [[skills/anti-drift/SKILL]] | [[skills/memory-management/SKILL]]
- [[skills/code-review/SKILL]] | [[skills/security-protocol/SKILL]]