fix(agent): register built-in tools from --allowedTools#1267
fix(agent): register built-in tools from --allowedTools#1267josephfinlayson wants to merge 1 commit intoanthropics:mainfrom
Conversation
…cts actual toolset Today --allowedTools sets the auto-approve gate-list (Options.allowedTools) but never sets Options.tools, so the SDK's spawned CLI defaults init.tools to the reduced set [Bash, Read] in agent mode. The model literally cannot call Edit/Glob/Grep/Write even when allow-listed. Bind built-in tool names from --allowedTools to Options.tools so the registered toolset matches what the user requested. MCP tool names (mcp__*) and Bash() pattern entries are filtered out of the registration list (they aren't base tools) but stay in allowedTools as before. Fixes anthropics#690, anthropics#181 (in part), and the docs vs. behaviour gap users hit in anthropics#533 and anthropics#264.
|
This is affecting us in production-like GitHub Actions runs for a custom-built agent. Our workflow passes built-in tools via
That causes the agent to burn turns retrying or working around unavailable native search tools, and in some cases the run fails with We can add This PR’s distinction between tool registration and approval matches the behavior we need: if a workflow explicitly passes built-in tools through Would appreciate this getting fixed soon 🙏 |
Symptom
After this PR,
init.toolsreports the actual built-in tool set requested via--allowedToolsinstead of always defaulting to[Bash, Read]in agent mode. Today the model literally cannot callEdit/Glob/Grep/Write/MultiEdit/LSeven when those names are passed viaclaude_args: --allowedTools ….Before / after
Run with
claude_args: --allowedTools 'Bash(git:*),Edit,Read,Glob,Grep,Write':Before
The model has no way to call
Edit,Glob,Grep, orWrite.After
Registration matches what the user asked for.
Root cause
The SDK's
Options.toolsfield is the registration knob — it controls which built-in tools are wired into the spawned CLI session.Options.allowedToolsis a separate, downstream auto-approve gate-list.parseSdkOptionsconstructedsdkOptionswithmodel,maxTurns,allowedTools,disallowedTools,systemPrompt,fallbackModel,pathToClaudeCodeExecutable,extraArgs,env,settingSources— but nevertools. Withtoolsundefined, the SDK falls through to a reduced default in agent mode and the model only sees[Bash, Read].Issue #690 has this analysis (verbatim):
The fix belongs in the option-parsing layer because both agent and tag modes funnel through
parseSdkOptions.Maintainer-blessed pattern that this PR makes work
examples/ci-failure-auto-fix.ymladvertises:Today that string only sets the auto-approve gate-list — the model never actually receives
Edit/MultiEdit/Write/Glob/Grep/LS. After this PR, that example does what users (and the docs) expect.What changed
base-action/src/parse-sdk-options.ts:BUILT_IN_TOOL_NAMESconstant: the SDK-known base tools (Bash,Read,Write,Edit,MultiEdit,Glob,Grep,LS,NotebookRead,NotebookEdit,Task,TodoWrite,WebFetch,WebSearch).extractBuiltInTools(mergedAllowedTools)helper that:(…)suffix (Bash(git:*)→Bash),mcp__*entries (those are MCP tool names, not base tools),BUILT_IN_TOOL_NAMES,undefinedif nothing matches (so we leaveOptions.toolsunset and the SDK keeps its current default — preserving prior behaviour for that case).sdkOptions.toolsin the existingsdkOptionsobject literal.sdkOptions.allowedToolsis unchanged — the auto-approve gate-list still carries the original entries (Bash patterns, MCP names, etc.) so MCP tool gating andBash(git:*)-style patterns keep working.Backwards compatibility
--allowedToolsonly contains MCP/Bash(...)entries (after stem filtering produces no built-ins),Options.toolsstays undefined and behaviour is unchanged.init.toolsexpand to what they asked for, not contract — they always wanted those tools; the auto-approve gate matched the same names, the registration just never followed.extraArgs, MCP config merging, or tag/agent mode files.Tests
Added six cases to
base-action/test/parse-sdk-options.test.tsunder a newbuilt-in tool registration (sdkOptions.tools)describe block:--allowedTools Edit,Read,Glob,Grep→tools = ["Edit","Read","Glob","Grep"].--allowedTools Bash(git:*),Edit,Read,mcp__github_comment__update_claude_comment→tools = ["Bash","Edit","Read"];allowedToolskeeps the original entries.--allowedTools→toolsundefined.--allowedToolswith only MCP entries →toolsundefined;allowedToolskeeps the MCP entries.--allowedTools Edit,Edit,Read→tools = ["Edit","Read"](deduped).--allowedTools Foobar,Read→tools = ["Read"](unknown stem dropped).claudeArgs--allowedToolsand directoptions.allowedTools.bun test→ 672 pass / 0 fail (34 pass / 0 fail inparse-sdk-options.test.ts).bun run typecheck→ clean.bun run format:check→ clean.Fixes / relates to
Fixes #690. Addresses the docs-vs-behaviour gap users hit in #181, #533, and #264.