ToolSearch intermittently cannot find LSP inside custom subagents

Status Open
Reported on v2.1.226
Maintainer reply None cached
Activity 0 comments · opened Aug 9, 2026

Summary

ToolSearch intermittently cannot find the deferred built-in LSP tool inside a custom subagent. The same probe returns either LSP_LOADED yes or LSP_LOADED no with exit code 0.

The interactive parent session can load LSP in the same TypeScript repository. The failure also occurs with an empty strict MCP configuration, so MCP server count is not sufficient to explain it.

Environment

  • Claude Code: 2.1.226
  • macOS, arm64
  • TypeScript repository with the user-scope TypeScript LSP plugin enabled
  • Probe agent uses disallowedTools: ["Agent"], with no tools: allowlist
  • Invocation mode: claude -p --model haiku --dangerously-skip-permissions

Minimal reproduction

Run this command five times from a TypeScript repository where the TypeScript LSP plugin is enabled:

claude -p \
  --model haiku \
  --dangerously-skip-permissions \
  --strict-mcp-config \
  --mcp-config '{"mcpServers":{}}' \
  --agents '{"probe":{"description":"lsp probe","disallowedTools":["Agent"],"prompt":"Be literal."}}' \
  'Use the Agent tool with subagent_type probe, prompt: "Call ToolSearch query select:LSP max_results 3. Reply exactly one line: LSP_LOADED yes or LSP_LOADED no." Then output that reply verbatim.'

Expected on every run:

LSP_LOADED yes

Observed across five identical runs with empty strict MCP:

no
no
no
yes
yes

Count: 2/5 successful.

A verbose stream-json failure confirmed that the nested agent called ToolSearch with query: "select:LSP". The tool returned:

No matching deferred tools found

Repeated measurements

Every condition used five identical probes.

| Condition | Successful runs |
| --- | ---: |
| Normal MCP surface | 1/5 |
| Empty strict MCP | 2/5 |
| Eight-server user MCP set | 2/5 |
| First four-server half | 2/5 |
| Second four-server half | 0/5 |
| Four two-server quarters | 0/5, 0/5, 1/5, 0/5 |
| Eight individual servers | 1/5, 1/5, 2/5, 0/5, 1/5, 3/5, 2/5, 2/5 |
| Normal surface after removing stale worktrees | 2/5 |

No tested configuration reached 5/5.

Ruled-out sufficient causes

  1. MCP server count. Empty strict MCP still failed 3/5 times.
  2. One specific MCP server. Every single-server configuration and the empty configuration failed.
  3. Project-specific database MCP startup. Empty strict MCP failed without project MCP servers.
  4. Agent tool allowlists. The probe uses disallowedTools, not a tools: allowlist.
  5. Accumulated worktrees. Removing stale worktrees and pruning metadata did not make the probe reliable.
  6. Probe-agent noncompliance. Verbose events recorded the nested ToolSearch call and its missing-tool result.
  7. Missing parent-session LSP registration. The interactive parent session loads LSP successfully in the same repository.

Impact

Custom subagents cannot reliably use workspaceSymbol, findReferences, goToDefinition, or other LSP operations. A failed discovery appears as an absent deferred tool registry entry. Retrying sometimes succeeds.

Requested investigation

Please inspect deferred built-in tool registration and registry finalization during custom subagent startup in non-interactive claude -p sessions.

A useful integration test would run the command above five times and require five LSP_LOADED yes results with both an empty strict MCP configuration and a representative MCP surface.

View original on GitHub ↗