claude-code - 💡(How to fix) Fix PreToolUse hooks do not fire for sub-agent (Agent tool) Bash calls

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

PreToolUse hooks configured in ~/.claude/settings.json fire correctly for the main conversation's Bash tool calls, but do not fire for Bash calls made by sub-agents spawned via the Agent tool.

This means any preprocessing or output filtering applied by hooks (e.g., token optimization proxies, security wrappers, logging) is silently bypassed when work is delegated to sub-agents — which is the recommended pattern for complex tasks.

Root Cause

  • #46696 — Sub-agents not inheriting environment variables (same root cause: sub-agent isolation)
  • #5812 — Hooks bridging context between sub-agents and parent (closed, different scope)
  • #29068 — Including agent_id in hook event inputs (closed, related)

Fix Action

Fix / Workaround

Current Workaround

No clean workaround exists. Options considered:

  • Manually prefixing rtk in every agent prompt — fragile, adds prompt overhead, agents forget
  • Avoiding sub-agents for Bash-heavy work — defeats the purpose of delegation
  • Using MCP tools instead of Bash — not always possible, doesn't help non-MCP hooks

Code Example

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": "echo 'hook fired' >> /tmp/hook-log.txt"
          }
        ]
      }
    ]
  }
}
RAW_BUFFERClick to expand / collapse

Feature Type

New feature request

Description

PreToolUse hooks configured in ~/.claude/settings.json fire correctly for the main conversation's Bash tool calls, but do not fire for Bash calls made by sub-agents spawned via the Agent tool.

This means any preprocessing or output filtering applied by hooks (e.g., token optimization proxies, security wrappers, logging) is silently bypassed when work is delegated to sub-agents — which is the recommended pattern for complex tasks.

Reproduction

  1. Configure a PreToolUse hook on Bash in ~/.claude/settings.json:
{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": "echo 'hook fired' >> /tmp/hook-log.txt"
          }
        ]
      }
    ]
  }
}
  1. Run a Bash command directly in the main conversation → hook fires, line appears in /tmp/hook-log.txt

  2. Spawn a sub-agent via the Agent tool that runs Bash commands (e.g., find, grep, ls) → hook does not fire, no new lines in log

Use Case

I use RTK (Rust Token Killer), a token-optimized CLI proxy that filters verbose command output to reduce token consumption by 40-90%. It's configured as a PreToolUse hook that rewrites Bash commands through the proxy.

When the main agent delegates exploration or implementation to sub-agents (the recommended pattern per CLAUDE.md), all sub-agent Bash calls bypass RTK entirely. In a typical research session, sub-agents run 50-100+ find/grep/ls commands — all unfiltered, consuming full tokens.

This applies to any PreToolUse hook, not just RTK: security wrappers, audit loggers, command rewriters, etc.

Expected Behavior

PreToolUse (and PostToolUse) hooks should fire for sub-agent tool calls, same as for the main conversation. Either:

  1. Default propagation — hooks fire for all tool calls regardless of agent depth (preferred, least surprising)
  2. Opt-in propagation — a propagateToSubagents: true flag on hook definitions
  3. SubagentStart hook support — allow SubagentStart hooks to register PreToolUse hooks for the sub-agent's lifetime

Current Workaround

No clean workaround exists. Options considered:

  • Manually prefixing rtk in every agent prompt — fragile, adds prompt overhead, agents forget
  • Avoiding sub-agents for Bash-heavy work — defeats the purpose of delegation
  • Using MCP tools instead of Bash — not always possible, doesn't help non-MCP hooks

Related Issues

  • #46696 — Sub-agents not inheriting environment variables (same root cause: sub-agent isolation)
  • #5812 — Hooks bridging context between sub-agents and parent (closed, different scope)
  • #29068 — Including agent_id in hook event inputs (closed, related)

Environment

  • Linux (WSL2), Claude Code with Agent tool
  • PreToolUse hook configured in ~/.claude/settings.json
  • Sub-agents spawned via Agent tool (Explore, Plan, general-purpose types)

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING