> ## Documentation Index
> Fetch the complete documentation index at: https://shunya.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# CI enforcement

> Require explicit acknowledgment when a change touches a blocking Decision scope.

`charter check` is designed for CI. It does not judge whether code semantically complies with a Decision. Instead, it guarantees that a matching accepted Decision was explicitly acknowledged.

## How matching works

1. Charter collects changed file names relative to the base ref using `git diff <base>...HEAD`.
2. It considers accepted Decisions only.
3. A Decision matches if a path glob matches a changed file, or if a scope tag appears in the unified diff.
4. For each matching `blocking` Decision, Charter searches commit messages in `<base>..HEAD` for `Governed-By: <id>` or `Charter: <id>`.
5. An uncited blocking match exits `2`.

```mermaid theme={null}
flowchart LR
    Diff["Changed files + diff"] --> Match{"Matches accepted\nDecision scope?"}
    Match -->|"No"| Pass["Exit 0"]
    Match -->|"Yes, advisory/off"| Notice["Report advisory\nExit 0 unless stale"]
    Match -->|"Yes, blocking"| Trailer{"Trailer in\nbase..HEAD?"}
    Trailer -->|"Governed-By / Charter"| Pass
    Trailer -->|"Missing"| Block["Exit 2"]
    Notice --> Stale{"Stale?"}
    Stale -->|"Yes"| Advisory["Exit 1"]
    Stale -->|"No"| Pass
```

## GitHub Actions example

Use a full Git history so the base commit and commit messages are available:

```yaml theme={null}
name: charter

on:
  pull_request:

jobs:
  governance:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - uses: actions/setup-go@v5
        with:
          go-version-file: go.mod
      - name: Check governed changes
        run: go run ./cmd/charter check --diff "${{ github.event.pull_request.base.sha }}"
```

For an installed release binary, replace the last command with `charter check --diff ...`.

## Commit acknowledgments

Use one trailer per Decision:

```text theme={null}
feat: replace storage adapter

Governed-By: 0001
Governed-By: 0014
```

Acknowledgments are assessed across the commit range, not only the latest commit. Keep the trailer on the commit that introduces the governed change so the project history stays understandable.

## Local use versus CI

```sh theme={null}
charter check
charter check --diff origin/main
```

Without `--diff`, Charter compares the working tree with `HEAD`, reports matches, and does **not** block—there is no commit range whose trailers it can inspect. With `--diff`, it enforces blocking Decisions.

## Interpret exit codes

| Exit code | Meaning |
| - | - |
| `0` | No blocking violations and no stale matched Decisions. |
| `1` | Advisory findings only: currently, a matched Decision is stale. |
| `2` | One or more matching blocking Decisions lack an acknowledgment. |
| `3` | The check could not run: bad base ref, unreadable or corrupt decision store, or missing `.charter`. CI must fail the job — this is not a pass. |

If `charter check` cannot run at all — bad base ref, unreadable or corrupt decision store, missing `.charter` — it exits `3`. Fail the job on it: it means "not checked", never "passed".

## Practical CI guidance

* Run the check on pull requests, not just after merge.
* Pass a stable base SHA or branch reachable in the checkout.
* Use `fetch-depth: 0` for GitHub Actions; shallow history can prevent Charter from reading the range and commit trailers.
* Keep scopes narrow enough that acknowledgments mean something.
* Treat stale advisories as a review prompt, not a failed compliance check.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.