Bash Tool End-to-End Execution
Overview
This flow traces a model-emitted Bash tool_use from tool dispatch through permission gating, AST safety parsing, and eventual shell execution . The whitelist does not include the actual subprocess spawn or output-streaming internals, so that tail of the flow cannot be fully cited .
Steps
- The agent loop receives a tool_use block and calls
runToolUse, which looks up the Bash tool by name and forwards to the permission+call pipeline . checkPermissionsAndCallToolruns zod input validation on the BashTool input schema and, on success, speculatively kicks off the async bash classifier in parallel with the permission dialog setup .- It then invokes the
canUseToolcallback, which in print/headless mode delegates tohasPermissionsToUseTooland only falls back to the permission prompt tool when the result isask. hasPermissionsToUseToolcomputes a base decision, and if the session is inautomode it routesaskoutcomes through the YOLO classifier instead of a user prompt .- For Bash specifically,
bashToolHasPermissionfirst tries the tree-sitter AST path: it parses the command and callsparseForSecurityFromAstto get either a cleanSimpleCommand[],too-complex, orparse-unavailable. - The parser entry point
parseCommanddispatches on token shape — subshells, compound statements, test commands, keywords, function definitions — and falls through toparseSimpleCommandfor ordinary argv . parseSimpleCommandaccumulates assignments and pre-redirects viatryParseRedirect, then collects the command name and arguments whilemaybeRedirectwraps trailing redirects into aredirected_statement.- Pipelines and
&&/||structure are layered on top byparsePipelineandparseTestAnd, givingbashToolHasPermissionthe tokenized subcommands it uses for rule matching . - On
too-complex, the code runs exact-match deny/ask/allow checks, and if nothing denies it returnsaskwith apendingClassifierCheckso the bash classifier decides . - When auto mode sends the action to the classifier,
classifyYoloActionbuilds the transcript, picks a model, and dispatches toclassifyYoloActionXmlwhen the two-stage XML classifier is enabled . classifyYoloActionXmlruns a fast stage-1 sideQuery that can return<block>no</block>for an immediate allow, otherwise escalates to a thinking stage-2 call and parses<block>/<reason>from the result .- The sideQuery itself is executed by
sideQuery, which acquires an Anthropic client viagetAnthropicClientand issues the classifier request . - Once permission resolves to
allow,checkPermissionsAndCallToolinvokesBashTool.call, which handles the_simulatedSedEditfast path and otherwise drivesrunShellCommandas an async generator collecting stdout into anEndTruncatingAccumulator. - The whitelisted source for
BashTool.callis truncated before the actualrunShellCommandsubprocess spawn and stdout/stderr streaming, so the fd-level spawn and progress-yield loop cannot be cited from the provided context .
State touched
Decisions
None of the whitelisted tokens include [decision:...] entries for this flow, so no design-decision citations are available .