Claude Octopus uses a hook system to inject custom logic at key points in the workflow lifecycle. Hooks enable quality gates, phase transitions, telemetry, and custom validations.
Available hooks
Claude Octopus provides hooks for the following lifecycle events:
Hook execution order
For a typical workflow command like /octo:embrace, hooks fire in this sequence:
Quality gates typically use PreToolUse to block execution, while validation hooks use PostToolUse to analyze output.
Creating custom hooks
Step 1: Choose the event
Decide which lifecycle event your hook should respond to. See the table above.
Step 2: Create the hook script
Hooks live in hooks/ or .claude/hooks/. Create a new executable script:
Step 3: Write the hook logic
PreToolUse hooks validate before tool execution:
PreToolUse hooks MUST return JSON with {"decision": "continue"} or {"decision": "block", "reason": "..."}. Malformed output will cause the workflow to fail.
PostToolUse hook example
PostToolUse hooks analyze tool output:
TaskCompleted hook example
TaskCompleted hooks trigger phase transitions:
Step 4: Register the hook
Hooks are registered via:
-
Filename convention (automatic):
*-gate.sh → PreToolUse
*-hook.md → Documentation (with frontmatter registration)
-
Persona frontmatter (persona-specific):
- Global registration (all personas):
Create a hook markdown file with frontmatter:
See hooks/quality-gate-hook.md in source code:~/workspace/source/hooks/quality-gate-hook.md
Built-in hooks
Claude Octopus ships with these hooks:
Quality gates
quality-gate.sh — Validates tangle output quality score (75% threshold)
security-gate.sh — Validates OWASP coverage in security audits
architecture-gate.sh — Checks architecture decisions against principles
code-quality-gate.sh — Enforces coding standards
budget-gate.sh — Blocks execution if token budget exceeded
perf-gate.sh — Validates performance benchmarks
Phase management
task-completion-checkpoint.sh — Records task completion metrics
task-completed-transition.sh — Triggers phase transitions
task-dependency-validator.sh — Validates task dependencies
Session management
session-sync.sh — Persists conversation state
context-reinforcement.sh — Injects workflow context
config-change-handler.sh — Reloads config on changes
Safety and validation
sysadmin-safety-gate.sh — Blocks dangerous system commands
scheduler-security-gate.sh — Validates scheduled task safety
provider-routing-validator.sh — Validates multi-AI routing decisions
Telemetry
telemetry-webhook.sh — Sends events to external webhooks
octopus-statusline.sh — Updates CLI status display
octopus-hud.mjs — Visual HUD for active workflows
Worktree isolation (v8.26+)
worktree-setup.sh — Creates isolated git worktrees for agents
worktree-teardown.sh — Cleans up worktrees after completion
See the full list in hooks/ directory: ~/workspace/source/hooks/
Hook return values
Must return JSON:
or
PostToolUse hooks
Can analyze output and return validation results:
TaskCompleted hooks
Usually return phase transition data:
Hook environment variables
Hooks have access to:
Best practices
- Fail fast — Exit with non-zero status if critical validation fails
- Idempotent — Hooks may run multiple times; design accordingly
- Minimal dependencies — Use standard bash utilities (jq, grep, awk)
- Timeout awareness — Keep hooks fast (under 1 second) to avoid workflow delays
- Security — Never log sensitive data (API keys, tokens)
- Error messages — Provide actionable error messages to users
Debugging hooks
Enable debug mode to see hook execution:
You’ll see:
Source code reference
- Hook scripts:
hooks/*.sh in source code:~/workspace/source/hooks/
- Hook documentation:
hooks/*-hook.md in source code:~/workspace/source/hooks/
- Claude Code hooks:
.claude/hooks/ for IDE-specific hooks