Custom GPTs retire: Dec 11, 2026Date announced, hour not (as of Nov 7, 2026). FedRAMP workspaces keep them until Feb 11, 2027; move a GPT to a plugin before then.

17Days23Hours13Minutes18Seconds

How to Let Codex Run a Command Without Asking

To let Codex run one command outside its sandbox without asking you each time, add prefix_rule(pattern = ["npm", "test"], decision = "allow") to ~/.codex/rules/default.rules and restart Codex. The file, the three decisions, how Codex treats chained shell commands, and how to test a rule with codex execpolicy check, read in OpenAI's docs on Nov 17, 2026.

To let Codex run a command outside its sandbox without asking you every time, add this line to ~/.codex/rules/default.rules and restart Codex: prefix_rule(pattern = ["npm", "test"], decision = "allow") (Rules, OpenAI docs, read Nov 17, 2026). From then on any command that starts with npm test, such as npm test -- --watch=false, runs with no approval prompt, while everything else still asks. OpenAI calls rules "experimental and may change". When you add a command to the allow list from the CLI's approval prompt, Codex writes the same kind of rule into the same file for you.

Rules sit on top of the approval modes OpenAI showed in its Codex CLI demo of October 2025: read only, auto and full access, with auto the default, which lets Codex read and change files in the current project directory but nothing else on your computer. A command that needs to go beyond that is what a rule can let through.

The blunt alternative is to stop asking altogether. Guided Resolution's April 2026 video starts Codex with --full-auto (reading, writing and running local actions in the sandbox without prompts), or sets sandbox_mode = "danger-full-access" and approval_policy = "never" in config.toml, and warns that this is risky and only for an agent you trust. A rule is the narrow version: one command allowed, everything else still asks.

Next: the sandbox and approval presets these rules sit on top of, a hook that checks every command before it runs or where CODEX_HOME moves the rules folder.

Hands typing on a dark laptop with the OpenAI logo beside a cup of coffee, with the words Codex CLI Updates
Hands typing on a dark laptop with the OpenAI logo beside a cup of coffee, with the words Codex CLI Updates OpenAI

The rule, field by field

A rule is one call to prefix_rule() in a .rules file written in Starlark, a safe subset of Python syntax. A fuller version of the line above, ours, with the optional checks OpenAI's page describes:

prefix_rule(
    pattern = ["npm", "test"],
    decision = "allow",
    justification = "Running the test suite is safe",
    match = ["npm test", "npm test -- --watch=false"],
    not_match = ["npm install"],
)
Field Required What it does
pattern Yes The start of the command, one list item per argument; an item can itself be a list of alternatives, such as ["view", "list"]
decision No, default "allow" allow runs it without asking, prompt asks every time, forbidden blocks it without asking
justification No A reason Codex may show in the prompt or the refusal
match, not_match No Example commands Codex checks when it loads the file, so a wrong rule fails at start-up instead of later

The pattern is matched against the command's argument list as an exact prefix. OpenAI's own example shows the cost of that: a rule for gh pr view does not match gh pr --repo openai/codex view 7888, because the flag sits between the words.

Three rules worth copying

Each of these is ours, built from the fields above:

  • Allow read-only Git commands: prefix_rule(pattern = ["git", ["status", "diff", "log"]], decision = "allow"). One rule covers three commands, because the second item is a list of alternatives.
  • Ask before every push: prefix_rule(pattern = ["git", "push"], decision = "prompt").
  • Block a tool and say what to use instead: prefix_rule(pattern = ["grep"], decision = "forbidden", justification = "Use rg instead of grep."). OpenAI's page suggests naming the alternative in a forbidden rule's justification.

When several rules match one command, the strictest wins: forbidden beats prompt, and prompt beats allow.

Chained commands are checked one by one

A rule cannot be used to slip something past it. When Codex is asked to run a shell string such as bash -lc "git add . && rm -rf /", it splits a plain chain (words joined by &&, ||, ; or |) into its commands and checks each, so allowing git add does not allow the rm -rf / behind it. A script with redirection, $(...), variables, wildcards or control flow is not split: the whole bash -lc "<script>" call is checked as one command, and a prefix rule for one of its parts does not apply.

Test a rule before you trust it

Codex has a checker that prints the decision as JSON:

codex execpolicy check --pretty --rules ~/.codex/rules/default.rules -- npm test -- --watch=false

It reports the strictest decision and every rule that matched, with their justifications. Pass --rules more than once to combine files.

Where rule files are read from

  • ~/.codex/rules/ for you, on every project. Under a different CODEX_HOME, the folder moves with it.
  • <repo>/.codex/rules/ for one project, read only once you have trusted that project's .codex/ folder.
  • Team Config locations, and admin rules in requirements.toml, which can enforce restrictive rules you cannot override.

Codex reads them at start-up, which is why a new rule needs a restart. Rules apply to Codex on your computer: OpenAI's page warns that Work Cloud with local computer access does not read local rule files, and an admin sets its command rules in Agent Security instead. With Smart approvals on, the default, Codex may suggest a prefix_rule itself when it asks to leave the sandbox; OpenAI advises reviewing the suggested prefix before accepting it, since a short prefix such as ["npm"] allows every npm command.

We think a rule that allows a whole tool (["npm"], ["python"]) is the most common mistake here, because it allows that tool's install, publish and script commands too; allow the exact subcommand you mean.

Sources

Moments

Using OpenAI Codex CLI with GPT-5-Codex

OpenAI

  1. Rules sit on top of the approval modes OpenAI showed in its Codex CLI demo of October 2025: read only, auto and full…

How To Allow Or Approve All Permissions In Codex

Guided Resolution

  1. The blunt alternative is to stop asking altogether. Guided Resolution's April 2026 video starts Codex with --full-auto…

See also

About this page

Last updated Nov 22, 2026 by the Vi.ki team. Page text CC BY-SA 4.0.

Edit History

Hotkeys

/
Jump to the search box
? or Ctrl + /
Open this list
Esc
Close this list, the photo viewer, or the account menu

Video

Space or K
Play or pause
← →
Back or forward 5 seconds
J L
Back or forward 10 seconds
0 to 9
Go to 0% to 90% of the video
, .
Previous or next frame, while paused
M
Mute or unmute
C
Captions on or off
F
Full screen on or off
A D
Previous or next moment

Photo viewer

← → or A D
Previous or next photo
↑ ↓ or W S
Previous or next photo
Home End
First or last photo
I
Show or hide the photo's info
Z
Clickless on or off: a pointer over a thumbnail shows it
N
Compare with the last photo: back to the one shown before this, and N again comes back
Q
Move the thumbnails to the next edge: top, bottom, left and round
, or Ctrl + ,
Open or close the viewer's settings
V
Clickless pan: a zoomed photo follows the pointer, rather than being dragged
Shift
Browse on or off
B
Show or hide the button bar
T
Show or hide the thumbnails
1
100% zoom on or off
0
Rate the photo as no opinion; again takes the answer back
+ -
Rate the photo a step higher or lower
F
Full screen: the photo alone. F again puts everything back.
Back to top