In VS Code, how do you configure chat.tools.terminal.autoApprove so Copilot's agent runs your test command unprompted while git push still asks?
answer
- one terminal tool, each command judged
- true runs, false asks
- slashes turn a key into a regex
- every subcommand must match
- asking is not blocking
basics
~20 sAdd rules to chat.tools.terminal.autoApprove: a command or /regex/ set to true runs without a prompt, one set to false always asks. Rules match each subcommand, a false match wins, and a false rule asks rather than blocks.
solid answer
~40 sUnder Manual permissions, VS Code judges every terminal command the agent proposes against `chat.tools.terminal.autoApprove`. A key set to `true` auto-approves, `false` requires approval, and a key wrapped in `/` is a regular expression — so `"/^npm (test|run lint)\\b/": true` and `"/^git push\\b/": false` do the job. Your rules sit on top of built-in ones: common read-only commands run automatically, while `rm`, `rmdir`, `del`, `kill`, `curl`, `wget`, `eval`, `chmod`, `chown` and `Remove-Item` ask. Rules match each subcommand, so `npm test && rm -rf build` still asks, and a `false` match always wins; object syntax with `matchCommandLine: true` matches the whole line instead. A `false` rule only asks — to refuse a command outright you need a `PreToolUse` hook (Preview) returning `permissionDecision: "deny"`. The docs call terminal auto-approval best-effort, not a security boundary.
code
json · 6 lines{
"chat.tools.terminal.autoApprove": {
"/^npm (test|run lint)\\b/": true,
"/^git push\\b/": false
}
}go deeper
Recall the setting name and the meaning of true and false, and that commands like rm ask by default.
Explain regex keys, per-subcommand matching, why a false match wins in a compound command, and that false asks rather than blocks.
Show how the rules interact with Allow all and with the sandbox's auto-approval, and when a PreToolUse hook is the right tool.
Decide whether a team commits shared rules in workspace settings or relies on the sandbox, given that parsing is best-effort.
## Where terminal approval fits Copilot's agent in VS Code runs every shell command through **one terminal tool**. Approving that tool once would approve anything it might ever run, so VS Code evaluates **each command separately** instead. Under the default **Manual permissions** level, a command either matches an auto-approve rule and runs, or waits for you to select **Allow**. Under **Allow all** or **Autopilot**, no command waits, whatever the rules say. The rules live in the `chat.tools.terminal.autoApprove` setting, which you can keep in user settings or commit in the workspace's `.vscode/settings.json` for the team. ## Rule syntax - **A plain key** such as `"mkdir": true` auto-approves that command. - **`false`** requires approval, for example `"del": false`. - **A key wrapped in `/`** is a regular expression: `"/^git (status|show\\b.*)$/": true` approves `git status` and anything starting with `git show`. - **Object syntax** with `matchCommandLine: true` matches the full command line instead of each subcommand. ## The built-in rules Your entries are added to built-in defaults. By default, common read-only commands run automatically and these require approval: | Built-in `false` rule | Why it asks | |---|---| | `rm`, `rmdir`, `del`, `Remove-Item` | Delete files or folders | | `kill` | Stops processes | | `curl`, `wget` | Reach the network and can download or upload data | | `eval` | Runs arbitrary strings as code | | `chmod`, `chown` | Change permissions and ownership | The Experimental `chat.tools.terminal.ignoreDefaultAutoApproveRules` drops the built-ins and uses only your rules; the docs warn that the built-in deny rules exist to protect against dangerous commands. Separately, `chat.tools.terminal.blockDetectedFileWrites` defaults to `outsideWorkspace`, which requires approval when VS Code detects a command writing outside the workspace. ## How compound commands are judged By default, rules match **each subcommand**: 1. VS Code splits `npm test && rm -rf build` into `npm test` and `rm -rf build`. 2. `npm test` matches your `true` rule; `rm -rf build` matches the built-in `rm: false`. 3. A compound command is auto-approved only when **every** subcommand matches a `true` rule and **none** matches a `false` one. A `false` match always takes precedence, so this one asks. ## Limits worth knowing - **`false` asks; it does not block.** If you click **Allow**, the command runs. To refuse a command in the Local harness, use a `PreToolUse` hook (Preview) that returns `permissionDecision: "deny"`. - **Best-effort parsing.** The bash and PowerShell grammars might miss subcommands, zsh and fish are parsed as bash, file-write detection is limited, and obfuscated commands can evade matching. For prompt-injection risk, the docs point to the terminal sandbox or a container. - **The sandbox changes the flow.** In Local sessions, commands that run inside an enabled sandbox are approved automatically by default (`chat.agent.sandbox.allowAutoApprove` is `true`), so your `false` rules stop prompting there unless you set it to `false`. ## A worked team setup 1. Decide which commands the agent runs constantly and safely — the test runner, the linter, read-only Git commands — and give each a `true` rule anchored with `^` so it cannot match inside a longer command. 2. Add `false` rules for commands that touch shared state, such as `git push` or a deploy script, so they always ask even if a broader pattern would match. 3. Commit the rules in the workspace's `.vscode/settings.json` so every teammate gets the same behaviour, and review changes to them like any other permission change. 4. Watch a few sessions: each command the agent ran appears in the chat with **Show Output** for its output and **Show Terminal** for the full integrated terminal, so you can see which commands ran without a prompt. Keep regexes narrow. A pattern such as `/^npm/` approves `npm install` of any package as well as `npm test`, and a rule that matches the whole line through `matchCommandLine` stops VS Code from checking each subcommand on its own. ## Related switches - `chat.tools.terminal.enableAutoApprove` — set it to `false` to require approval for every command. - `chat.tools.eligibleForAutoApproval` — set a tool to `false` so its confirmation dialog never offers auto-approval. - **Chat: Manage Tool Approval** and **Chat: Reset Tool Confirmations** — review or clear approvals saved from dialogs.
- You turn on the terminal sandbox in a Local session. Does your `git push` false rule still prompt?Not by default. In Local sessions, commands that run inside the sandbox are auto-approved because `chat.agent.sandbox.allowAutoApprove` defaults to `true`; set it to `false` to restore the normal approval flow. The push would also reach the network, because `chat.agent.sandbox.allowNetwork` defaults to `true`.
- How do you make Copilot's agent unable to run a command at all, rather than asking first?An auto-approve rule cannot do it, because `false` only requires approval. In the Local harness, add a `PreToolUse` hook (Preview) that returns `permissionDecision: "deny"` for the command. Hooks need `chat.useHooks` and a trusted workspace.
- When would you use `matchCommandLine: true` instead of a plain regex key?When the rule must judge the full command line rather than each subcommand — for example a pattern that only makes sense with its pipes or arguments together. Write the rule in object syntax and set `matchCommandLine` to `true`; without it, VS Code splits the command and evaluates every subcommand separately.
- A false rule in chat.tools.terminal.autoApprove blocks the command from running.
- A true rule for npm test also approves whatever is chained after it with &&.
- Terminal auto-approval is a reliable security boundary against prompt injection.
- Your own rules replace the built-in rules such as rm: false.
- A false rule still forces a prompt when the session is set to Allow all.