Bash tool_use hangs (seconds-to-minutes, sometimes indefinitely) on the first call after a context transition (session start, EnterWorktree, ExitWorktree)
Description
Bash tool calls intermittently hang — anywhere from minutes to indefinitely with no result and no error — even though the underlying command completes instantly once it actually starts. Same root symptom as #84154 ("Bash tool intermittently takes minutes to return despite command finishing in <10ms"), reproduced independently on Windows across three separate cases in one session; filing separately since #84154 was auto-closed as stale.
Consistent pattern across all three cases: the hang happens on the first Bash (or Bash-driven subagent) tool call issued right after a context transition — session start, EnterWorktree, or ExitWorktree — never on a repeat of the same command issued immediately after.
Environment
- Claude Code v2.1.247, Windows 11 Pro (10.0.26100)
- Shell: PowerShell 7 primary; Bash tool invoked via Git Bash (POSIX)
- Model: claude-sonnet-5[1m], effort medium
ANTHROPIC_BASE_URLpointed at a local proxy (Portkey/cc-proxy), not directly at api.anthropic.com — noted for completeness, not established as causal
Evidence
Case 1 — first Bash call of a session:gh pr view <PR> --repo <owner>/<repo> hung ~4 minutes. Re-running the identical command immediately after returned in <1s.
- Ruled out credential/auth-layer causes: reading the relevant token from the Windows Credential Manager (used by
ghfor keyring-stored auth) took ~74ms in isolation; the token was confirmed live-valid via a direct GitHub API call (200 OK). No abnormal auth resolution found.
Case 2 — first Bash call right after ExitWorktree:git fetch origin pull/<N>/head:<branch> hung ~2.5 minutes. Re-running the identical command immediately after returned in <1s.
- Ruled out SSH/agent causes: the repo's remote is HTTPS (
https://github.com/...), not SSH, so no SSH agent (e.g. a password manager's SSH agent integration) is in the code path for that command at all.
Case 3 — first Bash tool_use inside a workflow subagent right after EnterWorktree (more severe: indefinite hang, not just slow):
Two consecutive /code-review workflow runs (PR #403, then PR #418), each inside a git-worktree-isolated Claude Code session. In both, the Scope-phase subagent's first Bash tool_use call (a compound git rev-parse ... && gh pr view ... command) never received a tool_result at all — journal.jsonl showed only a started entry, no result, for 9–22 minutes, no error surfaced. Stopping the task (TaskStop) and resuming from the same runId (Workflow({scriptPath, resumeFromRunId})) fixed it every time — the retry succeeded immediately.
- Evidence: run
wf_49e4fabf-9bf(PR #403), agenta458cb8cbe7fa285c, stuck ~22min; runwf_96aeefe3-d8f(PR #418), agenta2d377380ab9c8c04, stuck ~9min. Both workflow-subagent type, model sonnet, spawnDepth 1, in a worktree-isolated session.
In all three cases the delay/hang is entirely between the tool call being issued and the underlying command's own execution starting — matching the "gap between tool call issued and command's own clock starting" pattern from #84154, not something wrong with the command, git, gh, or credentials themselves.
Impact
Bash tool calls (including inside background workflow subagents) are unpredictably slow-to-indefinitely-stuck specifically around context transitions (session start, worktree enter/exit), which is confusing to debug from the user side since every plausible external cause (auth, SSH, credentials) tests out fine — the delay is in the tool-dispatch layer itself. In the workflow case (case 3) there is no automatic recovery; the task silently sits in journal.jsonl with a started-but-no-result entry until manually stopped and resumed.
What would help
Visibility into what happens between a Bash tool call being issued and the underlying shell process starting, specifically around session-start and worktree-transition boundaries (sandbox/profile setup cost, IPC round-trip, process/shell spawn overhead) — see also #84154 for the same symptom on macOS without the transition-specific angle. For case 3 specifically, some form of automatic timeout/retry for a subagent's Bash tool_use that never resolves would avoid silent multi-minute stalls in background workflows.