Sub topic 9
Permissions and approval modes
This chapter assumes you can run a shell, read JSON and TOML, and know what the agent loop and built-in tools are from earlier chapters. It covers how Claude Code, Codex CLI, and Copilot CLI decide whether a tool call runs without asking you, and how to set those rules to match the risk of a task.
Why permissions exist
An agent can edit files and run shell commands. Each of those calls can change your machine, so every tool places a gate between the model's request and its execution. The gate has three possible outcomes:
- Allow: the call runs without asking.
- Ask: the tool pauses and shows you the call. You approve or reject it.
- Deny: the call is blocked, and the model sees a refusal as its observation.
Your job is to move routine, low-risk calls to "allow", keep risky calls at "ask", and put calls that should never happen at "deny".
Read-only versus side-effecting calls
The tools separate calls by what they can change.
- Reading files and searching are usually allowed by default, within the project directory.
- Editing files changes your working tree. Most tools ask the first time, and let you approve edits for the rest of the session.
- Running shell commands is the riskiest category, because a command can do anything your user account can do. These ask by default unless a rule or mode says otherwise.
Reads are not harmless in every case. A read of .env puts secrets into the model's context, and from there they can be sent to the model provider. That is why the examples below deny reads of sensitive files.
Claude Code: permission rules and modes
Claude Code uses rules in .claude/settings.json. Each rule names a tool and an optional pattern in parentheses. Rules are grouped into allow, ask, and deny lists.
{
"permissions": {
"allow": [
"Bash(npm run test:*)"
],
"deny": [
"Read(./.env)"
]
}
}This file lets the agent run any command starting with npm run test without asking. It also blocks reads of ./.env. Deny rules take priority over allow rules, so a broad allow cannot reopen something you denied.
Claude Code also has permission modes that change the default behavior for a whole session. Typical modes include:
- default: ask the first time each kind of action is needed.
- acceptEdits: file edits are approved automatically, and commands still ask.
- plan: the agent may read and propose a plan but not change anything.
- bypassPermissions: no prompts at all. Use this only in a disposable environment such as a container.
Mode names and the way you switch between them (a keyboard shortcut during a session, or a command-line flag) can change between versions. Check /help or the current documentation for your installed version.
Codex CLI: approval policy plus sandbox
Codex CLI splits the problem into two independent settings. The approval policy decides when to ask you. The sandbox mode decides what the process can physically do, whatever you approve.
# ~/.codex/config.toml
approval_policy = "on-request"
sandbox_mode = "workspace-write"With this configuration, the agent works inside the workspace and can write files there. It asks when it wants something outside that boundary, such as network access or a write elsewhere on disk. Common values you will meet:
| Setting | Value | Meaning |
|---|---|---|
| `approval_policy` | `untrusted` | Ask before running anything except a small set of known-safe read commands |
| `approval_policy` | `on-request` | The model decides when to ask for permission to go beyond the sandbox |
| `approval_policy` | `never` | Never ask. Failures go back to the model |
| `sandbox_mode` | `read-only` | The agent can read but not write |
| `sandbox_mode` | `workspace-write` | Writes allowed in the project directory |
| `sandbox_mode` | `danger-full-access` | No filesystem restriction |
The next chapter covers sandboxing in detail. For now, note the design difference: in Codex, a sandbox limits damage even when approvals are off, while in a rule-based system, the rules are the main control.
Copilot CLI: trusted directories and tool approval
Copilot CLI asks you to confirm that you trust the directory you start it in, because the agent can read and run code from there. When it wants to run a tool, it asks, and you can approve once or approve for the session. Flags exist to pre-approve or deny specific tools, and a flag exists to allow all tools without prompting. The exact flag names have changed across releases, so run copilot --help to see what your version supports.
Comparing the three approaches
| Question | Claude Code | Codex CLI | Copilot CLI |
|---|---|---|---|
| Main control | Allow, ask, and deny rules by tool and pattern | Approval policy plus sandbox mode | Trusted directory, per-tool approval, flags |
| Where configured | `.claude/settings.json` | `~/.codex/config.toml` | Startup flags and its config |
| Block a specific file read | Deny rule | Sandbox and instructions | Tool deny flags |
| Skip all prompts | A bypass mode | `never` with a sandbox | An allow-all flag |
Choosing settings for a task
Match the settings to the blast radius of the task, meaning how much damage a wrong action could do.
- Exploring an unfamiliar repository: use read-only or plan mode. Nothing can change.
- Fixing a bug on a branch with tests: allow edits and your test command. Keep other shell commands at "ask".
- A long, unattended refactor: use a sandbox or container, a clean git branch, and a narrow allow list. Approval prompts cannot protect you when nobody is watching.
- Anything touching credentials, production, or deployment: leave prompts on, and deny access to secrets.
Common mistakes
- Allowing a wide pattern such as
Bash(*). It turns the allow list into "everything", and a single injected instruction can then run any command. - Allowing commands that can run other commands. A rule for
npm run test:*is only as safe as the scripts inpackage.json, because a changed script runs with your approval. - Approving prompts without reading them. After many routine prompts, people click through. Pre-approve the routine calls so the remaining prompts are rare and worth reading.
- Treating prompts as the only defense. Pair them with a branch, a sandbox, and deny rules for secrets.
- Putting personal, permissive settings in a file that is committed. Project settings are shared with your team, so keep local overrides in a file that is not checked in.
Exercise
You want Claude Code to run your tests and lint without asking, but never read .env, and you want other shell commands to still prompt. Which rule groups do you use, and what do you put in each?
Show answer
Put Bash(npm run test:*) and Bash(npm run lint) in allow, and Read(./.env) in deny. Leave everything else out of both lists, so other shell commands fall back to the default behavior of asking. Deny wins over allow, so the .env read stays blocked.
Exercise
A teammate sets Codex CLI to approval_policy = "never" and sandbox_mode = "danger-full-access" for an overnight run on their laptop. What is the risk, and what would you change?
Show answer
With no approvals and no filesystem restriction, any command the model runs, including one triggered by prompt injection in a file or web page, executes with the user's full access. Change the sandbox to workspace-write, run on a clean git branch, and preferably run inside a container with no real credentials.