Rules File Design - Declarative Command Permission Control
Codex Rules classify commands requested outside the sandbox by command prefix. They turn guidance such as “production builds need approval” into an executable decision boundary.
Rules compared with AGENTS.md
| Area | AGENTS.md | .rules |
|---|---|---|
| Purpose | Explain working policy | Enforce command decisions |
| Format | Markdown | prefix_rule(...) |
| Example | State that builds need approval | Mark npm run build as prompt |
Rules are experimental, so confirm the current syntax before deployment.
Create a rule
Store user rules in ~/.codex/rules/default.rules or project rules in .codex/rules/*.rules for trusted projects.
prefix_rule(
pattern = ["npm", "run", "build"],
decision = "prompt",
justification = "Production builds require explicit approval",
match = ["npm run build"],
not_match = ["npm run dev"],
)pattern matches an argument prefix. match and not_match document examples that should or should not match.
- allow: low-impact, repeatable inspection commands
- prompt: external writes, publishing, dependencies, or broad network access
- forbidden: destructive actions or approval bypasses
Design Command Decisions
Avoid broad rules such as allowing every git command. Prefer narrow prefixes such as git status and git diff.
Policy in This Repository
This repository treats npm run dev and npm run harness:check as routine checks, while npm run build requires explicit approval. AGENTS.md explains that policy; Rules and approval settings reinforce it.
Rules cannot validate content quality or project structure. Hooks and CI handle those checks. Next, Commands and Workflows organizes reusable execution entry points.
Summary
Rules control command execution through narrow argument prefixes. Separate approval-gated and forbidden operations, and avoid permissions that are broader than the intended task.
See the references for the external specifications and background sources used on this page.[1][2]
This article is a general information summary and is not legal advice. Confirm practical decisions with a qualified specialist.
References
- OpenAI, Codex documentation
- OpenAI, OpenAI API documentation
For the latest releases and updates, check the official website and official documentation.