$ recombobulate _
home / tips / set-up-hooks-to-run-commands-automatically-before-or-after-tool-calls
100

Set Up Hooks to Run Commands Automatically Before or After Tool Calls

recombobulate @recombobulate · Mar 29, 2026 · Configuration
set-up-hooks-to-run-commands-automatically-before-or-after-tool-calls

Hooks let you attach shell commands to Claude's tool calls — they fire automatically before or after Claude reads a file, writes code, or runs a command. No prompting required.

{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Write|Edit",
        "command": "vendor/bin/pint --dirty --format agent"
      }
    ]
  }
}

Drop that in your .claude/settings.json and every time Claude edits or writes a PHP file, Pint runs automatically to fix formatting. Claude sees the hook output and adjusts if needed.

You can hook into different events:

  • PreToolUse — runs before a tool executes (can block it by returning a non-zero exit code)
  • PostToolUse — runs after a tool completes
  • Notification — runs when Claude sends a notification

The matcher field filters which tool triggers the hook. Match specific tools like Write, Edit, Bash, or use a regex pattern to match several.

{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Write|Edit",
        "command": "npx eslint --fix $CLAUDE_FILE_PATH"
      },
      {
        "matcher": "Bash",
        "command": "echo \"$(date): $CLAUDE_TOOL_INPUT\" >> ~/.claude-commands.log"
      }
    ],
    "PreToolUse": [
      {
        "matcher": "Bash",
        "command": "echo 'Review this command carefully' >&2"
      }
    ]
  }
}

Hooks run in your shell with access to environment variables like $CLAUDE_FILE_PATH and $CLAUDE_TOOL_INPUT, so you can build context-aware automation around Claude's actions.

Hooks turn Claude Code from an assistant you instruct into a workflow that enforces your standards automatically.

via Claude Code

~/recombobulate $ tip --comments --count=0

Log in to leave a comment.

~/recombobulate $ tip --related --limit=3
0
Describe Your Users in CLAUDE.md So Claude Writes Appropriate Copy, Error Messages, and UX

When Claude writes error messages, button labels, validation text, or onboarding flows, it defaults to generic developer-speak. Add a "Users" section to your CLAUDE.md describing who your actual users are — their technical level, industry jargon, and what they care about — so Claude writes copy that makes sense to THEM, not to developers.

recombobulate @recombobulate · 1 day ago
1
Create Custom Agents with --agent for Scoped Sessions

Use the --agent flag with custom markdown files in .claude/agents/ to launch purpose-built Claude sessions with restricted tools and scoped system prompts.

recombobulate @recombobulate · 1 day ago
106
Add Known Gotchas and Pitfalls to Your CLAUDE.md So Claude Avoids Mistakes Your Team Already Made

Every project has traps — the billing module that silently fails if you forget to queue the job, the legacy table with column names that don't match the model, the config value that must be set before tests run. Document these gotchas in your CLAUDE.md so Claude avoids the same mistakes your team spent days debugging.

recombobulate @recombobulate · 1 day ago