chat.tools.terminal.autoApprove (and related terminal tool auto-approval) does not match inner commands when the command line uses common wrappers (timeout, bash -c, env, sudo time, etc.)
@anthonykim1 is already working on this.
Since May 26, 2026.
Assessment
This issue has not been assessed yet.
Description
Problem
The chat.tools.terminal.autoApprove setting (and the underlying auto-approval logic used by the Run in Terminal tool) only matches against the outermost command(s) returned by TreeSitterCommandParser.extractSubCommands.
Common wrapper patterns used in agent workflows (timeouts, explicit shells for cd + command, environment setup, etc.) cause the inner "real" command (git, npm run build, etc.) to be invisible to the rule matcher. As a result, granular allow/deny rules for those inner commands never fire, and users are forced to either:
- Approve every invocation manually, or
- Use very broad rules (e.g.
bashor the fulltimeout ...line), which is both less safe and less convenient.
Steps to Reproduce
- Add a rule such as:
"chat.tools.terminal.autoApprove": { "git": true, "npm": true } - Ask the agent to run something that produces a wrapped command, for example the pattern commonly generated from
copilot-instructions.md:
(ortimeout 30 bash -c 'cd /home/src/code && git status --porcelain'env ...,sudo time git ...,bash -c "...", etc.) - Observe that the command requires explicit confirmation even though
git(ornpm) would have been auto-approved without the wrapper.
Expected behavior
The auto-approval logic should "see through" well-known wrappers (the same way other parts of the terminal chat agent tools already do for sandboxing/display) and evaluate the effective inner command(s) against the user's rules. A git rule should still apply when the command is wrapped in timeout 30 bash -c '...'.
Actual behavior
Only the outer command (timeout, bash, env, etc.) is considered. Inner commands are never extracted for rule matching.
Additional context / motivation
- This pattern is actively used in real agent instructions (see the user's
copilot-instructions.mdfor the exacttimeout 30 bash -c 'cd ... && ...'idiom). - The terminal chat agent tools already contain richer command parsing that identifies wrappers and inner tokens (
src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/tools/terminalCommandParser.ts–parseCommand,wrappers,segmentHead, etc.). - Recent work (#315881 and related compression-parsing improvements) enhanced wrapper handling for other purposes; the auto-approve path was not updated at the same time.
- Security note: the existing
neverAutoApproveCommandsset inrunInTerminalHelpers.ts(shells, interpreters,sudo,eval, etc.) should continue to be respected when deciding what to surface for approval suggestions.
References to current implementation
- Primary parser used for auto-approval:
src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/treeSitterCommandParser.ts
extractSubCommands(the query(command) @command) andextractCommands. - Auto-approval decision logic:
src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/tools/commandLineAnalyzer/autoApprove/commandLineAutoApprover.ts
CommandLineAutoApproveAnalyzer(incommandLineAutoApproveAnalyzer.ts). - Richer wrapper-aware parser (already used for sandboxing):
src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/tools/terminalCommandParser.ts. neverAutoApproveCommandsguard:
src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/runInTerminalHelpers.ts.- Platform-level auto-approver (similar tree-sitter usage):
src/vs/platform/agentHost/node/commandAutoApprover.ts.
Possible implementation direction
- Extend
CommandLineAutoApproveAnalyzer(or the approver) to also call the existing wrapper-stripping logic fromterminalCommandParser.ts(or a shared helper) and feed the effective inner commands to the rule matcher. - Alternatively, enhance
TreeSitterCommandParser(or add a post-processing step) to optionally return "unwrapped" commands for the auto-approve use case. - Ensure the change does not affect the security-sensitive
neverAutoApproveCommandslist or the exact-command-line matching path.
This would make the auto-approve experience consistent with the rest of the terminal agent tooling and dramatically improve usability for realistic long-running or multi-step agent commands.
- Dominant language
- TypeScript
- Stars
- 193k
- Forks
- 42.9k
- PR merge metrics
- PR metrics pending
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from microsoft/vscode
-
testplan-item
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
new release
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
testplan-item
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
testplan-item
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
All issues in microsoft/vscode
Similar issues
-
clawsweeper:fix-shape-clear clawsweeper:queueable-fix clawsweeper:source-repro impact:ux-friction issue-rating: 🦞 diamond lobster no-stale P3
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Difficulty 1/5 Under an hour Newbie friendliness 76/100
-
code-quality refactoring
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
github/gh-aw-firewall#8816 ·
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
vercel/react-tweet#225 ·