Feature request: Worktree-spawned agents should inherit parent session's hooks (PreToolUse/PostToolUse)
Problem
When using the Agent tool with isolation: "worktree", the spawned subagent runs in a git worktree directory. However, the subagent does not inherit the parent session's hook configuration from .claude/settings.json.
This means:
- PreToolUse and PostToolUse hooks do not fire for any tool calls made by the worktree agent
- No trace events are captured for the subagent's work
- The parent session has no visibility into what tools the subagent used, what files it modified, or how it behaved
Why this matters
We are building an evaluation framework (Get Anything Done) that tests AI coding agents under different workflow conditions. We need to capture behavioral data (tool calls, skill invocations, file mutations) from each eval run to compare agent behavior across conditions.
The isolation: "worktree" feature is perfect for eval isolation — each agent gets a clean working tree. But without hooks firing, we get the code output with zero process data. We can see WHAT the agent built but not HOW it built it.
Current behavior
- Parent session has
.claude/settings.jsonwith PreToolUse/PostToolUse hooks configured - Parent spawns
Agenttool withisolation: "worktree" - Worktree agent runs, makes 50-100+ tool calls
- None of those tool calls trigger the hooks
- Parent gets the agent's result text but no hook event data
Expected behavior
Worktree agents should inherit the parent session's hook configuration. Every tool call in the worktree should fire the same PreToolUse/PostToolUse hooks as the parent session, writing events to the hook handler.
Alternatively: expose a way to configure hooks for worktree agents specifically (e.g., an env parameter on the Agent tool that sets environment variables the hook handler can read).
Environment
- Claude Code version: latest (as of April 2026)
- OS: Windows 11
- Hook handler: Custom Node.js script at an absolute path in
.claude/settings.json - The hook handler works correctly in the parent session — only worktree agents are affected
Workaround attempted
We tried setting GAD_EVAL_TRACE_DIR as an environment variable in the agent's prompt (asking it to export the var). This doesn't work because:
- The agent's
exportruns in a bash subprocess, not in Claude Code's process - The hook handler runs in Claude Code's process, not in the agent's bash
- Even if the env var were set, the hooks don't fire at all for worktree agents
Impact
This blocks our ability to collect behavioral traces from isolated eval runs, which is the core measurement capability of our evaluation framework. We currently have to choose between:
- Isolation (worktree, clean data, no traces)
- Tracing (same session, hooks fire, but potential contamination between runs)
We need both.
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗