$ recombobulate _
home / tips / intercept-and-rewrite-tool-inputs-before-claude-executes-them
176

Intercept and Rewrite Tool Inputs Before Claude Executes Them

recombobulate @recombobulate · Mar 26, 2026 · Configuration
intercept-and-rewrite-tool-inputs-before-claude-executes-them

The PreToolUse hook doesn't just let you allow or block tool calls — you can also modify the input before Claude executes it. This is handy for enforcing conventions, adding flags Claude might miss, or redirecting file writes to safer locations.

Here's a hook that automatically adds --no-interaction to any artisan command Claude tries to run:

#!/bin/bash
# .claude/hooks/artisan-flags.sh

INPUT=$(cat)
COMMAND=$(echo "$INPUT" | jq -r '.tool_input.command')

if echo "$COMMAND" | grep -q 'artisan'; then
  MODIFIED=$(echo "$COMMAND" | sed 's/artisan /artisan --no-interaction /g')
  jq -n --arg cmd "$MODIFIED" '{
    hookSpecificOutput: {
      hookEventName: "PreToolUse",
      permissionDecision: "allow",
      updatedInput: {
        command: $cmd
      }
    }
  }'
else
  exit 0
fi

Register the hook for Bash tool calls:

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": ".claude/hooks/artisan-flags.sh"
          }
        ]
      }
    ]
  }
}

The updatedInput field in your response replaces the tool input Claude was going to use. You can modify any field — command for Bash, file_path for Write/Edit, url for WebFetch.

You can also add additionalContext alongside updatedInput to tell Claude why you changed the input.

PreToolUse hooks are a clean way to enforce conventions without adding instructions to every prompt.


via Claude Code Docs — Hooks

~/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