Sub topic 9
Permissions and approval modes
This chapter assumes you can start a session in Claude Code, Codex CLI, or Copilot CLI, and that you know the built-in tools from earlier chapters: file edits, shell commands, and search. Here you learn how each tool decides whether an action runs or waits for you.
Why approvals exist
An agent can edit files and run shell commands. A wrong command can delete work or leak a secret. Permissions put a checkpoint between the model's request and the action. The checkpoint can allow the action, ask you, or deny it.
Reading files is usually low risk, so most tools allow it without asking. Editing files and running commands carry more risk, so they ask by default.
Rules in Claude Code
Claude Code uses rules in .claude/settings.json. Each rule names a tool and an optional pattern. A rule is one of three kinds: allow, ask, or deny. Deny rules win over allow rules.
{
"permissions": {
"allow": [
"Bash(npm run test:*)"
],
"deny": [
"Read(./.env)"
]
}
}This file lets the agent run npm run test commands without asking. It also blocks reads of .env, so the agent cannot see your secrets. Everything not matched still prompts you.
Approval policy in Codex CLI
Codex CLI separates two questions. The approval policy decides when the agent must ask you. The sandbox mode decides what the agent can touch at all. The next chapter covers sandboxing in detail.
# ~/.codex/config.toml
approval_policy = "on-request"
sandbox_mode = "workspace-write"Here on-request lets the agent work inside the sandbox and ask when it needs to go beyond it. workspace-write limits writes to the project directory. Stricter policies ask before more actions. Looser ones ask rarely or never.
Copilot CLI
Copilot CLI also asks before it runs commands or changes files. You can approve a single action or allow a tool for the rest of the session. Check its in-session help for the current flags and options, because they change between releases.
Choosing a level
Match the level to the risk of the task.
| Task | Suggested setting |
|---|---|
| Explore an unfamiliar repository | Read-only, or ask for everything else |
| Fix a bug on a branch | Allow tests, ask for edits and other commands |
| Unattended script or CI job | Narrow allow list inside a sandbox |
Common errors
- Allowing a broad pattern such as every shell command. Prefer narrow rules like one test command.
- Approving prompts without reading them. A prompt is your only review of that action.
- Relying on deny rules alone. Pair them with a sandbox, because a shell command can reach a file by another route.
- Using a "skip all approvals" option outside a disposable environment.
Exercise
You want an agent to run your test suite freely but never read .env. In Claude Code, which settings go in allow and which in deny, and why should you also use a sandbox?
Show answer
Put the test command, for example Bash(npm run test:*), in allow and Read(./.env) in deny. Deny rules take priority over allow rules. A sandbox adds a second barrier, because a shell command could otherwise reach the file by another route.
Exercise
In Codex CLI, what is the difference between approval_policy and sandbox_mode?
Show answer
approval_policy controls when the agent must ask you before acting. sandbox_mode controls what the agent is technically able to read or write, whether or not you approve.