Skip to content
LinkedInX

Rules File Design - Declarative Command Permission Control

Target audience: Developers who need fine-grained control over commands Codex requests to run outside the sandbox
Prerequisites: Understanding of config.toml approval policies and sandboxing

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

AreaAGENTS.md.rules
PurposeExplain working policyEnforce command decisions
FormatMarkdownprefix_rule(...)
ExampleState that builds need approvalMark npm run build as prompt
This table scrolls horizontally. Keyboard users can focus the table and use the left and right arrow keys.

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

  1. OpenAI, Codex documentation
  2. OpenAI, OpenAI API documentation

For the latest releases and updates, check the official website and official documentation.

Quiz