Skip to content

Self-protection and the policy lock

The agent cannot edit the policy or a hook, approve its own blocked call, read the audit log or switch OpenMoat off. A pinned file changed behind OpenMoat's back blocks every call until you look.

Try it

openmoat policy check "openmoat allow --last"
✕ deny
   rules : kernel-self
   reason: OpenMoat protects its own policy, hooks and binary: shell "openmoat allow --last"

A real run with the default policy: the same call from an agent is denied. You run openmoat allow in your own terminal.

Change it

Self-protection has no switch. After a change of your own, openmoat doctor shows what changed and openmoat doctor --accept pins it again.

What it does not stop

The lock is a list of digests, with no key: a program that runs as you outside any sandbox can change the policy and write new digests. All its limits

Protects against an agent, or a prompt injection steering it, turning OpenMoat off or loosening it: editing the policy or a hook, approving its own blocked call, reading the audit log, stopping the proxy.

  • kernel-self (deny). The agent may not write ~/.moat, any .moat/ folder, the agents’ hook and settings files, or the openmoat binary, and may not read OpenMoat’s state beside the policy: audit.db, policy.lock, hosts.json, approvals.json, trust.json, allowed_signers, mcp/, and from 0.12.0 proxy.key (the key openmoat proxy checks session credentials with) and proxy-ca/ (the proxy CA’s key and certificate). ~/.moat/policy.yaml stays readable, so the agent can explain a deny. The commands that change what agents may do are denied to it too, by either name (openmoat, moat), by absolute path, through a link, and under terminal wrappers (script, expect, unbuffer, tmux, screen, osascript, Python’s pty.spawn). From 0.12.0 the read-only forms are allowed (openmoat-readonly): openmoat --help, --version, <command> --help, policy lint FILE, policy check … and demo read no state and change nothing, so an agent may run them to explain a verdict.
  • Editors count as writes (from 0.15.0). vi, vim, nvim, nano, emacs and code save the file they open, so vim /usr/local/bin/openmoat and nano ~/.moat/policy.yaml are denied by kernel-self as writing them is.
  • The hook’s own entry points (from 0.15.0). Only a host runs openmoat guard and openmoat mcp proxy, so an agent running them from its own shell tool is denied (kernel-self): it cannot write audit rows, MCP tickets or a session’s proxy credential for calls it made up. --help still works.
  • The agents’ own hook places. kernel-self also covers the Cline CLI’s hook and plugin directories (and ~/Documents/Cline/Hooks) and goose’s configuration, its plugin settings and every .agents/plugins directory, so an agent cannot add, change or remove a hook there.
  • The agents’ system-wide settings (managed-settings, deny, from 0.17.0). Claude Code’s managed settings folder, Gemini CLI’s system settings and Codex’s /etc/codex outrank your settings and can turn every hook off, so an agent’s write there is denied (Code that runs later).
  • The provenance record (from 0.16.0). An agent’s openmoat provenance --write-notes is denied (kernel-self), and its git notes on the openmoat ref and git update-ref of refs/notes/openmoat need review (provenance-notes) (Provenance).
  • The state directory’s access list on Windows (from 0.21.0). openmoat init gives the state directory an access list of your account and SYSTEM only (inheritance off, every other entry removed) and refuses a state directory another account owns; openmoat doctor reads back which account owns it and its access list and names any other account that may change or read it. This keeps other accounts out, not the agent, which runs as you: kernel-self keeps the agent out.
  • Person-only commands. Those commands also refuse to run when an agent started them, even through a terminal wrapper, and read your answer from the terminal itself, not from their input.
  • The policy lock (kernel-integrity). openmoat init records the SHA-256 of the policy, every hook file it installed and the agents’ settings in ~/.moat/policy.lock. Every call checks them; a pinned file changed, removed or replaced by a symlink without a person accepting it (drift) denies every call until you re-pin. openmoat edit, openmoat allow and openmoat trust re-pin after their own change. From 0.15.0, openmoat allow --last and openmoat policy upgrade (and --undo) refuse to re-pin when a pinned file or the lock changed while they waited for your answer, so a change made meanwhile is never pinned unseen.
  • Pinned programs (executables). openmoat init records where common programs (git, npm, node, python3, cargo, curl, ssh, sudo, …) resolve. A command whose program now resolves elsewhere (a git planted in node_modules/.bin) is denied.
  • It fails closed. If its own check errors or hangs, OpenMoat blocks the call (kernel-error, or no decision within 30 s), in the format of the event it was given (a ConfigChange is blocked as one).
The agent runs Verdict Rule
openmoat allow --last deny kernel-self
cat ~/.moat/audit.db, sqlite3 -readonly ~/.moat/audit.db deny kernel-self
echo x >> ~/.moat/policy.yaml, nano ~/.moat/policy.yaml deny kernel-self
openmoat guard --host claude-code, openmoat mcp proxy … deny kernel-self
cat ~/.moat/proxy.key, cat ~/.moat/proxy-ca/ca.key deny kernel-self
systemctl --user stop moat-proxy deny kernel-self
pkill -f 'openmoat proxy', killall moat review stops-openmoat
pkill -f my-server.js no review: the pattern cannot match openmoat or moat
openmoat --help, openmoat policy check 'rm -rf ~' allow openmoat-readonly

When anything edits a pinned file behind OpenMoat’s back, every call gets:

Terminal window
moat: deny [kernel-integrity] — /Users/you/.moat/policy.yaml was modified;
run `openmoat doctor` to inspect; `openmoat doctor --accept` or `openmoat init` to re-pin

openmoat doctor lists what drifted. If it was not you, you caught what this exists for: look before you accept.

A person-only command started by an agent refuses before it does anything:

Terminal window
moat: `openmoat allow` must be run by a person, not by an agent: it was started from `<agent>`. Run it in a terminal of your own

Some agents load project settings at start that can turn every hook off, OpenMoat’s included (Claude Code’s disableAllHooks, and similar settings in GitHub Copilot CLI, Gemini CLI, OpenCode, goose, pi, Codex and Antigravity CLI).

  • openmoat run refuses to start an agent whose project files, from the working folder up to the project root, would turn its hook off. It names the file and the fix, and writes an audit row. A file it cannot read counts as turning the hook off.
  • Claude Code is started with --settings '{"disableAllHooks":false}' whenever OpenMoat’s hook is installed, so its hooks stay on for the whole session, through reloads and /cd. When your own user settings turn hooks off, the run says so and leaves them off.
  • Your own policy can choose sandbox.project_hook_off: start to start anyway; that needs an intact policy lock, writes an audit row, and a repository policy cannot set it.

Hooks a project cannot turn off: openmoat init --managed

Section titled “Hooks a project cannot turn off: openmoat init --managed”

openmoat init --managed writes OpenMoat’s hook where an agent reads an administrator’s hooks: Claude Code’s managed settings, Cursor’s enterprise hooks.json and GitHub Copilot CLI’s policy.d. There a project cannot turn it off. It needs a person at a terminal and never edits an administrator’s own file. Where root is needed, it keeps the file in ~/.moat/managed/ and prints a command that checks the file’s SHA-256 before installing it. openmoat doctor reports it, and openmoat uninstall removes it.

Command What it does Example
openmoat Shows a changed pinned file first, with Accept these changes? [y/N] openmoat
openmoat doctor What drifted, and every other check of the installation openmoat doctor
openmoat doctor --accept Accept the current files and re-pin. Terminal only openmoat doctor --accept
openmoat init Re-pin, keeping the hook files already in the lock openmoat init
openmoat status Each agent’s protection level, and pinned files that changed openmoat status --format json

Commands that only a person in a terminal may run (refused without a terminal, refused when an agent started them, and denied to agents by kernel-self): openmoat (its questions), openmoat init over an existing lock, uninstall, allow, edit, secret add, trust, doctor --accept, doctor --bundle, sandbox sync, policy upgrade (except --dry-run), policy install, policy trust-key, policy remove, mcp accept, mcp wrap, mcp unwrap, audit anchor, proxy ca init, proxy install and proxy uninstall. The full list: Commands.

Self-protection has no switch. executables: adds pins of your own (Shell command checks). After installing a tool in a new place, run openmoat init or openmoat doctor --accept so the snapshot follows it.

  • The lock is a list of digests, with no key. A program that runs as you outside any sandbox can change the policy and write new digests. Only an OS sandbox stops that, so hook-only agents (OpenClaw, GitHub Copilot CLI, pi, Gemini CLI, OpenCode, Hermes Agent, the Cline CLI, goose, and Claude Code and Cursor on native Windows) do not have this protection.
  • Agent settings can turn hooks off (disableAllHooks, [features] hooks = false, pi’s --no-extensions), and a repository’s .claude/settings.json is loaded at session start, before any hook runs (Keep Claude Code’s hooks on for everyone).
  • Some agents run a call when the hook fails: Claude Code before 2.1.295, if openmoat is missing or crashes. Since 0.26.0 Codex, Gemini CLI, Qwen Code and Crush block it then, and run it only when the hook times out.

Since 0.26.0:

  • Fail-safe hook commands. For Codex, Gemini CLI, Qwen Code and Crush, the hook entry openmoat init writes turns a missing or killed openmoat into the agent’s block answer; run openmoat init once after the upgrade.
  • Other hooks the agents run (plugin hooks, helper commands, a project’s hook files, .git/config programs) are recorded in the lock; a new or changed one is named until you run openmoat hooks accept, and one whose command your policy denies denies the agent’s calls (Other hooks the agents run).
  • A root user or a replaced openmoat binary is out of scope.

What the lock is not. More in Limits.