claude-code - 💡(How to fix) Fix Feature: Hook event for subagent spawning (OnAgentSpawn) [3 comments, 3 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#49106Fetched 2026-04-17 08:50:43
View on GitHub
Comments
3
Participants
3
Timeline
8
Reactions
0
Author
Timeline (top)
commented ×3labeled ×3closed ×1cross-referenced ×1

Root Cause

The current architecture puts instruction inheritance entirely on the model, which is the one component that can't be trusted to do it consistently. Moving enforcement to the harness eliminates the drift problem entirely.

RAW_BUFFERClick to expand / collapse

Problem

Subagents do not inherit CLAUDE.md or any project-level instructions. The only way to pass rules to subagents is by instructing the model to manually prepend content to each subagent prompt.

In practice, the model progressively abbreviates these instructions across multi-subagent sessions. Auditing across two separate sessions showed the same pattern: the first subagent gets full rules, subsequent ones get progressively shortened summaries (down to ~5% coverage by task 4+). This is a model-level behavior under context pressure — no amount of instructions or memory prevents it.

Request

Add an OnAgentSpawn hook event that fires when the Agent tool is invoked, allowing users to intercept and modify subagent prompts before execution.

This fits naturally into the existing hook architecture (PreToolUse, PostToolUse, etc.) and would enable:

  • Automatic preamble injection — prepend project rules to every subagent prompt without relying on the model
  • Conditional injection — inject different rules based on agent type (e.g., code-writing agents get quality rules, Explore agents don't)
  • Auditing/logging — track what subagents are being spawned and what they receive
  • Rate limiting — control subagent spawn frequency

Simpler Alternative

If a full hook event is too heavy, a subagentPreamble setting in settings.json (string or file path) that the harness automatically prepends to every subagent prompt would also solve the core problem. Less flexible but simpler to implement.

Why This Matters

The current architecture puts instruction inheritance entirely on the model, which is the one component that can't be trusted to do it consistently. Moving enforcement to the harness eliminates the drift problem entirely.

extent analysis

TL;DR

Implementing an OnAgentSpawn hook event or adding a subagentPreamble setting in settings.json can help ensure consistent instruction inheritance for subagents.

Guidance

  • Consider adding an OnAgentSpawn hook event to the existing hook architecture to allow users to modify subagent prompts before execution, enabling features like automatic preamble injection and auditing.
  • Alternatively, introducing a subagentPreamble setting in settings.json can provide a simpler solution to prepend project rules to every subagent prompt.
  • Evaluate the trade-offs between flexibility and implementation complexity when deciding between the two approaches.
  • Assess the potential impact of the proposed solutions on the overall system architecture and performance.

Example

No code snippet is provided as the issue does not contain specific code references.

Notes

The proposed solutions aim to address the issue of inconsistent instruction inheritance for subagents, but their effectiveness may depend on the specific use cases and system configurations.

Recommendation

Apply a workaround by introducing a subagentPreamble setting in settings.json, as it provides a simpler and more straightforward solution to the problem, allowing for consistent instruction inheritance without relying on the model.

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 Feature: Hook event for subagent spawning (OnAgentSpawn) [3 comments, 3 participants]