Check a pull request
openmoat policy check-diff and the GitHub Action check what a change does before it merges, with the same rules as the hook: CI and hook edits, agent settings, the policy, secret files, look-alike dependencies and new hosts, whoever wrote it.
When you need it
Try it
openmoat policy check-diff --base origin/mainreview .github/workflows/ci.yml [runs-later, session-taint]
CI, commit hooks, the editor or the agent host run this later, outside any sandbox: write .github/workflows/ci.yml
CI, a build or test tool, a commit hook or an AI agent runs or reads this file later
deny .claude/settings.json [kernel-self]
OpenMoat protects its own policy, hooks and binary: write .claude/settings.json
review package.json [session-taint]
CI, a build or test tool, a commit hook or an AI agent runs or reads this file later
deny: 1 deny, 2 review in 4 changed files (checked against the default policy)For a pull request that changes a workflow trigger, sets hooks in .claude/settings.json, adds a postinstall script and edits one source file (MERGE_CHECK.md in the openmoat repository).
Change it
In the Action, fail-on: review (the default), deny or never; policy: checks against a policy file in the repository, read as the pull request's base has it.
What it does not stop
It reads the text a change adds, offline: a payload built from pieces at run time, a script the change does not touch, and a package's age or owner are not checked. All its limits
Protects against a change that was never checked by OpenMoat’s hook reaching your main branch: one written by an agent on a machine without OpenMoat, by a person, or by a fork. The hook checks each call while an agent works; a pull request is the other place to check.
What it does
Section titled “What it does”openmoat policy check-diff reads a change and reports:
- every file it adds, edits, deletes or renames that the policy protects: CI workflows, git hooks and hook managers, build and package files (
package.json,Makefile,Cargo.toml,pyproject.toml, …), agent instructions, settings, hooks and MCP server lists (CLAUDE.md,.claude/,.mcp.json,.cursor/, …), OpenMoat’s own files (.moat/) and secret files (.env); - every added line that holds a known token format (GitHub, OpenAI and Anthropic, AWS access key ids, Slack, Google API, npm, GitLab), without printing the token;
- symbolic links and where they point, submodule changes, and paths that leave the repository;
- what the added lines do (content checks, since 0.16.0): a typo-squatted or off-registry dependency, an install script, a lockfile hash swapped for the same version, a CI workflow a pull request can take over, a script downloaded or decoded and run, a private key, and every new host the code connects to that your network allow list does not name;
- what provenance notes say agents wrote in the change.
Each file is decided by the policy’s own rules, as a write from untrusted content, so the lists of protected files are the ones the hook uses: the git hook folders core.hooksPath usually names, Cline’s workspace hooks and, from 0.17.0, all of .vscode/ and .idea/, .venv/bin/, .devcontainer/ and package-manager configuration that runs code, reported for review (Code that runs later).
It runs offline: nothing is looked up on the network, so the same change gives the same report everywhere.
| Level | Exit code | Means |
|---|---|---|
| deny | 2 | the policy denies an agent this write (kernel-self, secrets-paths), the change adds a token or a private key, a path leaves the repository, or a content check finds what should never be merged unnoticed (a swapped lockfile hash, a CI takeover, decoded code that runs) |
| review | 3 | a person should look before merging: a file that CI, a build, a commit hook or an agent runs or reads later, a link, a submodule, a policy file, or a content check’s review finding (a near-miss dependency, an unpinned action, a new host) |
| clean | 0 | nothing the policy protects |
| error | 64 | the change or a policy could not be read; never reported as clean |
Run it locally
Section titled “Run it locally”openmoat policy check-diff --base origin/main # this branch against mainopenmoat policy check-diff --base main --head feature --format jsongit diff main | openmoat policy check-diff # any unified diff on stdinopenmoat policy check-diff --base main --policy ci/openmoat.yamlWith --base, the change is everything from the commit --base and --head (default HEAD) share to --head, as a pull request shows it. Without --policy, the shipped default policy is used, not the one installed in ~/.moat, so every machine gives the same answer. That is unlike openmoat policy check, which decides with your installed policy.
Example
Section titled “Example”A pull request that changes a workflow trigger, sets hooks in .claude/settings.json, adds a postinstall script and edits one source file:
review .github/workflows/ci.yml [runs-later, session-taint] CI, commit hooks, the editor or the agent host run this later, outside any sandbox: write .github/workflows/ci.yml CI, a build or test tool, a commit hook or an AI agent runs or reads this file laterdeny .claude/settings.json [kernel-self] OpenMoat protects its own policy, hooks and binary: write .claude/settings.jsonreview package.json [session-taint] CI, a build or test tool, a commit hook or an AI agent runs or reads this file laterdeny: 1 deny, 2 review in 4 changed files (checked against the default policy)The source file is not listed: nothing the policy protects. --format json prints one document with result, files, policy, repository_policy and findings (each with level, path, line for an added line, rules and reasons).
Content checks
Section titled “Content checks”From 0.16.0 each added line is also read for what it does. Each finding names the file and the line, a stable rule id, a level and a short reason; a secret’s value is never printed.
review web/package.json:14 [diff-package-near-miss] adds the npm dependency `lodahs`, one typo or trick away from the popular `lodash`, as typo-squats and made-up names are; check which one is meantdeny package-lock.json:2041 [diff-lock-integrity] changes a package's integrity hash while its version stays: the next install accepts other code under the same version (…)deny .github/workflows/greet.yml:12 [diff-ci-injection] expands `${{ github.event.issue.title }}`, text a pull request's or issue's author writes, into a script, where it runs as code; pass it through `env:` and use the variable instead| Area | Rule id | Level |
|---|---|---|
| Supply chain | diff-package-near-miss: a dependency one typo away from a popular one |
review |
diff-install-script: package.json sets preinstall, install, postinstall or prepare |
review | |
diff-package-source: a dependency or locked package from git, a URL or another host than its registry |
review | |
diff-lock-integrity: a lockfile hash changed or removed while the version stays |
deny | |
| CI takeover | diff-ci-pr-target: pull_request_target with a checkout of the pull request’s code |
deny |
diff-ci-permissions: write permissions |
review | |
diff-ci-unpinned: uses: without a full commit SHA |
review | |
diff-ci-injection: an author’s text (an issue title, a branch name) expanded into a script |
deny | |
diff-ci-secret-out: ${{ secrets.* }} printed in a script |
deny | |
| Backdoors | diff-pipe-to-shell: curl … | sh and the like |
review |
diff-decode-exec: decoded text run as code |
deny (review in a test folder) | |
diff-python-startup: a .pth file with an import line |
deny (review in a test folder) | |
diff-docker-remote-add: a Dockerfile ADD of a URL without --checksum |
review | |
diff-encoded-blob: a long base64 blob in source code |
review | |
| Secrets | diff-private-key: a PEM or PuTTY private key |
deny (review in a test fixture or marked fake) |
diff-env-secret: a real-looking value in a .env file |
review | |
| Network | diff-new-host: one finding per new host your network allow list does not name |
review |
Setting the levels
Section titled “Setting the levels”Set any content rule to deny, review or off in the policy the check reads (--policy, or your own policy file):
version: 1check_diff: levels: diff-ci-unpinned: off # this repository pins actions by tag on purpose diff-new-host: deny # nothing may add an endpoint unnoticed diff-package-source: off # our packages come from a private registryopenmoat policy lint rejects a rule id that is not a content check and warns about each rule set to off. A repository’s .moat/policy.yaml cannot set levels: it only adds rules.
Provenance notes
Section titled “Provenance notes”When the change’s commits carry provenance notes on refs/notes/openmoat, the check adds a line per agent session:
review provenance: 2 files / 12 lines written by claude-code (session 3c9e1a7f02d4, after reading web content (fetch docs.example.com)) 1 of 3 commits have a note on refs/notes/openmoat; notes are claims from the machine that wrote them (`openmoat provenance --verify` there checks them), and a commit without one proves nothingThey never change the exit code or fail the check. --provenance info shows them as notices, --provenance off hides them; the Action’s provenance input does the same.
On GitHub
Section titled “On GitHub”The check is a GitHub Action, listed on GitHub Marketplace as OpenMoat merge check.
-
Add the workflow
Save this as
.github/workflows/openmoat.yml. Pin the action to the full commit SHA of an OpenMoat release tag, and setversionto that release:name: openmoaton:pull_request:permissions:contents: readjobs:merge-check:runs-on: ubuntu-24.04steps:- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1with:fetch-depth: 0 # the base and head commits and what they sharepersist-credentials: false- uses: crocodile-labs/openmoat@1dd88d81246a60ffa318f619375628128d5b7ece # v0.23.0with:version: 0.23.0 # the same release, without the leading vfail-on: review # review (default), deny or never# policy: ci/openmoat.yaml # read as the pull request's base has it -
Open a pull request
The action downloads that release for the runner (Linux or macOS, x64 or arm64), checks the archive’s sha256 against the release’s
sha256.sumand its build attestation withgh attestation verify, then runsopenmoat policy check-diffon the pull request’s base and head. -
Read the annotations
Every finding becomes an annotation on the pull request:
denyas an error,reviewas a warning. The step fails on whatfail-onnames; the outputresultisclean,reviewordeny. -
Hold merges on it, if you want
A finding is a report, not a block on merging. Make the job a required status check to hold merges until it passes, and merge past it when a person meant the change. A repository whose pull requests often change CI, hooks or policy can block on
denyalone (fail-on: deny) and leave reviews as warnings: OpenMoat’s own repository does (its workflow).fail-on: denyandneverwork from 0.23.0; before it, any finding failed the step.
| Input | Default | What it does |
|---|---|---|
version |
none (required) | the OpenMoat release to run |
fail-on |
review | fail the step on anything found (review), only on deny, or never |
policy |
the default policy | a policy file in the repository, read as the base has it |
base, head |
the pull request’s base and head commits | the revisions to compare |
provenance |
review | what provenance notes say the change’s agents wrote: warnings (review), notices (info) or nothing (off); never fails the step. The Action fetches refs/notes/openmoat from origin first; with persist-credentials: false that works only for a public repository |
token |
github.token |
what gh attestation verify reads the attestation with |
Use the pull_request event, not pull_request_target: the check needs no secrets, and pull_request_target runs with the base repository’s token while it reads code from the pull request. Under GitHub Actions, --format github (workflow annotations) is the default.
The change cannot loosen its own check
Section titled “The change cannot loosen its own check”With --base, the policy files are read as the base revision has them, with git, not from the checked-out files: a relative --policy path, and the repository’s .moat/policy.yaml, whose deny and review rules are added as the hook adds them for an untrusted repository. A change to either file is reported (diff-policy) and applies from the next change after it is merged. A diff on stdin has no base revision: --policy is read from disk and no repository policy is read.
Since 0.26.0, with --base, a change that makes .moat/policy.yaml (or the --policy file) decide any call less strictly than the base revision’s fails with diff-widens (deny; review for a setting whose direction is not ranked): one finding per call that moves toward allow, with the rules before and after. It is the same check as openmoat policy diff --widen (Does a change widen?).
Rule ids it adds
Section titled “Rule ids it adds”| Rule id | Level | When |
|---|---|---|
diff-secret |
deny | an added line holds a known token format |
diff-path |
deny | a path is absolute, leaves the repository (../) or is not a file name |
diff-policy |
review | the change edits a policy file the check read |
diff-link |
review | the change makes a symbolic link; where it points is checked too |
diff-submodule |
review | the change moves a submodule to another commit |
diff-unchecked |
review | the diff is larger than 64 MiB: its paths were checked, its added lines were not searched |
Paths are compared without letter case and as Windows opens them (trailing dots and spaces dropped, \ as /), . and .. are collapsed, and a renamed file is checked under both names; a deleted file is checked too.
Commands
Section titled “Commands”| Command | What it does | Example |
|---|---|---|
openmoat policy check-diff --base <rev> [--head <rev>] |
Check the change between two revisions | openmoat policy check-diff --base origin/main |
openmoat policy check-diff (diff on stdin) |
Check any unified diff | git diff main | openmoat policy check-diff |
--policy <file> |
Check against that policy instead of the shipped default | --policy ci/openmoat.yaml |
--format text|json|github |
Text, one JSON document, or workflow annotations | --format json |
--provenance review|info|off |
How provenance notes are shown (default review); never changes the exit code |
--provenance info |
Limits
Section titled “Limits”- It reads the text a change adds (and the lockfile lines it removes), offline, not a parse of each language: a payload built from pieces at run time, a script the change does not touch, and a package’s age or owner are not checked, and a benign line can match (set its level in
check_diff.levels). - A source file a build or a test runs is code like any other and is not flagged by path, nor is a script that a flagged file (
package.json) already named before the change. - Binary files are not searched for tokens; their paths are checked.
- Tokens are found by their vendor prefix, private keys by their PEM or PuTTY header, and passwords only as values of
.envfiles. Commit messages are not searched. - GitLab, CircleCI, Azure and Jenkins files get the path rules and the backdoor checks, not the GitHub workflow checks.
- A submodule’s code, and what a symbolic link points to outside the repository, are not read.
~/rules do not apply to repository paths, so a dotfiles repository is checked as an ordinary project. Windows short names (GITHUB~1) are not expanded.- The action runs on Linux and macOS runners.
The full reference: MERGE_CHECK.md. Checking what a repository’s own rules decide for one command in CI: A repository policy.