The Codex CLI command supports setting the approval mode to control how much freedom the AI assistant has when making changes to files or running shell commands. This setting is crucial for balancing automation and security during interaction with the codebase.
There are three main approval modes available via the Codex CLI command:
1. Suggest Mode (default): This mode prioritizes safety and manual control. The AI will ask for your approval before creating, editing files, or running shell commands. It is ideal when you want maximum oversight, for example, when exploring unfamiliar code or reviewing changes carefully. The commands to enable this mode include using the `--approval-mode suggest` flag, or the short form `-a suggest`.
2. Auto Edit Mode: This mode automates file creation and edits without needing explicit approval for these actions, but it will still prompt you before executing any shell commands. This mode is well-suited for users who want to streamline coding and refactoring tasks while maintaining control over system-level commands. It can be set with `--approval-mode auto-edit` or `-a auto-edit`.
3. Full Auto Mode: This is the most autonomous mode. It allows the Codex CLI to create, edit files, and run shell commands automatically without needing any user confirmation. It is ideal for trusted workflows where you want maximum automation. The mode runs commands within a sandbox with no network access, ensuring some safety despite full automation. This can be set via `--approval-mode full-auto` or `-a full-auto`.
Usage Example for Setting Approval Mode:
bash
codex --approval-mode suggest "Analyze dataset.csv and generate report"
codex -a auto-edit "Refactor all utility functions"
codex --approval-mode full-auto "Fix build errors and run tests"
Details on each mode:
- Suggest Mode: Every action that changes files or executes shell commands requires your explicit yes/no confirmation. This is the safest and most controlled mode, designed to keep the user fully in the decision loop. It suits cautious environments or new users learning the tool.
- Auto Edit Mode: Automates all file writing activities, including creating and editing files, but before any shell command is run, it requests approval. This mode balances automation in coding tasks with caution on command execution which might affect the system or environment.
- Full Auto Mode: Grants Codex CLI full authority to carry out file edits and execute commands without user intervention. It runs in a sandboxed environmentâdisabling network access and restricting the working directoryâto mitigate risks. This mode maximizes productivity for trusted projects or repetitive tasks.
Changing Approval Mode interactively is also discussed in community feedback. When in suggest or auto-edit modes, users can switch to full-auto mode temporarily during approval prompts by choosing the mode switch option, allowing flexibility without cancelling the current operation.
Behind the scenes, the CLI sends the chosen mode via an approval flag (`--approval-mode` or shorthand `-a`) that guides its behavior in file manipulation and command execution.
Summary points:
- `--approval-mode` or `-a` flag sets the approval level.
- Modes are 'suggest', 'auto-edit', and 'full-auto'.
- Suggest asks approval at every step.
- Auto-edit auto approves file edits, but asks for shell commands.
- Full-auto auto approves everything in a sandboxed environment.
- Sandbox restricts network and limits directory access in full-auto.
- You can switch modes interactively during workflow approval prompts.
Common CLI usage example:
bash
codex --approval-mode suggest "Task description"
codex --approval-mode auto-edit "Another task"
codex --approval-mode full-auto "Automate everything"
Additional options related to approval beyond mode include:
- `--auto-edit` shortcut to auto approve file edits but not commands.
- `--full-auto` shortcut to auto approve edits and commands within sandbox.
- `--dangerously-auto-approve-everything` to skip all confirmations without sandboxing (not recommended).
In practice, setting approval mode allows tailoring Codex CLI's interaction level to fit user preferences for security, automation, or efficiency during various phases of development or automation tasks.
This balance of control and automation is especially important for coding agents like Codex to avoid unwanted changes or command execution while providing powerful AI-assisted development.