codex-execpolicy
创建或编辑 Codex execpolicy .rules 文件(允许/提示/禁止命令,定义 prefix_rule 模式,添加匹配/不匹配测试)并使用 codex execpolicy check 进行验证。当用户提及 Codex 规则、execpolicy、命令策略、允许列表/拒绝列表,或控制 Codex 可以运行的命令时,以及需要明确作用域(全局 vs 项目)时使用。
📖 中文导读:创建或编辑 Codex execpolicy .rules 文件(允许/提示/禁止命令,定义 prefix_rule 模式,添加匹配/不匹配测试)并使用 codex execpolicy check 进行验证。当用户提及 Codex 规则、execpolicy、命令策略、允许列表/拒绝列表,或控制 Codex 可以运行的命令时,以及需要明确作用域(全局 vs 项目)时使用。 以下正文为该技能的原始 SKILL.md 内容(英文),上方安装命令可直接使用。
name: codex-execpolicy description: Create or edit Codex execpolicy .rules files (allow/prompt/forbid commands, define prefix_rule patterns, add match/not_match tests) and validate them with codex execpolicy check. Use when a user mentions Codex rules, execpolicy, command policies, allowlists/denylists, or controlling which commands Codex can run, and when scope (global vs project) must be clarified.
Codex Execpolicy
Overview
Define and maintain Codex execpolicy rules so the agent can allow, prompt, or forbid command prefixes, and validate the policy before use.
Workflow
Clarify scope and location.
- Ask: “Should this be a global rule or project-specific?”
- If global: default to
~/.codex/rules/default.rulesunless the user provides another path or uses a different Codex home. - If project-specific: ask for the exact file path; a common pattern is
.codex/rules/default.rulesat repo root. - If the file already exists, inspect it before editing.
Clarify intent.
- Ask for the decision:
allow,prompt, orforbidden. - Ask for the command prefix and any alternatives.
- Ask for at least one “should match” and “should not match” example if the rule is non-trivial.
- Ask for the decision:
Implement the rule.
- Use
prefix_rule(...)with a precisepatternlist. - Use union lists for alternatives when only one argument varies.
- Add
match/not_matchas inline tests when the rule is tricky.
- Use
Validate before finishing.
- Run
codex execpolicy check --pretty --rules <path> -- <command>using realistic examples. - If validation fails, adjust
patternor tests and re-check.
- Run
Summarize outcomes.
- State what command prefixes are allowed/prompted/blocked and where the rule lives.
Examples
Block all git commands:
prefix_rule(
pattern = ["git"],
decision = "forbidden",
)
Prompt for either gh pr view or gh pr list:
prefix_rule(
pattern = ["gh", "pr", ["view", "list"]],
decision = "prompt",
)
Resources
- See
references/execpolicy.mdfor syntax notes, decision precedence, and validation commands.