claude-code - 💡(How to fix) Fix Subagent MCP tool result not delivered after WorktreeCreate hook in non-git workspace

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…

When Claude Code runs from a non-git workspace using a plugin-provided WorktreeCreate hook, an Agent(isolation: \"worktree\") can start successfully, but a subagent MCP tool call may never be delivered back to the subagent transcript.

In the observed case, the MCP tool (context-mode ctx_batch_execute) completed successfully according to the Claude Code debug log, but the subagent transcript stopped at assistant stop_reason: tool_use and never received the corresponding tool_result. The parent Agent call never returned, and WorktreeRemove was never triggered.

This does not reproduce in a normal git workspace using Claude Code's built-in git worktree handling.

Error Message

  • no timeout or error in the debug log

Root Cause

When Claude Code runs from a non-git workspace using a plugin-provided WorktreeCreate hook, an Agent(isolation: \"worktree\") can start successfully, but a subagent MCP tool call may never be delivered back to the subagent transcript.

In the observed case, the MCP tool (context-mode ctx_batch_execute) completed successfully according to the Claude Code debug log, but the subagent transcript stopped at assistant stop_reason: tool_use and never received the corresponding tool_result. The parent Agent call never returned, and WorktreeRemove was never triggered.

This does not reproduce in a normal git workspace using Claude Code's built-in git worktree handling.

Fix Action

Fix / Workaround

MCP server "context-mode": Successfully connected
Hook PreToolUse ... returned permissionDecision: allow
WorktreeCreate ... completed with status 0
"worktreePath": "/Users/.../.claude/non-git-worktree/worktrees/agent-ad33b70c131934aed-20260508233939-82006"
ToolSearchTool: selected mcp__context-mode__ctx_batch_execute
Permission suggestions for mcp__context-mode__ctx_batch_execute
[Stall] tool_dispatch_start tool=mcp__context-mode__ctx_batch_execute ... permissionDecisionMs=24256
MCP server "context-mode": Calling MCP tool: ctx_batch_execute
MCP server "context-mode": Tool 'ctx_batch_execute' completed successfully in 225ms
[Stall] tool_dispatch_end tool=mcp__context-mode__ctx_batch_execute ... outcome=ok durationMs=225

Code Example

{
  "worktreePath": "/Users/.../.claude/non-git-worktree/worktrees/agent-..."
}

---

rm -rf /tmp/cc-context-node20-retest
mkdir -p /tmp/cc-context-node20-retest
cd /tmp/cc-context-node20-retest
printf "context node20 retest\n" > README.md

---

claude --plugin-dir "/path/to/non-git-worktree-plugin" --debug hooks

---

Please start an Agent(isolation: "worktree") for a read-only investigation. The subagent may use context-mode MCP tools and Bash. It should inspect the current directory, README content, Node version, context-mode version, and report whether there are better-sqlite3 / NODE_MODULE_VERSION errors. Do not modify files.

---

MCP server "context-mode": Successfully connected
Hook PreToolUse ... returned permissionDecision: allow
WorktreeCreate ... completed with status 0
"worktreePath": "/Users/.../.claude/non-git-worktree/worktrees/agent-ad33b70c131934aed-20260508233939-82006"
ToolSearchTool: selected mcp__context-mode__ctx_batch_execute
Permission suggestions for mcp__context-mode__ctx_batch_execute
[Stall] tool_dispatch_start tool=mcp__context-mode__ctx_batch_execute ... permissionDecisionMs=24256
MCP server "context-mode": Calling MCP tool: ctx_batch_execute
MCP server "context-mode": Tool 'ctx_batch_execute' completed successfully in 225ms
[Stall] tool_dispatch_end tool=mcp__context-mode__ctx_batch_execute ... outcome=ok durationMs=225

---

~/.claude/projects/-private-tmp-cc-context-node20-retest/<session-id>/subagents/agent-<id>.jsonl

---

stop_reason: tool_use
工具名: mcp__context-mode__ctx_batch_execute
RAW_BUFFERClick to expand / collapse

Summary

When Claude Code runs from a non-git workspace using a plugin-provided WorktreeCreate hook, an Agent(isolation: \"worktree\") can start successfully, but a subagent MCP tool call may never be delivered back to the subagent transcript.

In the observed case, the MCP tool (context-mode ctx_batch_execute) completed successfully according to the Claude Code debug log, but the subagent transcript stopped at assistant stop_reason: tool_use and never received the corresponding tool_result. The parent Agent call never returned, and WorktreeRemove was never triggered.

This does not reproduce in a normal git workspace using Claude Code's built-in git worktree handling.

Environment

  • Claude Code: 2.1.133
  • Platform: macOS Darwin 24.6.0 arm64
  • Claude Code binary: native Mach-O executable at ~/.local/share/claude/versions/2.1.133
  • MCP server involved: context-mode 1.0.111
  • Node used by context-mode wrapper: Node v20.20.0, ABI 115
  • Test plugin: local Claude Code plugin providing WorktreeCreate and WorktreeRemove command hooks

Plugin behavior

The local plugin registers:

  • WorktreeCreate: creates a directory under ~/.claude/non-git-worktree/worktrees/<safe-id>/, runs git init, and returns top-level JSON:
{
  "worktreePath": "/Users/.../.claude/non-git-worktree/worktrees/agent-..."
}
  • WorktreeRemove: safely removes only direct child directories under the plugin-owned worktree root.

The hook script itself returns successfully. The created path exists, contains .git, has no lock files, and remains clean.

Reproduction steps

  1. Start from a non-git directory:
rm -rf /tmp/cc-context-node20-retest
mkdir -p /tmp/cc-context-node20-retest
cd /tmp/cc-context-node20-retest
printf "context node20 retest\n" > README.md
  1. Start Claude Code with a local plugin that provides WorktreeCreate / WorktreeRemove hooks:
claude --plugin-dir "/path/to/non-git-worktree-plugin" --debug hooks
  1. In Claude Code, ask for a subagent that uses MCP inside Agent(isolation: \"worktree\"), for example:
Please start an Agent(isolation: "worktree") for a read-only investigation. The subagent may use context-mode MCP tools and Bash. It should inspect the current directory, README content, Node version, context-mode version, and report whether there are better-sqlite3 / NODE_MODULE_VERSION errors. Do not modify files.
  1. Observe that WorktreeCreate succeeds and ctx_batch_execute succeeds, but the Agent never returns.

Observed debug log timeline

Relevant debug log: ~/.claude/debug/ab196228-7fce-432c-8f05-100080794a4a.txt

Key events:

MCP server "context-mode": Successfully connected
Hook PreToolUse ... returned permissionDecision: allow
WorktreeCreate ... completed with status 0
"worktreePath": "/Users/.../.claude/non-git-worktree/worktrees/agent-ad33b70c131934aed-20260508233939-82006"
ToolSearchTool: selected mcp__context-mode__ctx_batch_execute
Permission suggestions for mcp__context-mode__ctx_batch_execute
[Stall] tool_dispatch_start tool=mcp__context-mode__ctx_batch_execute ... permissionDecisionMs=24256
MCP server "context-mode": Calling MCP tool: ctx_batch_execute
MCP server "context-mode": Tool 'ctx_batch_execute' completed successfully in 225ms
[Stall] tool_dispatch_end tool=mcp__context-mode__ctx_batch_execute ... outcome=ok durationMs=225

After that line, there are no further relevant events:

  • no tool_result recorded in the subagent transcript
  • no subagent final response
  • no parent Agent tool result
  • no WorktreeRemove
  • no timeout or error in the debug log

Transcript evidence

The subagent transcript exists at a path like:

~/.claude/projects/-private-tmp-cc-context-node20-retest/<session-id>/subagents/agent-<id>.jsonl

Its final event is an assistant message with:

stop_reason: tool_use
工具名: mcp__context-mode__ctx_batch_execute

There is no corresponding tool_result event after it, even though the debug log says the MCP tool completed successfully.

The parent transcript similarly stops at the Agent tool use and never receives an Agent tool result.

Expected behavior

After the MCP tool completes successfully, Claude Code should deliver the MCP tool_result back into the subagent transcript, allow the subagent to continue/finalize, then return the parent Agent result and trigger WorktreeRemove cleanup.

Actual behavior

The MCP tool completes successfully according to debug logs, but the result is not delivered to the subagent transcript. The Agent hangs indefinitely and WorktreeRemove is not triggered.

Comparison with normal git workspace

In a normal git workspace, Agent(isolation: "worktree") does not show this failure in the same environment.

Separately, an A/B test showed that with the non-git plugin path, the subagent shell pwd remains the original non-git directory rather than the returned worktreePath. This suggests the hook-provided worktreePath may be treated as lifecycle metadata rather than the actual subagent shell cwd.

Impact

This makes plugin-provided WorktreeCreate hooks usable only as a startup compatibility shim for non-git workspaces. If a subagent uses MCP tools in this mode, the session can hang and the cleanup hook may never run, leaving orphan plugin-created worktree directories.

Notes

An earlier native module ABI issue with context-mode / better-sqlite3 was fixed and is not the current failure. In the current repro, the debug log shows ctx_batch_execute completing successfully with outcome=ok durationMs=225, but no tool_result reaches the subagent transcript.

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…

FAQ

Expected behavior

After the MCP tool completes successfully, Claude Code should deliver the MCP tool_result back into the subagent transcript, allow the subagent to continue/finalize, then return the parent Agent result and trigger WorktreeRemove cleanup.

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 Subagent MCP tool result not delivered after WorktreeCreate hook in non-git workspace