claude-code - 💡(How to fix) Fix PreToolUse hook input missing agent_id for tmux/pane-based teammates [2 comments, 2 participants]

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…
GitHub stats
anthropics/claude-code#54785Fetched 2026-04-30 06:36:05
View on GitHub
Comments
2
Participants
2
Timeline
7
Reactions
0
Author
Timeline (top)
labeled ×5commented ×2

For PreToolUse hooks fired by teammate (Agent-tool) tool calls, the hook input includes agent_id when the teammate runs in in-process mode, but omits agent_id when the teammate runs in tmux/pane-based mode. Same teammate, same Agent invocation, same hook script — different payload depending on teammateMode.

This breaks hook scripts that branch on agent_id to distinguish main-agent vs subagent calls.

Root Cause

For PreToolUse hooks fired by teammate (Agent-tool) tool calls, the hook input includes agent_id when the teammate runs in in-process mode, but omits agent_id when the teammate runs in tmux/pane-based mode. Same teammate, same Agent invocation, same hook script — different payload depending on teammateMode.

This breaks hook scripts that branch on agent_id to distinguish main-agent vs subagent calls.

Code Example

import json, sys
data = json.load(sys.stdin)
is_main = not data.get("agent_id")  # documented contract: agent_id set only for subagent calls
# ... applies different rules based on is_main
RAW_BUFFERClick to expand / collapse

Summary

For PreToolUse hooks fired by teammate (Agent-tool) tool calls, the hook input includes agent_id when the teammate runs in in-process mode, but omits agent_id when the teammate runs in tmux/pane-based mode. Same teammate, same Agent invocation, same hook script — different payload depending on teammateMode.

This breaks hook scripts that branch on agent_id to distinguish main-agent vs subagent calls.

Repro

Hook script (force_background_bash.py, registered for PreToolUse on Bash):

import json, sys
data = json.load(sys.stdin)
is_main = not data.get("agent_id")  # documented contract: agent_id set only for subagent calls
# ... applies different rules based on is_main

Spawn the same teammate via Agent (with team_name/name) and have them run a Bash call.

Modeagent_id in hook inputHook treats teammate as
In-process (no tmux)presentsubagent
Pane-based (tmux)absentmain agent

Concrete observed effect with the hook above:

  • In-process teammate: Bash with timeout: 35000 runs synchronously (subagent rules — no auto-promote); explicit run_in_background: true is blocked.
  • Pane-based teammate (tmux): same Bash call gets auto-promoted to background (main-agent rules); explicit run_in_background: true is allowed.

Expected

agent_id semantics in PreToolUse hook input should be consistent across teammate spawn modes — a teammate is a teammate regardless of whether the harness chose in-process or pane-based execution.

Related

  • #29068 (closed) — added agent_id to common hook input
  • #24175 (closed/stale) — lifecycle hook firing inconsistency between in-process and pane-based teammates. This issue is narrower: PreToolUse does fire in both modes here, but with different payloads.

Environment

  • Claude Code 2.1.119
  • Linux
  • Reproduces with a vanilla Agent call using team_name/name and a PreToolUse hook reading agent_id from stdin.

🤖 Generated with Claude Code

extent analysis

TL;DR

The agent_id field in the PreToolUse hook input should be consistently included or excluded across different teammate spawn modes to fix the inconsistent behavior.

Guidance

  • Review the code responsible for generating the PreToolUse hook input in both in-process and pane-based modes to identify the discrepancy in agent_id inclusion.
  • Verify that the agent_id field is correctly set or unset based on the teammate type (main-agent or subagent) in both modes.
  • Consider modifying the hook script to handle the inconsistent agent_id presence, potentially by checking for other indicators of teammate type.
  • Investigate related issues (#29068 and #24175) for potential clues on the root cause of the inconsistency.

Example

No code snippet is provided as the issue does not contain sufficient information to generate a specific example.

Notes

The fix may require changes to the Claude Code framework or the Agent-tool implementation, depending on where the inconsistency originates.

Recommendation

Apply a workaround by modifying the hook script to handle the inconsistent agent_id presence, as the root cause of the issue is unclear and may require further investigation.

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

claude-code - 💡(How to fix) Fix PreToolUse hook input missing agent_id for tmux/pane-based teammates [2 comments, 2 participants]