fix(agent): register built-in tools from --allowedTools#1267
Open
josephfinlayson wants to merge 1 commit intoanthropics:mainfrom
Open
fix(agent): register built-in tools from --allowedTools#1267josephfinlayson wants to merge 1 commit intoanthropics:mainfrom
josephfinlayson 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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.