Sub topic 6
Approving tool calls and terminal commands
Agent mode edits files and runs commands on your machine. Tool approval is the checkpoint between what the model proposes and what actually happens. This chapter covers what the approval prompts mean, how to scope them, and how to loosen them without giving up control.
This chapter assumes you can edit and run projects in VS Code, read a Git diff, and run build or test commands in a terminal. It also assumes you have used the agent loop (plan, call a tool, observe the result, repeat) from earlier chapters. Menu labels and setting names below follow recent VS Code with GitHub Copilot. They change between releases, so check them against your version.
Why approval exists
The model never touches your system directly. It emits a request such as "run this command" or "edit this file". The editor decides whether to carry it out. Approval is how you stay in that decision.
Tool calls fall into three risk groups:
| Group | Examples | Typical default |
|---|---|---|
| Read-only | Searching the workspace, reading a file, listing a directory | Runs without a prompt |
| Workspace edits | Creating or changing files inside the workspace | Applied, shown as a reviewable diff |
| Side-effecting | Terminal commands, MCP tools, fetching web pages, edits outside the workspace | Asks for confirmation |
Reading is cheap to undo because nothing changes. Editing is recoverable through version control. A terminal command can delete data, send network requests, or change state outside the repository. That is why commands get the strictest default.
A denial is not an error. The model receives the refusal as an observation, so it may try a different approach. Read what it tries next, because a rejected command is sometimes replaced by an equivalent one.
Reading a confirmation prompt
A terminal confirmation shows the exact command line, usually in a collapsible card with a short description of the model's intent. Check three things before you click:
- The command itself. Read the whole line, not only the first word. Chained commands (
&&,;,|) run several programs under one approval. - The working directory. A command that is safe in the project folder may not be safe elsewhere.
- The side effects. Writes, deletes, installs, network calls, and anything that touches credentials deserve a pause.
The description the model writes is a claim, not a guarantee. Trust the command text, not the summary.
Approval scopes
The confirmation button usually offers more than a single yes. In VS Code the options include allowing the call once, allowing it for the current session, allowing it for the current workspace, and always allowing it. The exact labels vary by tool and version.
| Scope | Lasts for | Use when |
|---|---|---|
| Once | This single call | You are unsure, or the command is unusual |
| Session | Until you close or reset the chat session | A routine command repeats during one task |
| Workspace | Every session in this folder | The command is part of the project's normal workflow |
| Always | Every workspace you open | Almost never, except for tools with no side effects |
A good rule is to choose the narrowest scope that stops the repeated prompts. Approving npm test for the workspace is reasonable. Approving a general shell for all workspaces is not.
Terminal auto-approval rules
Prompting for every git status wears you down, and tired reviewers click through prompts without reading them. Instead of approving everything, define precisely what is safe. VS Code lets you do this with the chat.tools.terminal.autoApprove setting. Each key is a command (or a regular expression written between slashes), and each value says whether to approve it automatically.
{
"chat.tools.terminal.autoApprove": {
"npm test": true,
"npm run lint": true,
"git status": true,
"git diff": true,
"/^git log\\b/": true,
"rm": false,
"git push": false,
"/^curl\\b/": false
}
}With this configuration:
npm test,npm run lint,git status, andgit diffrun without a prompt.- Any command starting with
git logruns without a prompt. The regular expression anchors the match at the start of the command. rm,git push, and anycurlcommand always ask. Afalsevalue forces a prompt even if another rule would allow the command.
Put these rules in workspace settings (.vscode/settings.json) when they describe the project, and in user settings when they describe your habits. Workspace settings can be committed, so teammates get the same rules. Review those files after pulling from a repository you do not control, since a settings file can widen what runs without a prompt.
Matching pitfalls
Pattern matching on command text is a convenience, not a security boundary. Keep these failure modes in mind:
- Allow a program, allow its arguments. Approving
npm runin general approves any script inpackage.json, including ones the agent just edited. Prefer the specific script names. - Chains and substitutions. Editors try to split a chained command and check each part. Shell features such as subshells,
eval, andbash -c "..."can hide the real command inside a string. Do not allow-list shells, interpreters, oreval. - Programs that run other programs.
find -exec,xargs,make, andgitaliases or hooks can all start further commands. A permitted program is only as safe as what it can launch. - Scripts the agent can edit. If the agent can change
scripts/test.shandscripts/test.shis auto-approved, the approval no longer means what you think. Review edits to anything on the allow list.
Edit approvals
File edits have their own controls. By default, edits to workspace files are applied and left pending until you keep or undo them, which the reviewing chapter covers in detail. Some files are treated as sensitive, for example files outside the workspace and configuration files such as .vscode/settings.json, and may require confirmation before the edit is written. This matters because editing .vscode/settings.json is one way an agent could change its own approval rules. Read any prompt that targets a settings or tasks file with extra care.
Auto-approving everything
VS Code has a setting that approves all tool calls without asking, often called YOLO mode (chat.tools.global.autoApprove). Enabling it turns the agent into a process that runs whatever the model decides, including commands influenced by text in files, web pages, and tool output. If a README or an issue comment contains injected instructions, nothing stands between that text and your shell.
A reasonable middle path combines these habits:
- Allow-list read-only and test commands, and deny-list deletes, pushes, and network downloads.
- Run risky or long tasks in a dev container or on a separate branch.
- Commit before a task so any change can be reverted.
- Keep secrets out of the environment the terminal inherits.
MCP and other tool prompts
Tools provided by MCP servers go through the same approval flow, but each tool is judged separately. A server may expose a read-only search tool and a destructive delete_record tool. Approve them individually. When a server first starts, check its command and arguments before trusting it, since starting it runs a local program. Tool descriptions are supplied by the server, so a malicious server can word them to encourage approval.
Workflow for a long task
- Commit or stash your current work.
- Describe the task with a verification command, such as
npm test. - Approve that verification command for the session so the loop can check itself.
- Read each new kind of command the first time it appears. Approve repeats at the session scope.
- Deny anything you cannot explain, and ask the agent why it wanted it.
- When the task ends, remove any session-wide or workspace-wide rules that were only needed for it.
Exercise
A teammate adds "npm run": true to the terminal auto-approve rules because the agent kept asking about test runs. Name two problems with this, and propose a better rule set.
Show answer
The rule approves every script in package.json, including scripts that deploy, delete files, or publish packages. It also covers scripts the agent has just edited, so the approval no longer matches what actually runs. A better set allows only the specific scripts needed, such as "npm run test" and "npm run lint", and sets destructive or publishing scripts, such as "npm run deploy" and "npm publish", to false so they always prompt.
Exercise
The agent proposes bash -c "cd build && rm -rf ./*" and you have "bash": true in your allow list. What happens, and what should you change?
Show answer
The command runs without a prompt, because the allow rule matches the program bash and the dangerous part is hidden inside a quoted string. Remove "bash" from the allow list, since shells and interpreters should never be auto-approved, and add a deny rule for "rm" so deletions always ask.