# Policies

> Rules for what agents may touch: path, symbol and agent matches, required claims and lane limits, enforced in hooks, MCP and CI or set for an organization.

Availability: Repository policies in the CLI; organization policies on the Team plan.

A policy file, `.lanekeeper/policy.yml`, says which code agents may change and under what conditions. Commit it:
the daemon reads it from the repository when it starts.

```yaml
version: 1
rules:
  - id: no-agent-secrets
    match: { paths: ["**/.env*", "infra/secrets/**"] }
    agents: { kinds: ["claude-code", "cursor", "codex", "other"] }
    effect: deny
    message: "Agents may not edit secrets. Ask a human."
  - id: protect-migrations
    match: { paths: ["db/migrations/**"] }
    require: { claim: exclusive }
  - id: one-agent-on-auth
    match: { paths: ["src/auth/**"] }
    limit: { concurrentLanes: 1 }
  - id: combined-tests-before-merge
    ci: { requireCombinedCheck: true }
```

## Rules

Each rule has an `id` (lowercase, with dashes) and at least one of these clauses:

- `effect: deny | warn` — every matching edit is denied (or flagged), with `message` if you give one.
- `require: { claim: soft | exclusive }` — the lane must hold a claim covering the file, at least that strong.
  A claim on a glob that includes the file covers it, and so does a claim on a symbol in that file. When the
  rule matches a specific symbol, only a claim on that symbol counts. Without the claim the edit is denied
  (or flagged, if the rule also says `effect: warn`).
- `limit: { concurrentLanes: N }` — warns (or denies, with `effect: deny`) when more than N lanes, counting the one
  editing, change the matched area.
- `ci: { requireCombinedCheck: true }` — the [GitHub Action](https://lanekeeper.dev/docs/github-action) fails a pull request when no
  `build-command` or `test-command` is configured, because a combined check can't run.

`match` takes `paths` (globs) and `symbols` (symbol-id globs such as `ts:src/routes.ts#*`); without `match` a rule
applies to every edit. `agents.kinds` limits it to some agents (`claude-code`, `cursor`, `codex`, `copilot`,
`devin`, `human`, `other`, or `*`).

## Where they apply

- **Hooks and MCP:** a `deny` blocks the edit even in warn mode (clashes only block in block mode); the agent
  sees the policy's message. Warnings are shown with the edit.
- **CI:** `ci.requireCombinedCheck` in the GitHub Action.
- **`lk policy test [file]`** lists the rules, reports a broken file, and with a path shows what an edit to it would
  trigger right now (`--agent <kind>` to check as another agent).

Every decision is recorded in the [audit log](https://lanekeeper.dev/docs/audit) with the rules that fired.

## Organization policy

Owners and admins write one policy for the whole organization on the dashboard's **Policies** page, in the same
YAML. Every machine with team sync fetches it (on start and every 10 minutes) and enforces its rules ahead of the
repository's own; a repository rule with the same id as an organization rule is ignored, so a repository can't
relax it. The last policy fetched stays in force offline and across restarts. With a `cloud-api-url` and a `cloud-token`, the GitHub
Action applies the organization's `ci` rules too. The page also tests a draft against a file path and agent, with
the same evaluator, before you save it. Saving and removing it are audited.

`lk policy test` marks organization rules with "(organization)" and reports an organization policy that doesn't
parse (it is then not enforced, like a broken `policy.yml`).

## Owners

With `owners: { from: CODEOWNERS }` in `policy.yml`, clash suggestions name the owners of the clashing files, read
from `.github/CODEOWNERS`, `CODEOWNERS` or `docs/CODEOWNERS` (GitHub's order and matching: the last matching line
wins). For example: "… let one lane merge first. Owners: @acme/security."

## Good to know

- A policy file that doesn't parse enforces nothing, and says why in `lk policy test` and `lk daemon logs`, so a
  typo can't block every edit. Fix it and restart the daemon (`lk daemon stop`; the next command starts it).
- The daemon reads the policy when it starts; restart it after editing.
- `require` and `limit` rules depend on claims and other lanes, which live on developers' machines; the dashboard
  test treats an edit as holding no claim with no other lane on the path.
