Subagent MCP tool result not delivered after WorktreeCreate hook in non-git workspace

Resolved 💬 3 comments Opened May 8, 2026 by Dee-0503 Closed Jun 5, 2026

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.

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗