[BUG] toolUseContext.getAppState is not a function — React effect cleanup race during permission prompt (v2.1.111)
Summary
TypeError: q.toolUseContext.getAppState is not a function is thrown during permission-prompt rendering in v2.1.111. Appears to be a React commit-phase effect cleanup race involving stale toolUseContext closures.
Version
@anthropic-ai/claude-code@2.1.111 — npm global install, macOS (darwin-arm64), Node 22 (homebrew)
Stack Trace
ERROR q.toolUseContext.getAppState is not a function
file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:8493:15619
- (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:8493:15619)
- S0 (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:551:63170)
- G06 (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:551:76223)
- yN (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:551:76103)
- G06 (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:551:76202)
- yN (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:551:76103)
- G06 (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:551:76202)
- yN (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:551:76103)
- G06 (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:551:76202)
- yN (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:551:76103)
Root Cause Analysis
Error site — cli.js:8493
let Y = q.toolUseContext.getAppState().toolPermissionContext.mode;
d("tengu_tool_use_show_permission_request", {
messageID: q.assistantMessage.message.id,
toolName: PK(q.tool.name),
isMcp: q.tool.isMcp ?? !1,
decisionReasonType: q.permissionResult.decisionReason?.type,
sandboxEnabled: Z7.isSandboxingEnabled(),
...
});
Permission-prompt display code path reads toolPermissionContext.mode from q.toolUseContext. The object q.toolUseContext exists but the method getAppState is missing — suggesting the context was replaced with an incompatible shape, or cleaned up before this call site executed.
Call stack — cli.js:551 (React Fiber traversal)
function yN(b,I,Q,a){
if (I.subtreeFlags & 10256)
for (I = I.child; I !== null;) G06(b,I,Q,a), I = I.sibling
}
function G06(b,I,Q,a){
var Z6 = I.flags;
switch (I.tag) {
case 0: case 11: case 15:
yN(b,I,Q,a), Z6 & 2048 && S0(9,I); break;
case 1: yN(b,I,Q,a); break;
case 3: yN(b,I,Q,a), Z6 & 2048 && ( ...cache refCount work... ); break;
...
}
}
Patterns subtreeFlags & 10256, flags & 2048, and S0(9, I) match React's commit-phase effect cleanup (passive/layout destroy effects). The mutual recursion between yN and G06 is a depth-first fiber tree walk. S0(9, I) is an effect destroy invocation.
Scenario
During the React commit phase (unmount or re-render), a cleanup/destroy effect closure holds a stale reference to a toolUseContext object. By the time the effect runs, the context has been replaced with a newer-shaped object (or the old one has been partially torn down), and getAppState is no longer present on it.
Reproduction
The error consistently appears when using TeamCreate (multi-agent team spawn) with agents that trigger permission prompts concurrently. Individual sequential Agent tool spawns do not reproduce the error in my testing.
Session state at error:
- 4 parallel
claudesessions running (all withbypass permissions on) - Affected session was attempting to spawn a multi-agent team for an ad-campaign review task
- Error surfaced mid-execution, terminating that session's tool use loop
Related Issues
- #12176 — PermissionRequest Hook Race Condition (same subsystem)
- #17129 — Tool use recursion error (tool-use context related)
Workarounds
- Downgrade:
npm i -g @anthropic-ai/claude-code@2.1.110 - Avoid concurrent multi-agent teams; spawn individual
Agents sequentially
Environment
- OS: macOS 15 (Darwin 25.5.0), arm64
- Node: v22 (homebrew)
- Install:
npm i -g @anthropic-ai/claude-code@2.1.111 - Shell: zsh
---
Stack analysis performed against the installed cli.js bundle. Happy to provide additional bytes around the error site or a minimal repro if useful.
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗