CLI reference
Exit codes, store health, the Claude Code hook, argv parsing, compound commands, dry runs, and
library usage for the aegis CLI.
← back to the README
Argv forms
Global options in front of the verb (kubectl -n prod delete …, git -C /repo push …,
helm --kube-context prod uninstall …), glued short flags (-nprod), label selectors
(-l role=worker) and comma-separated kinds (nodes,pods) all parse to the same intents as
their canonical forms; a leading option Aegis does not recognise is an error (exit 65), never a
guess at where the verb starts. kubectl’s short flags can also be bundled, so -itnprod is -i -t
-n prod and -Rf dir is -R -f dir. A bundle with an unknown letter in front of a flag Aegis
reads (-xnprod) is the same error, and kubectl refuses it too. helm, flux and argocd words are
read the same way, from the letters in their source. git’s options are read as git’s
parse-options reads them (-fu, an unambiguous prefix such as --amen, --no-force), aws
takes an unambiguous prefix of an option as argparse does (--reg is --region), and az reads
-nNAME and -ynNAME as argparse does. A prefix of an az option that names the target or its
scope (--resource-gr) is refused, since what it stands for depends on the command.
kubectl delete namespace prod
additionally emits a synthetic */* delete intent scoped to that namespace, so namespace-scoped
deletion rules fire on it.
Exit codes
The exit code is the worst verdict across all evaluated intents, or a tool error. Verdict codes
depend on --exit-style; tool errors are identical in every style and never print a verdict.
| exit code | --exit-style aegis (default) |
--exit-style claude-hook |
--exit-style ci |
|---|---|---|---|
0 |
ALLOW | ALLOW (prints nothing) | ALLOW |
1 |
— | — | ESCALATE or BLOCK |
2 |
ESCALATE | ESCALATE or BLOCK, printing {"decision": "block", "reason": "<verdict>: <citations>"} |
— |
3 |
BLOCK | — | — |
64 |
usage error (unknown flag, no argv after --, compound argv without --split-compound, a command string Aegis refuses to evaluate statically) |
same | same |
65 |
bad data: unparseable argv, --now, YAML or JSON; degraded store (see below); no signing key, or a missing/bad signature |
same | same |
66 |
a constraints/authority/environments/plan/key file does not exist or is unreadable | same | same |
70 |
internal error; the exception class name is on stderr | same | same |
Every error is one aegis: error: … line on stderr, never a traceback. claude-hook exists
because Claude Code PreToolUse hooks treat exit 2 as block and any other non-zero code as a
non-blocking error, which would invert the default 3 = BLOCK contract.
Store health
Every output carries the state of the constraint store, so a degraded store can never be
mistaken for a clean allow. Each per-intent JSON line and the plan summary include a
store_health object — loaded, quarantined: [{id, reason}], principals,
constraints_sha256 (of the raw file bytes), warnings — and --pretty ends with a
STORE: loaded=N quarantined=M principals=P line plus one line per quarantined rule, preceded
by one WARNING: … line per store warning (using example signing key, insecure: signatures
not verified, ledger: chain-broken, rate-limit key typos). Quarantines also go to stderr as
aegis: WARNING … lines.
An untrustworthy constraint gets no vote. A constraint that was quarantined at load
(tampered, forged, principal-mismatch, unauthorized for one of several
entries sharing an id, invalid) or discarded at decision time
(tampered, forged, unauthorized) contributes nothing to the verdict — but it is never silently
dropped. It is named in discarded, counted in STORE: … quarantined=N, and logged to stderr:
aegis check kubectl --constraints /tmp/oneflip.yaml --key file:data/example-signing.key \
--plan-constraints '' --pretty -- kubectl delete node/x --context kind-local
aegis: WARNING Quarantined constraint no-delete-nodes: provenance hash mismatch
ALLOW: kubernetes delete node/x
discarded: [{'id': 'no-delete-nodes', 'reason': 'tampered'}]
covered: True latency_ms: 0.25
STORE: loaded=20 quarantined=1 principals=3
quarantined: no-delete-nodes (tampered)
warning: Quarantined constraint no-delete-nodes: provenance hash mismatch
Why not stop the line instead? Because if an untrustworthy rule could force ESCALATE, anyone able to write a rule could stall every matching action — a denial of service on the guardrail, and the usual reason guardrails get switched off. Measured on the benchmark, that policy scores the same poison-susceptibility and over-block rate as a verifier with no trust model at all. Visibility, not obedience, is what makes a poisoned rule safe.
If you would rather an edited rule stopped the line, and accept that anyone who can write a
rule can then stop it, opt in with --on-untrusted-match escalate. The same command then
exits 2:
ESCALATE: kubernetes delete node/x
discarded: [{'id': 'no-delete-nodes', 'reason': 'tampered'}]
note: fail-closed: no-delete-nodes (tampered)
Even then, an untrustworthy rule can never produce BLOCK.
(/tmp/oneflip.yaml here is data/constraints.example.yaml with the last hex digit of
no-delete-nodes’s provenance_hash flipped and re-signed with the example key — a valid
signature, invalid content, exactly what a hand-edited rule or a one-bit storage error looks
like. --key is explicit because the example key normally auto-resolves next to
--constraints, and /tmp has no example-signing.key of its own. --context kind-local
resolves the environment and --plan-constraints '' switches off plan rules, so the tampered
rule is the only thing deciding this intent.)
Aegis refuses to decide at all (exit 65, one-line message, no verdict) when the store loaded
zero constraints, the authority map grants nothing to anyone, or more than
--max-quarantine-ratio (default 0.10) of the constraints were quarantined. --fail-closed
additionally turns an uncovered intent (no rule matched) into ESCALATE with the note
fail-closed: uncovered.
Some clauses do fail closed, because they cover missing information rather than an
attacker’s choice: a rule that scopes on env when the
intent’s environment could not be resolved contributes ESCALATE with the note
env-unresolved: <id> (see Environment mapping), and an
intent whose target the parser could not pin down (git push -f with no refspec) contributes
ESCALATE with the note unknown-target, so it cannot slip past a ref/main rule as ref/*.
In the same way a namespace-scoped rule escalates with namespace-unresolved: <id> when a
kubectl/helm/flux command names no namespace (or uses -A), and a kind- or object-based rule
escalates with manifest-not-inspected: <id> on kubectl … -f <file>|-, once per file, whose
manifest is never read (Environment mapping). The note
target-unresolved: <id> is the same idea for targets kubectl finds when it runs: kubectl exec
deploy/web or kubectl logs deploy/web reaches some pod, so a rule on pod/payments-0 escalates
while a rule on pod/* decides as usual, and --all or a selector does the same for a rule on one
object of that kind. kubectl describe pod pay escalates under a describe rule on a pod whose
name starts with pay, because kubectl treats the name as a prefix when no pod has exactly that
name. A kind outside the built-in table, as in kubectl delete widgets --all, escalates under a
rule on a custom kind, because a plural or short name cannot be resolved from the command
(Kubernetes resource names). kubectl debug web,
kubectl run web and kubectl cp b web:/a need no note: they are pod/web, beside the target
earlier versions gave.
Words after -- count as operands on the verbs that take them, so kubectl describe pod api --
payments-0 is two pods.
Claude Code hook
For Claude Code, Codex, Copilot, VS Code and Cursor, use aegis hook <agent> and
aegis install <agent> instead; see Coding agents. The script below predates
them and is kept for existing setups: unlike aegis hook, it gates every project it is
registered in, whether or not the project has a policy.
examples/claude-code-hook.sh is a PreToolUse hook: it reads the hook JSON from stdin and
hands tool_input.command — the raw string — to aegis check command --exit-style claude-hook.
ALLOW lets the tool call proceed; ESCALATE and BLOCK exit 2 with the reason on stderr (which
Claude Code shows to the model). Compound commands are split and launchers unwrapped (see
“Compound commands” below); binaries Aegis has no parser for are not gated unless you add
--fail-closed via AEGIS_ARGS; any tool error — including a command string Aegis refuses to
evaluate statically, such as kubectl delete $(cat x) — is converted into a block, so the hook
never fails open. It runs the aegis in the venv next to it (AEGIS_BIN overrides).
{"hooks": {"PreToolUse": [{"matcher": "Bash", "hooks": [
{"type": "command", "command": "/path/to/aegis-devops/examples/claude-code-hook.sh"}]}]}}
Verified snapshot
aegis snapshot loads and verifies the policy as aegis check does and prints what may
actually vote:
aegis snapshot --pretty
SNAPSHOT eac55f5b2b2163b6…
aegis 0.2.1; verified=30 excluded=0
input: environments 9d970db5…
input: plan_constraints c2f595cd…
input: sources_manifest 2fbfa3b2…
verified counts constraints that are loaded and, at this moment, intact, authorized
(authority is otherwise checked per decision) and source-verified at load — a signed
constraint with a self-consistent hash is not proof that its cited source backs it. excluded
lists everything else with its reason (tampered, forged, unauthorized, source-unverified,
invalid, …). The digest covers every input — the verified constraints, the authority map, the
environment and plan-constraint maps, the sources manifest, repos.yaml/signers.yaml/
agents.yaml when present, the commit each Git source ref points at, store settings that change
evaluation (the default time zone, tzdata availability) and the Aegis version — so anything
built from the policy can be traced to exactly this state.
It refuses --insecure, --sources '', and any decision-shaping file that does not verify: the
environment and plan-constraint maps are loaded through their loaders (signature and shape),
agents.yaml through the identity-model loader (below). The snapshot is detached from the loaded store: it keeps canonical
records and hands out fresh copies, so nothing can change what it describes after the fact.
Without --pretty it prints one JSON object. aegis sources is the per-constraint view of the
same load.
Identity model
aegis agents verifies agents.yaml (signature, shape, and that its principal holds the
identity class) and prints the identity model server-side enforcement is compiled for:
aegis agents --pretty
AGENTS /home/me/.config/aegis/agents.yaml
mode=deny-by-default enforcement=report-only principal=admin
kubernetes:
break-glass group aegis:break-glass
trusted group platform-admins
trusted serviceaccount argocd:argocd-application-controller
(every other identity is treated as an agent)
aws:
break-glass role arn:aws:iam::111122223333:role/BreakGlass
trusted role arn:aws:iam::111122223333:role/Deploy
(every other identity is treated as an agent)
Exit 0, 1 when the model has a warning (workflow-unbound, no-break-glass), 65 when it does
not verify, 66 when there is no agents.yaml (--agents PATH points elsewhere). Without
--pretty it prints one JSON object. See Configuration.
Denial report (preview)
aegis report aws --compiled build/aegis-aws (--events FILE... | --collect [--days N])
[--policy-id p-...] [--test-principal GLOB] [--quiet-days 30] [--since ISO] [--json]
Read-only. Which calls the compiled SCPs denied, from CloudTrail: attributed to Aegis when the
error carries the policy ARN of a --policy-id, per rule, real versus --test-principal
tests. Exit 0; 1 when no real call was denied in a window of at least --quiet-days, or
nothing could be attributed (no --policy-id); 65 for unreadable events or compile output.
See Server-side: is it denying anything?.
aegis report kubernetes --compiled build/aegis-kube --audit-log FILE...
[--test-principal GLOB] [--quiet-days 30] [--since ISO] [--json]
Read-only. Which requests the compiled admission policies denied (or warned about, in
report-only mode), from the API server’s audit log: per rule, real versus --test-principal
tests. Exit 0; 1 when no real request failed an Aegis policy in a window of at least
--quiet-days, or the log holds no events; 65 for unreadable events or compile output. See
Server-side: is it denying anything? (Kubernetes).
Server-side compile (preview)
aegis compile aws --account <12-digit id> --out DIR compiles the verified snapshot to AWS
Service Control Policies scoped to the agent identities in agents.yaml; --check DIR exits 1
on drift. It refuses --insecure and unsigned policy like aegis snapshot, and needs
agents.yaml. Options: --partition, --escalate deny|omit, --max-policies. See
Server-side enforcement.
aegis compile kubernetes --cluster <name> --out DIR compiles it to Kubernetes
ValidatingAdmissionPolicies (policies.yaml, for kubectl apply -f) scoped to the same
agents, with the same coverage report, manifest and --check DIR; --escalate deny|omit.
Identity audit
aegis audit-identity aws checks agents.yaml against the IAM roles and users that actually
exist in an AWS account. It is read-only: it runs aws iam get-account-authorization-details
with your credentials (--profile), or reads a saved copy of that output (--inventory FILE).
aegis audit-identity aws --profile sandbox-admin --pretty
AUDIT aws account 701331084529 (deny-by-default, report-only)
would restrict (2):
role arn:aws:iam::701331084529:role/coding-agent last used 2026-09-29T03:12:50+00:00
role arn:aws:iam::701331084529:role/nightly-backup last used 2026-09-28T02:00:00+00:00
exempt (3):
role arn:aws:iam::701331084529:role/BreakGlass
...
service-linked, never restricted by SCPs: 5
- would restrict: every role and user a compiled policy would restrict — in
deny-by-default, everything not trusted or break-glass. This is the report-only review: add the legitimate automation here (backup jobs, cleanup functions, deploy roles) totrustedbefore settingenforcement: enforce.--would-restrictprints only this list. The last-used date helps tell live automation from leftovers; Identity Center andOrganizationAccountAccessRoleroles carry a hint. - missing (a problem): an identity
agents.yamllists for this account that does not exist. A mistyped break-glass role means there is no break-glass. - findings, on trust policies:
workflow-unbound,oidc-wildcard-subject,oidc-no-subject— GitHub OIDC trust that any job in a repository (or any repository) can use. On an exempt role this is a problem: an agent job can assume it withAssumeRoleWithWebIdentity, which no SCP condition on the caller can see.exempt-trusts-restricted,exempt-trusts-account— an exempt role that a restricted identity (or the whole account) may assume. The compiled self-protection block closes this once enforced, so it is a problem only whilereport-only.
Exit 0, 1 on a problem, 65 if agents.yaml does not verify, 66 if it is missing.
aegis audit-identity kubernetes [--context CTX] does the same for a cluster, read-only (get
and SubjectAccessReviews through kubectl with your credentials; --inventory FILE reads a
copy saved with --save-inventory):
- would restrict: every ServiceAccount, and every user and group named in an RBAC binding
(the API has no user objects), that the compiled policies would restrict, with its bindings
and how many pods run as it. The control plane is always exempt, as in the compiler, and groups
every identity carries (
system:authenticated,system:serviceaccounts) are not listed.system:masters, the API server’s kubelet client and node bootstrap tokens carry a hint. - missing (a problem): a listed ServiceAccount that does not exist, or a break-glass user or group no binding grants anything.
- findings (problems): an identity the policies restrict that RBAC still lets impersonate
users, groups, ServiceAccounts or UIDs; update, patch or delete ValidatingAdmissionPolicies,
their bindings or webhook configurations; create mutating webhooks or policies; or escalate,
bind or write cluster role bindings. Admission cannot see impersonation or protect admission
objects, so RBAC is the only control there. Each is asked as the identity with the groups it
really carries, by name for every trusted and break-glass user, group and ServiceAccount
(RBAC can grant impersonation by
resourceNames), and per namespace for ServiceAccounts (a RoleBinding grants it in one namespace). Note that the built-ineditandadminroles include impersonating ServiceAccounts in their namespace. A review that fails (no right to run it) is an error, never a “no”.
Compound commands
Agent frameworks hand over a shell string, not an argv. aegis check command -- "<string>"
(and aegis check argv --split-compound) turns that string into the simple commands it would
run — splitting on ;, &&, ||, |, & and newlines, unwrapping sudo, env VAR=…,
timeout, nice, nohup, command, time, sh -c "…" and the k/tf/g aliases — and
checks every one whose binary Aegis knows. The exit code is the worst verdict across them:
aegis check command -- "kubectl get pods; kubectl delete node/w1" # BLOCK, exit 3
aegis check command -- "sudo kubectl delete node/w1" # BLOCK, exit 3
aegis check command -- "kubectl get pods | grep x" # ALLOW, exit 0
aegis check command -- 'kubectl delete $(cat x)' # exit 64: command rejected
A help or version probe of a known binary produces one read-only intent, resource
cli/<tool>, action read, params.informational help or version. Only these forms
count:
- the tool’s help or version flag on its own:
helm --help,kubectl --version,psql -V(notpsql -h, which is--host); <tool> help [topic…]for kubectl, helm, argocd, flux, git, gh, gcloud and pulumi; a barehelpfor flyway and rails;<tool> version [options]for kubectl, helm, argocd, flux, gh and pulumi (argocd version --client); a bareversionfor git, az, gcloud, prisma, flyway and rails;<command words…> --help(or-h) for built-in commands of kubectl, helm, argocd, flux, gh and pulumi, and for any command of az, gcloud and prisma (kubectl delete --help,gcloud compute instances delete --help). kubectl’s subcommands are checked too:kubectl create nuke --helpwould run akubectl-create-nukeplugin;git <command> --helpandalembic <command> --help(one word;git <command> -his passed to an alias as is).
For aws only aws --version counts: a [toplevel] alias in ~/.aws/cli/alias can replace
help and any service name (s3 = !cmd makes aws s3 help run cmd), so aws help and
aws <service> … help go to the aws parser like any other aws command.
Anything else is parsed as the command it is: an option before the help flag
(kubectl -n --help delete ns prod deletes namespace prod), -- before it, a plugin,
extension or unknown subcommand, and gh extension exec NAME --help, which passes the flag to
the extension and runs it. Some real probes are therefore still refused, for example
gcloud version --format json and alembic -c x.ini upgrade --help. The git and aws parsers
do not resolve aliases at all: git co is read as a git command, and an unknown aws service
as that service.
kubectl, helm, flux and argocd flags, and those of the gh commands that change something: each
tool has a table of its flags, read from its source (kubectl 1.36’s --help on every command,
helm 4.3.1 and 3.21.1, flux 2.10.0, argo-cd 3.6.1, gh 2.103). Booleans (--no-headers, --no-hooks, --prune, …) take no value; value flags take the next
token even when it starts with -, as pflag does, so helm upgrade api ./c -n prod
--description -ndev runs in prod. A flag in no table is a boolean at the end of argv and
keeps a value written as --flag=value. Anywhere else the command is refused (cannot tell
whether '--x' takes a value): if the flag takes a value the next word is that value, and if it
does not the next word is a flag, a name or an operand, so either guess could misread the
namespace or the target. A short flag in no table is read the same way. Words after -- are
operands on helm, flux and argocd. kubectl get|create|replace|delete --raw <path> acts on the
object or collection the path names (/api/v1/namespaces/prod/pods/x is pod/x in prod),
whatever the other words, -n and --dry-run say, since kubectl ignores them; a path that
names no object or collection (a subresource, a query, /healthz) is refused.
Updating the flag tables. The tables in src/aegis_core/parser.py are pinned to the
versions named above, and a flag a later release adds is refused until it is listed: that is
on purpose, since guessing is how a namespace or a target gets misread. To add one, find how
the tool registers it and put it in the matching set, with a test that reads it:
- kubectl:
kubectl <command> --helpon every command. A flag shown as--x=falseor--x=true, or one with a default for a bare use (--cascade,--validate), goes in_KNOWN_BOOL_FLAGS; any other in_KUBECTL_VALUE_FLAGS; one with a number default in_KUBECTL_INT_FLAGStoo; a short letter in_KUBECTL_SHORT_BOOL_LETTERSor_KUBECTL_SHORT_VALUE_LETTERS. - helm (
pkg/cmd,pkg/cli), flux (cmd/flux, and cli-runtime’s kubeconfig flags), argo-cd (cmd/argocd/commands,cmd/util) and gh (pkg/cmd,pkg/cmdutil): everyFlags().XxxVar[P](…)call. ABool…flag, or one whoseNoOptDefValis set, is a boolean (_HELM_BOOL_ONLY_FLAGS,_FLUX_BOOL_FLAGS,_ARGOCD_BOOL_FLAGS,_GH_COMMAND_FLAGS); any other takes a value (_HELM_VALUE_FLAGS,_FLUX_VALUE_FLAGS,_ARGOCD_VALUE_FLAGS). A name that is a boolean on one command and takes a value on another needs a per-verb rule, as--server-sidehas in_helm_long_flags. - git:
git <verb> -handgit <verb> --git-completion-helper-all(in a repository) for_GIT_OPTION_SPECS:<arg>is=,[=<arg>]is?,[no-]is!. - aws: the global options in
awscli/data/cli.json(_AWS_GLOBAL_OPTIONS) and the s3 options inawscli/customizations/s3(_AWS_S3_OPTIONS). Every other command’s options are insrc/aegis_core/data/aws_cli_options.zip, read from aws-cli’s own parsers: runscripts/gen_aws_cli_options.pywith the Python of an installed aws-cli v2 to regenerate it (itsVERSIONnames the aws-cli). An option is resolved by prefix against the operation’s list, as argparse does, and one the operation does not have is refused. - az: the short letters in every
command_modules/*/_params.pyof azure-cli: a letter on astore_trueargument goes in_AZ_SHORT_BOOL_LETTERS, and every letter in_AZ_SHORT_KNOWN_LETTERS. The long option each letter is, per command, is insrc/aegis_core/data/az_short_options.json: runscripts/gen_az_short_options.pyon an azure-cli checkout to regenerate it. - Short options are recorded under their long name on every tool (
_KUBECTL_SHORT_NAMES,_helm_short_name,_FLUX_SHORT_NAMES,_argocd_short_name, gh’s per-command short maps, the gcloud table’salias, the az table): a new letter needs its long name there too. - gcloud: the flags of the commands the parser names resources for are in
src/aegis_core/data/gcloud_flags.json, read from their reference pages byscripts/gen_gcloud_flags.py(add a command to itsCOMMANDSand run it); a flag such a command does not have is refused. For other commands, and alpha and beta, a flag whose reference page shows--flag=VALUEmay go in_GCLOUD_VALUE_FLAGS; never a boolean, which would take the name after it as its value.
Inside a pipeline an unknown binary (| grep x) produces nothing; on its own it produces a
synthetic shell / binary/<name> / exec intent that --fail-closed escalates. When that
binary runs code Aegis cannot read (a script file, make or npm run, python3 -c code, a
shell fed through a pipe, which counts even inside a pipeline), the intent carries
params.runs_code and --escalate-scripts escalates it with the note runs-code: …. KUBECONFIG=…
and env AWS_PROFILE=… prefixes land in the intent’s metadata (kubeconfig, profile, …) so
the environment map sees them. Fail closed: anything whose argv cannot be known without
running it is refused as a usage error (exit 64, command rejected: <reason>) — command
substitution ($(…), backticks), $VAR outside single quotes, process substitution,
subshells, here-docs, eval/exec/source/./xargs, and unbalanced quotes. Without the
flag, aegis check <target> still treats any shell metacharacter in an argv as a usage error.
Dry runs
A rehearsal (kubectl --dry-run=client|server, helm --dry-run, argocd app sync --dry-run,
flux create --export, aws --dry-run, aws s3 --dryrun, az --what-if|--dry-run, gcloud
--dry-run, git push -n) can’t change infrastructure, so Aegis never blocks or escalates it —
the verdict is always ALLOW, with dry_run: true and would_be reporting what a real run
would have gotten. When the flag is repeated the last one decides: kubectl --dry-run=client
--dry-run=none is a real run, and so is --dry-run --no-dry-run on aws and git (and a prefix of
--no-dry-run that the tool takes, such as --no-dry). A --dry-run the verb does not have is
not a rehearsal: flux has none on the verbs Aegis reads, argocd has it only on app sync, and
git commit -n is --no-verify.
ALLOW: kubernetes scale deployment/api-server (dry-run; would be BLOCK)
citations: no-scale-prod-peak
covered: True latency_ms: 0.12
PLAN ALLOW: 1 intent(s)
note: would_be: BLOCK
terraform/tofu plans are evaluated normally — the plan JSON is the proposed change, not a
rehearsal of one.
Library usage
from aegis_core.authority import load_authority_map
from aegis_core.store import ConstraintStore
from aegis_core.interceptor import AegisInterceptor
from aegis_core.parser import from_kubectl
authority_map = load_authority_map("data/authority.example.yaml")
store = ConstraintStore.load("data/constraints.example.yaml", authority_map=authority_map)
interceptor = AegisInterceptor(store)
intent = from_kubectl(["kubectl", "delete", "node/worker-1"])
decision = interceptor.intercept(intent)
print(decision.verdict, decision.citations, decision.covered)
# BLOCK ['no-delete-nodes'] True
Decision also carries discarded (constraints that matched but were thrown out, with why),
notes (fail-closed: …, rate-limit: …), latency_ms, dry_run, and would_be.
store.health is the StoreHealth the CLI prints; AegisInterceptor(store, fail_closed=True)
is the library form of --fail-closed.