AgentKit
DocsKitsCLI ReferenceDesktop App
BetaYou are reading docs for the beta channel (3.0.0-beta.15). Features may change before the next stable release.Switch to stable →

policy

ak policy check

Ask the project policy what it says about writing one path, running one command, or landing one diff.

Use ak policy check to ask the project's policy about one operation before an agent or a script performs it. The answer carries an outcome, a one-sentence explanation, and every rule that matched, with where each rule came from. A hook or CI job can act on the exit code alone.

Usage

ak policy check [flags] [-- command args...]

Describe the operation with flags, and put a command's argv after --. The argv is taken literally; a command rule matches on the base name of its first element.

Command flags

FlagDefaultDescription
--dir <path>.Project directory holding .agentkit/policy.yaml.
--path <path>EmptyFile path an edit would touch. Checked against protected_path rules.
--changed <path>NoneChanged path in the diff being landed. Repeatable. Checked against required_check and diff_class rules.
--ran <check>NoneA check you have already run, so a matching required check counts as satisfied. Repeatable.
--no-bypassfalseIgnore AGENTKIT_POLICY_BYPASS, so a rule that would have fired is reported as firing.

Shared flags are described in CLI conventions.

Ask one question per call. If rules about different operations match the same request and disagree, the engine refuses to answer rather than ranking them.

Common examples

Check a file write

ak policy check --path internal/gen/api.pb.go

Check a command

ak policy check -- npm install

If a rewrite rule matches, the output quotes the command the rule asks for instead, such as pnpm install. The command is not run for you.

Check a diff before landing it

ak policy check --changed docs/a.md --changed README.md --ran lint --json

The result lists the checks the diff requires, whether each was reported with --ran, and the checks its diff class may skip. A required check you did not report turns the outcome into warn, or block when its rule's action is block.

Outcomes

OutcomeMeaningExit
allowNo rule objected, or a bypass waived the rules that did.0
warnA rule objected but does not stop the operation.0
rewriteA rule names a different program to run.0
blockA rule says the operation must not happen.3
errorThe engine refused to answer: the document conflicts, or the matching rules disagree.4

A compiled rule whose source instruction has changed still enforces; its match reports the drift.

Setting AGENTKIT_POLICY_BYPASS to 1 or true turns block, warn, and rewrite into allow, sets bypassed to true, and lists the waived rules in suppressed. It never changes an error. Use --no-bypass in CI to prove a rule would have fired.

Automation output

kind is policy.check. The data payload contains document and a decision with these fields:

FieldDescription
outcomeallow, warn, rewrite, block, or error.
reasonno_matching_rule, matched_rule, document_conflict, ambiguous_match, or bypassed.
explanationOne sentence stating the cause.
matchesMatched rules: rule, kind, action, reason, matched, origin, source, stale, and stale_reason.
rewriteThe replacement command, when the outcome is rewrite.
required_checksChecks the diff requires: check, rule, action, and satisfied.
skippable_checksChecks the diff may skip: check and rule.
conflictsConflicting rule pairs, when the document did not load.
bypassedtrue when AGENTKIT_POLICY_BYPASS waived the decision.
suppressedThe rules a bypass waived.

The payload is written even when the command exits 3 or 4.

Exit behavior

ExitMeaningWhat to do
0The outcome is allow, warn, or rewrite.Show any warning or proposed rewrite to the user.
1The policy document is missing or unreadable.Run ak policy compile and ak policy adopt, or fix the file.
2Arguments were invalid.Correct the invocation.
3A rule blocks this operation.Do not perform the operation; read the explanation.
4The engine refused to answer.Run ak policy validate and resolve the conflict.

Treat 4 as "the policy could not answer", not as a block or an allow.