claude-code - 💡(How to fix) Fix [BUG] toolUseContext.getAppState is not a function — React effect cleanup race during permission prompt (v2.1.111) [3 comments, 3 participants]

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…
GitHub stats
anthropics/claude-code#49345Fetched 2026-04-17 08:43:50
View on GitHub
Comments
3
Participants
3
Timeline
15
Reactions
0
Timeline (top)
labeled ×5cross-referenced ×4commented ×3closed ×1

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.

Error Message

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

Root Cause Analysis

Fix Action

Fix / Workaround

Workarounds

Code Example

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)

---

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(),
  ...
});

---

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;
    ...
  }
}
RAW_BUFFERClick to expand / collapse

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/[email protected] — 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 claude sessions running (all with bypass 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

  1. Downgrade: npm i -g @anthropic-ai/[email protected]
  2. 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/[email protected]
  • 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.

extent analysis

TL;DR

Downgrade to @anthropic-ai/[email protected] to potentially resolve the TypeError: q.toolUseContext.getAppState is not a function issue.

Guidance

  • The error is likely caused by a React commit-phase effect cleanup race involving stale toolUseContext closures, so reviewing the React component lifecycle and effect handling may help.
  • To verify the issue, try reproducing it with the provided reproduction steps, specifically using TeamCreate with agents that trigger permission prompts concurrently.
  • As a temporary workaround, avoid concurrent multi-agent teams and spawn individual Agents sequentially.
  • Reviewing related issues, such as #12176 and #17129, may provide additional insight into the problem.

Example

No code snippet is provided as the issue is related to a specific version of the @anthropic-ai/claude-code package and requires a deeper understanding of the codebase.

Notes

The provided stack trace and code snippets are specific to the @anthropic-ai/[email protected] version, and the issue may not be present in other versions. Additionally, the error only occurs when using TeamCreate with concurrent permission prompts, so individual sequential Agent tool spawns may not reproduce the issue.

Recommendation

Apply the workaround by downgrading to @anthropic-ai/[email protected] using npm i -g @anthropic-ai/[email protected], as this version is reported to not have the issue.

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…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING