Skip to content
LinkedInX

Rules File Design - Declarative Command Permission Control

About 5 minutes

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.

AreaAGENTS.md.rules
PurposeExplain working policyEnforce command decisions
FormatMarkdownprefix_rule(...)
ExampleState that builds need approvalMark npm run build as prompt

Rules are experimental, so confirm the current syntax before deployment.

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

Avoid broad rules such as allowing every git command. Prefer narrow prefixes such as git status and git diff.

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.

Quiz