Skip to content

The policy file

File What it is Who writes it
~/.moat/policy.yaml ($MOAT_HOME/policy.yaml) Your policy, for every agent and project openmoat init writes the default; you change it with openmoat edit
~/.moat/policy.d/approved.yaml The rules openmoat allow --always, --site and --dir added openmoat allow; openmoat allow --remove <id> takes one out
~/.moat/policy.d/packs/ Signed policy packs you installed openmoat policy install
<project>/.moat/policy.yaml A repository’s rules, committed with the code the repository’s maintainers (Team rules)
~/.moat/policy.lock The digests of the policy and the hook files OpenMoat (Self-protection)

The agent may read ~/.moat/policy.yaml, so it can explain a deny; it can change none of these. Your policy, the openmoat allow rules and installed packs decide together, in every project; a repository’s file adds to them in that repository only.

version: 1
deny:
- id: secrets-paths # stable id, shown to the agent and stored in the audit log
reason: secret material # prefixed to the explanation
fs.read: ["~/.ssh/**", "**/.env"]
fs.write: ["~/.ssh/**"]

A group lists patterns of one or more kinds, and matches when any of them matches:

Kind Matched against
shell the command’s words, and every pipeline suffix
fs.read, fs.write the absolute path, symlinks resolved
net the host name, lowercase (also matches fetches)
fetch the host of a URL a fetch tool reads (Claude Code WebFetch)
env.read, env.set the variable name
mcp the full MCP tool name, mcp__<server>__<tool>

Rule ids must be unique across the policy; unknown keys are errors.

How your policy and a repository’s combine

Section titled “How your policy and a repository’s combine”

A repository’s deny and review rules apply at once, as repo:<id>; its allow rules only after you run openmoat trust on that exact file, or when a key you trusted signed it. The details: Repository policies.

Terminal window
openmoat policy lint # the installed policy; or a file: openmoat policy lint ./policy.yaml
openmoat policy check "npm install left-pad" --policy ./policy.yaml --project ~/code/app
openmoat policy check "~/.aws/credentials" --kind fs-read --policy ./policy.yaml

openmoat policy lint prints ok: <file> (N deny, N allow, N review groups), with a warning: line for each rule that can never decide anything, such as a review pattern an allow already covers, and for the name ask: that policies used before 0.14.0 (it still loads; openmoat policy upgrade renames it, see The four verdicts). It fails (exit 64) on errors, for example:

Terminal window
duplicate rule id `push`
rule `push` has no patterns
bad shell pattern `git push "*` (unbalanced quotes?)
unsupported policy version 2: the policy is written for policy schema version 2, which a newer OpenMoat reads; this build reads schema version 1: upgrade OpenMoat

With --policy, only that file decides: not the openmoat allow rules, packs or a repository’s policy. Without it, openmoat policy check decides as the hook does.

Every policy starts with version: 1, the policy schema it is written in. OpenMoat reads that line first: a file for a newer schema says to upgrade OpenMoat, and a file without it says to add version: 1. Within a schema version, new keys are only ever optional, so a policy that loads today keeps loading.

Terminal window
openmoat policy migrate --dry-run # show what would change; writes nothing
openmoat policy migrate # show the diff, ask, then write it
openmoat policy migrate --file ./policy.yaml

openmoat policy migrate rewrites how a policy is written, never what it decides: it adds a missing version: and renames the old ask to review. It shows the diff, writes only when you run it yourself in a terminal (an agent’s call is denied), keeps the previous file as <file>.before-migrate, and re-pins the installed policy. New default rules come from openmoat policy upgrade instead.

OpenMoat publishes a JSON Schema for policy files. With the YAML extension in VS Code (or any editor that uses the YAML language server), it completes keys and marks a misspelt one as you type. Add this first line with openmoat edit (the installed policy is pinned, so a line written into the file any other way counts as a change OpenMoat did not make):

# yaml-language-server: $schema=https://raw.githubusercontent.com/crocodile-labs/openmoat/main/crates/openmoat-core/policies/policy-v1.schema.json

For a repository’s .moat/policy.yaml, use repo-policy-v1.schema.json from the same folder. openmoat policy lint stays the check that counts.

The full language and the default policy, rule by rule: POLICY.md.