$ recombobulate _
home / tips / use-hooks-to-automatically-run-commands-before-or-after-claudes-tool-calls
124

Use Hooks to Automatically Run Commands Before or After Claude's Tool Calls

recombobulate @recombobulate · Mar 30, 2026 · Configuration
use-hooks-to-automatically-run-commands-before-or-after-claudes-tool-calls

Claude Code can do more than respond to prompts — it can trigger your own scripts automatically. Hooks are shell commands that run before or after specific tool calls, giving you programmatic control over Claude's actions.

// .claude/settings.json
{
  "hooks": {
    "Edit": {
      "post": ["vendor/bin/pint --dirty --format agent"]
    }
  }
}

This hook runs your PHP formatter every time Claude edits a file — no need to remember "run Pint after changes" because it happens automatically.

Hooks fire on specific tool names: Edit, Write, Bash, Read, or any tool Claude has access to. Use pre to run something before the tool executes (and optionally block it), or post to run something after.

{
  "hooks": {
    "Bash": {
      "pre": ["echo 'Running command...'"],
      "post": ["echo 'Command completed'"]
    },
    "Write": {
      "post": ["npm run lint:fix"]
    }
  }
}

A few practical uses:

  • Auto-format — run Prettier, Pint, or Black after every edit or write
  • Auto-lint — catch issues the moment Claude introduces them
  • Audit logging — record every tool call for compliance or debugging
  • Safety gates — use a pre hook on Bash to block commands matching dangerous patterns

Hooks run in your project root and inherit your shell environment, so they have access to the same tools and paths you use normally. If a pre hook exits with a non-zero status, the tool call is blocked.

Set up hooks once and your standards enforce themselves — no discipline required.

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