- Home
- Skills
- Agents & Orchestration
- Claude Code Hooks Builder: Auto-Lint, Tests & Guards
Works with the AI Agents you already use
Claude Code Hooks Builder: Auto-Lint, Tests & Guards
This skill automates the design and implementation of local or project-wide hooks to enforce coding standards, block dangerous commands, and automate post-edit tasks.
Free
Claude Code Hooks Builder: Auto-Lint, Tests & Guards
Example session with this skill installed
I need a hook that runs 'npm test' only when files in the /src directory are edited. Block the edit if tests fail.
- Read your context and instructions
- Compiled the claude code hooks
I have generated a PreToolUse hook to validate edits against your test suite. This ensures that no breaking changes are committed to the /src directory during the session.
Claude Code Hook: Test on Edit
1. Hook Script (.claude/hooks/test_src.sh)
#!/bin/bash
# Read tool input from stdin
INPUT=$(cat)
FILE_PATH=$(echo "$INPUT" | jq -r '.tool_input.file_path // empty')
# Only run for src directory
if [[ "$FILE_PATH" == src/* ]]; then
echo "Running tests for $FILE_PATH..." >&2
npm test -- --findRelatedTests "$FILE_PATH" > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Validation failed: npm test must pass for files in /src." >&2
exit 2 # Block the tool execution
fi
fi
exit 0 # Allow the execution
2. Configuration (.claude/settings.json)
{
"hooks": {
"PreToolUse": [
{
"matcher": "Edit|Write|MultiEdit",
"hooks": [
{
"type": "command",
"command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/test_src.sh",
"timeout": 60
}
]
}
]
}
}
3. Test Command
echo '{"tool_name":"Write","tool_input":{"file_path":"src/index.ts"}}' | ./.claude/hooks/test_src.sh; echo "Exit code: $?"
Next steps
- Run
chmod +x .claude/hooks/test_src.shto make the script executable. - Ensure
jqis installed on your system. - Run
/hooksinside Claude Code to verify registration.
Connects securely to your tools. The creator never sees your data.
About this skill
Claude Code hooks are powerful but brittle. Writing them manually requires navigating specific JSON schemas, handling stdin/stdout correctly, and managing exit codes for blocking or allowing actions. This skill automates the design and implementation of local or project-wide hooks to enforce coding standards, block dangerous commands, and automate post-edit tasks.
What it does
- Event Mapping identifies the correct lifecycle event like
PreToolUseorPostToolUsefor your specific automation goal. - Hook Script Generation writes idempotent shell scripts that parse tool inputs and handle exit codes for blocking or allowing executions.
- Configuration Management generates the correct JSON for
.claude/settings.jsonor local overrides. - Security Validation implements checks to prevent accidental execution of high-risk commands.
- Testing Procedures provides dry-run commands to verify hook logic before registering them in the environment.
How it works
- Goal definition where you specify what you want to automate, such as running a linter after every file edit.
- Strategy selection to map the task to events like
PreToolUsefor blocking orPostToolUsefor post-processing. - Script delivery providing the executable bash script and the corresponding JSON configuration snippet.
- Verification using a pipe-based test command to ensure the script handles JSON payloads correctly.
Frameworks & tools
This skill produces standard Bash scripts and JSON configurations optimized for the Claude Code CLI. It relies on jq for robust JSON parsing within the hook scripts.
Why this beats prompting it yourself
Standard LLM prompts often fail to account for the specific exit code requirements (Exit 2 for blocking) or the need to quote variables for path safety. This skill ensures scripts are idempotent and performant, preventing the 2-second timeout from killing your developer workflow.
Use cases
- Block dangerous commands like
rm -rfor unauthorizedgit pushattempts. - Auto-format code by triggering Prettier or Ruff immediately after a write tool finishes.
- Context injection to load project-specific rules at the start of every session.
- Notification alerts to send desktop or Slack messages when long-running tasks complete.
Known limitations
Hooks must be fast to avoid timeouts. This skill does not handle remote script downloads and requires jq to be installed on your local machine for JSON parsing.
Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for Agents & Orchestration.
Requires jq for JSON parsing. Scripts must execute in under 30s (2s typical). Does not support remote script fetching for security.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before buying a skill.
Reviews
This skill has been used 1 time.
Trust & safety
Security scan
Security scan passed 4 days ago
- Free with an Agensi account