Works with the AI Agents you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIDeepSeekDeepSeekMuseMuse+22 more

    Claude Code Hooks Builder: Auto-Lint, Tests & Guards

    1

    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

    1 use5.0 (1 review)
    Claude Code Hooks Builder: Auto-Lint, Tests & Guards

    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

    1. Run chmod +x .claude/hooks/test_src.sh to make the script executable.
    2. Ensure jq is installed on your system.
    3. Run /hooks inside 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 PreToolUse or PostToolUse for 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.json or 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

    1. Goal definition where you specify what you want to automate, such as running a linter after every file edit.
    2. Strategy selection to map the task to events like PreToolUse for blocking or PostToolUse for post-processing.
    3. Script delivery providing the executable bash script and the corresponding JSON configuration snippet.
    4. 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 -rf or unauthorized git push attempts.
    • 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. 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. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 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

    5.0
    1 review
    5
    1
    4
    0
    3
    0
    2
    0
    1
    0

    This skill has been used 1 time.

    Trust & safety

    Security scan

    Security scan passed 4 days ago

    • Free with an Agensi account

    Permissions

    Read Files
    Listed4 days ago
    Updated1 day ago

    What's inside

    Frequently Asked Questions

    The skill automates the creation of bash scripts and JSON configurations for Claude Code CLI hooks, ensuring they follow strict exit code requirements and JSON parsing standards to prevent workflow errors.

    This skill requires the Claude Code CLI and the `jq` utility installed on your local machine to ensure the generated scripts can correctly parse tool inputs and outputs.

    Yes, you can generate both project-specific hooks for individual repositories and global hooks to enforce security standards across all your local Claude Code sessions.

    The builder specifically implements logic to handle the 2-second timeout window, ensuring scripts are optimized and idempotent so they don't interrupt your developer workflow.

    You receive the optimized Bash script for the hook logic, the specific JSON configuration snippet for your settings file, and a dry-run command to test the hook safely.

    The builder is designed to output scripts that use Exit Code 2 for intentional blocking and Exit Code 0 for successful execution, ensuring Claude Code responds correctly to your custom rules.

    New in Agents & Orchestration

    Free