evgeniy-mikhailove/rlm-claude-code-os/hook-automation-patterns

Claude Code and agent skill by evgeniy-mikhailove/rlm-claude-code-os

Trust tier 2
  • community
  • ext:[{"type":"hook","description":"Pre/post lifecycle hooks"}]
LLM review pending
Source check pending

Checking that the SKILL.md file is still in the repository.

Claude Code hook patterns for automatic formatting, security scanning, usage measurement, and permission routing. Use when setting up automated behaviors triggered before/after tool use without manual invocation. Covers PreToolUse, PostToolUse, and session lifecycle hooks with ready-to-use JSON configs.

Install

npx vskill@latest install evgeniy-mikhailove/rlm-claude-code-os/hook-automation-patterns

Semi-extensibleMentions customization, but needs skill-specific knowledge. Read the extensible skills standard

SKILL.md

The same SKILL.md was published earlier as evgeniy-mikhailove/rlm-claude-code-os/hook-automation-patterns.

Hook Automation Patterns

Hooks run shell commands automatically on Claude Code events. Zero manual intervention.

Hook Lifecycle

EventWhen it firesBest used for
PreToolUseBefore any tool callValidation, permission checks, logging
PostToolUseAfter any tool callFormatting, security scan, metrics
SessionStartSession beginsLoad context, restore state
SessionEndSession endsCompress memory, save state
StopAgent task completesFinal checks, notifications

Pattern 1: Auto-Format on Save

Prevent CI failures from formatting issues. Fires after every Edit/Write.

json
{
"hooks": {
"PostToolUse": [{
"matcher": "Edit|Write",
"hooks": [{
"type": "command",
"command": "npx prettier --write \"$CLAUDE_TOOL_FILE\" 2>/dev/null || true"
}]
}]
}
}

Pattern 2: Security Scanner

Catch secrets and vulnerabilities after every file change.

json
{
"hooks": {
"PostToolUse": [{
"matcher": "Edit|Write",
"hooks": [{
"type": "command",
"command": "~/.claude/hooks/security-scanner.sh \"$CLAUDE_TOOL_FILE\""
}]
}]
}
}

Pattern 3: On-Demand Safety Hooks (Slash Commands)

bash
# /careful — blocks destructive bash operations
# activate before working near production code
# /freeze <dir> — blocks edits outside specified directory
# scopes agent to a single folder

Pattern 4: Permission Routing

Route expensive/risky Bash operations through an approval gate.

json
{
"hooks": {
"PreToolUse": [{
"matcher": "Bash",
"hooks": [{
"type": "command",
"command": "~/.claude/hooks/permission-router.sh \"$CLAUDE_TOOL_INPUT\""
}]
}]
}
}

Pattern 5: Skill Usage Measurement

Track which skills fire too rarely (undertriggering) or too often.

json
{
"hooks": {
"PreToolUse": [{
"matcher": ".*",
"hooks": [{
"type": "command",
"command": "echo \"$(date -Iseconds),$CLAUDE_TOOL_NAME,$CLAUDE_SESSION_ID\" >> ~/.claude/skill-usage.log 2>/dev/null || true"
}]
}]
}
}

Pattern 6: Smart Commit on Edit

Auto-commit file changes in git repos with a generated message.

json
{
"hooks": {
"PostToolUse": [{
"matcher": "Edit|Write",
"hooks": [{
"type": "command",
"command": "~/.claude/hooks/smart-commit.sh \"$CLAUDE_TOOL_FILE\""
}]
}]
}
}

Hook Environment Variables

VariableContent
$CLAUDE_TOOL_NAMETool that fired (Edit, Bash, etc.)
$CLAUDE_TOOL_FILEFile path for file-based tools
$CLAUDE_TOOL_INPUTRaw input to the tool
$CLAUDE_SESSION_IDCurrent session ID
$CLAUDE_PROJECT_DIRProject root directory

Config Location

ScopeFile
Global (all projects)~/.claude/settings.local.json
Project-specific.claude/settings.json in project root

Project settings override global. Both use the same JSON schema.

Anti-Patterns

  • Hooks that fail loudly and block the main agent flow — always add || true
  • Heavy operations in PreToolUse — adds latency to every tool call
  • Hooks that modify the file they're scanning — creates loop risk
  • Missing 2>/dev/null — stderr from hooks can confuse Claude's output parsing

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewNot runA model review is scheduled for the next rescan.

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
0

Not refreshed yet.

Extension points

  • hookPre/post lifecycle hooks

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/evgeniy-mikhailove/rlm-claude-code-os/hook-automation-patterns/badge)](https://verified-skill.com/skills/evgeniy-mikhailove/rlm-claude-code-os/hook-automation-patterns)

Something wrong with this skill or its page? Tell us.