brainstorming
Structured design dialogue that validates ideas before implementation begins.
moai-cc-hook-model-strategy
Claude Code hook execution strategies, timing models, sequencing patterns, and orchestration for automated workflow enforcement. Covers all hook types and execution timing models.
Full skill instructions
Hooks provide automation triggers at strategic points in Claude Code workflows: pre-tool execution (validation), post-tool execution (processing), and session lifecycle events (initialization, cleanup). Enable systematic enforcement of quality standards and security policies.
WORKFLOW TIMELINE
│
├─ Session Start
│ └─ SessionStart hooks trigger
│
├─ Tool Invocation
│ ├─ Pre-Tool hooks trigger (validation)
│ ├─ Tool executes
│ └─ Post-Tool hooks trigger (processing)
│
├─ Task Completion
│ └─ SessionEnd hooks trigger (cleanup)
│
└─ Session Close
Execute BEFORE tool runs:
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "python3 .claude/hooks/validate-command.py"
}
]
}
]
}
}
Execution Timing:
User: bash("git commit -m 'message'")
↓
Pre-Tool Hook: validate-command.py
├─ Check command syntax
├─ Verify permissions
├─ Scan for dangerous patterns
└─ Decision: ALLOW / DENY
↓
ALLOW → Tool executes
DENY → Block & report error
Use Cases:
Example Hook Script:
#!/usr/bin/env python3
import re
import sys
import json
DANGEROUS_PATTERNS = [
r"rm -rf",
r"sudo ",
r"chmod 777",
r"&&.*rm",
r"\|.*sh"
]
def validate_command(command):
for pattern in DANGEROUS_PATTERNS:
if re.search(pattern, command):
return False, f"Dangerous pattern: {pattern}"
return True, "Safe"
if __name__ == "__main__":
input_data = json.load(sys.stdin)
command = input_data.get("command", "")
is_safe, message = validate_command(command)
if not is_safe:
print(f"SECURITY BLOCK: {message}", file=sys.stderr)
sys.exit(2) # Non-zero = block
sys.exit(0) # Zero = allow
Execute AFTER tool completes:
{
"hooks": {
"PostToolUse": [
{
"matcher": "Edit",
"hooks": [
{
"type": "command",
"command": "python3 .claude/hooks/post-edit-processing.py"
}
]
}
]
}
}
Execution Timing:
Tool executes: Edit(src/auth.py)
↓
Post-Tool Hook: post-edit-processing.py
├─ Validate syntax
├─ Run linter
├─ Check formatting
└─ Log results
↓
Returns to user with processing results
Use Cases:
Execute at session start/end:
{
"hooks": {
"SessionStart": [
{
"type": "command",
"command": "uv run .moai/scripts/statusline.py"
}
],
"SessionEnd": [
{
"type": "command",
"command": "python3 .claude/hooks/cleanup.py"
}
]
}
}
Timing:
SESSION START
↓
SessionStart hooks trigger
├─ Load project config
├─ Initialize memory
├─ Check dependencies
└─ Display status
↓
WORK PHASE
↓
SESSION END
↓
SessionEnd hooks trigger
├─ Save state
├─ Cleanup temp files
├─ Generate report
└─ Close connections
Use Cases:
Hooks run one after another, in order:
Tool Call
↓
Pre-Hook 1 (VALIDATE INPUT)
├─ Check syntax → Pass/Fail
└─ Output: validated_input
↓
Pre-Hook 2 (CHECK PERMISSIONS)
├─ Verify permissions → Pass/Fail
└─ Output: permission_result
↓
Pre-Hook 3 (AUDIT LOG)
├─ Log operation → Always pass
└─ Output: audit_entry
↓
Tool Execution
↓
Post-Hook 1 (VALIDATE OUTPUT)
Post-Hook 2 (FORMAT RESULTS)
Post-Hook 3 (UPDATE METRICS)
↓
Result
When to use sequential:
Hooks run simultaneously when independent:
Tool Call
↓
Pre-Hooks (all in parallel):
├─ Thread 1: Validate syntax
├─ Thread 2: Check permissions
├─ Thread 3: Scan for secrets
└─ Thread 4: Verify resources
↓
(All must pass for tool to execute)
↓
Tool Execution
↓
Post-Hooks (all in parallel):
├─ Thread 1: Validate output
├─ Thread 2: Update metrics
├─ Thread 3: Log operation
└─ Thread 4: Format results
↓
Result
When to use parallel:
# Pre-execution chain:
# 1. Validation Hook (input validation)
# 2. Permission Hook (authorization)
# 3. Resource Hook (availability check)
# 4. Audit Hook (logging)
# 5. Execution (actual tool)
# Post-execution chain:
# 1. Output Hook (result validation)
# 2. Processing Hook (transformation)
# 3. Cleanup Hook (resource release)
# 4. Metrics Hook (usage tracking)
#!/bin/bash
# Hook only runs if specific conditions met
if [[ "$TOOL_TYPE" == "Edit" ]]; then
# Run linter for edit operations
python3 -m pylint --score=no "$FILE" || exit 1
fi
if [[ "$COMMAND" == "rm -rf" ]]; then
echo "BLOCKED: Destructive command"
exit 2
fi
exit 0
# Hook exit codes:
# 0 = Success (allow/continue)
# 1 = Warning (log but continue)
# 2 = Error (block/stop)
#!/usr/bin/env python3
import sys
try:
# Perform validation
result = validate_operation()
if not result.valid:
# Block operation
print(f"BLOCK: {result.error}", file=sys.stderr)
sys.exit(2) # Exit code 2 = block
except Exception as e:
# Unexpected error
print(f"ERROR: {e}", file=sys.stderr)
sys.exit(1) # Exit code 1 = warning
# Success
sys.exit(0) # Exit code 0 = allow
{
"hooks": {
"PreToolUse": [
{
"command": "python3 .claude/hooks/fast-validation.py",
"timeout": 5000 # 5 second timeout
}
]
}
}
#!/bin/bash
# Pre-commit hook: validate before git commit
# Check for secrets
if grep -r "PASSWORD\|API_KEY\|SECRET" --include="*.py" . ; then
echo "ERROR: Secrets found in code"
exit 2
fi
# Check code formatting
python3 -m black --check . || exit 2
# All checks pass
exit 0
#!/bin/bash
# Post-edit hook: auto-format edited files
# Get edited file from input
FILE="$1"
# Auto-format
python3 -m black "$FILE" || exit 1
python3 -m ruff check --fix "$FILE" || exit 1
echo "Formatted: $FILE"
exit 0
#!/bin/bash
# SessionStart hook: initialize project context
# Load project status
echo "Loading project configuration..."
python3 .moai/scripts/statusline.py
# Check dependencies
echo "Verifying dependencies..."
uv sync --quiet
echo "Session ready!"
exit 0
moai-cc-permission-mode - Permission validation in hooksmoai-cc-subagent-lifecycle - Lifecycle hooks for subagentsmoai-core-workflow - Overall workflow orchestrationLast Updated: 2025-11-19 Version: 4.0.0 Enterprise Production Ready: Yes ✅ Maturity: Stable
Structured design dialogue that validates ideas before implementation begins.
Comprehensive design intelligence for web and mobile UI/UX across 10 technology stacks.
Comprehensive implementation plans for multi-step tasks, breaking down specs into bite-sized, testable steps.
Introduction to the obra skills system with mandatory skill invocation rules and best practices.
Execute a written implementation plan with critical review and task checkpoints.
Delegate independent tasks to specialized agents working concurrently with isolated context.
Isolated git worktrees with smart directory selection and safety verification.
Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.
Plan searchable and shareable content that drives traffic, builds authority, and generates leads.
README-first repository scanner that extracts commands and classifies reproduction candidates without executing them.
Brainstorm and prioritize marketing strategies tailored to your SaaS stage, budget, and goals.
Plan and optimize your website's page hierarchy, navigation, URL structure, and internal linking.
The world's fastest calendar for remote work
Capture, organize, and utilize your knowledge effortlessly.
Instant Summaries of Audio & Video Interviews with AnySummary
Transform PDFs into engaging mind maps.
Chat with any PDF instantly
Create an optimal daily plan using your voice
A productivity platform to centralize organizational knowledge and workflows with contextual AI assistance.
AskYourPDF Pricing Plans: Tailored to Your Needs