Files
dev/docs/execpolicy.md
T
zeekay 434ac17f31 Remove code-rs/, rebrand all references to hanzo-dev/
- Delete entire code-rs/ directory (1796 files) — just-every/code fork
  is no longer needed; hanzo-dev/ is the canonical Rust workspace
- Update all build scripts, CI workflows, docs, and configs to
  reference hanzo-dev/ instead of code-rs/
- Update binary name references: code → dev throughout
- Fix hanzo-cli/index.js, hanzo.sh, README.md, dev-cli READMEs
- Include pre-existing TUI improvements (theme, colors, greeting,
  card styles, chatwidget refactor) and build-fast.sh enhancements
  (symlink install, smarter crate prefix detection)
- codex-rs/ (read-only upstream mirror) is untouched
2026-02-10 16:14:50 -08:00

2.9 KiB

Execution policy

Every Code can enforce your own rules-based execution policy before it runs shell commands. Policies live in Starlark .codexpolicy files under ~/.code/policy (Code still reads ~/.codex/policy for backward compatibility).

How to create and edit rules

TUI interactions

Codex CLI will present the option to whitelist commands when a command causes a prompt.

Screenshot 2025-12-04 at 9 23 54 AM

Whitelisted commands will no longer require your permission to run in current and subsequent sessions.

Under the hood, when you approve and whitelist a command, codex will edit ~/.codex/rules/default.rules.

Editing .rules files

  1. Create a policy directory: mkdir -p ~/.code/policy.
  2. Add one or more .codexpolicy files in that folder. Code automatically loads every .codexpolicy file in there on startup.
  3. Write prefix_rule entries to describe the commands you want to allow, prompt, or block:
prefix_rule(
    pattern = ["git", ["push", "fetch"]],
    decision = "prompt",  # allow | prompt | forbidden
    match = [["git", "push", "origin", "main"]],  # examples that must match
    not_match = [["git", "status"]],              # examples that must not match
)
  • pattern is a list of shell tokens, evaluated from left to right; wrap tokens in a nested list to express alternatives (for example, match both push and fetch).
  • decision sets the severity; Code picks the strictest decision when multiple rules match (forbidden > prompt > allow).
  • match and not_match act as optional unit tests. Code validates them when it loads your policy, so you get feedback if an example has unexpected behavior.

In this example rule, if Code wants to run commands with the prefix git push or git fetch, it will first ask for user approval.

Preview decisions

Use the code execpolicy check subcommand to preview decisions before you save a rule (see the codex-execpolicy README for syntax details):

code execpolicy check --policy ~/.code/policy/default.codexpolicy git push origin main

Pass multiple --policy flags to test how several files combine, and use --pretty for formatted JSON output. See the hanzo-dev/execpolicy README for a more detailed walkthrough of the available syntax.

Example output when a rule matches:

{
  "matchedRules": [
    {
      "prefixRuleMatch": {
        "matchedPrefix": ["git", "push"],
        "decision": "prompt"
      }
    }
  ],
  "decision": "prompt"
}

When no rules match, matchedRules is an empty array and decision is omitted.

{
  "matchedRules": []
}

Status

execpolicy commands are still in preview. The API may have breaking changes in the future.