The pre-commit hook
Last updated 24 November 2026
Since 1.18.0 the scanner's repository is a hook repository of the pre-commit framework. Add the hook to a repository and every commit that changes agent content, such as a skill, an MCP configuration file or an agent card, is scanned on the developer's machine first. A finding at the chosen severity stops the commit, as it would fail the CI check later. The hook runs the same open-source scanner as the GitHub Action and the GitLab component. Since 1.19.0 it judges only what is staged for the commit, and it sends nothing to Spellwarden.
Set up the hook
The hook needs the pre-commit framework 3.2.0 or later. Add these lines to the repository's .pre-commit-config.yaml:
repos:
- repo: https://github.com/spellwarden-ai/spellwarden
rev: v1.21.0
hooks:
- id: spellwarden
# args: [--preset, low-noise] # any `spellwarden scan` option
# args: [--follow-links] # also judge linked directories in instruction foldersThen run pre-commit install once in the repository. The framework installs the scanner from the tagged release into an environment of its own, so the developer needs no other install of it. Pin rev to a release tag, as the CI wrappers are pinned. The hook definition is the file .pre-commit-hooks.yaml at the root of the scanner's repository.
What the hook runs, and when
The hook runs spellwarden scan --staged at the repository root, at the framework's stages pre-commit, pre-push and manual, when the commit changes agent content:
- a
SKILL.mdanywhere, or anything under a folder namedskills; - anything under a folder named
.claude,.cursor,.codex,.gemini,.devin,.windsurf,.agents,.vscode,.claude-plugin,.spellwardenor.well-known; - anything under
.github/hooks,.github/instructions,.github/agentsor.github/copilot; - an MCP configuration file, a plugin's
hooks/hooks.json, an instruction file,CLAUDE.local.md,AGENTS.override.md,AGENTS.local.mdandAGENT.mdamong them, or an agent card.
Release 1.20.0 widened this filter with the files the scanner reads since then: the whole of the folders .gemini, .devin, .windsurf and .agents, the four folders under .github and the four variant names. A hook pinned to an earlier release keeps its narrower filter until rev moves.
The file filter only decides when the hook runs. The scan itself covers the whole repository as the git index holds it, because a skill is a folder, not a file: every staged file, and never an untracked file or a change that is not staged. The settings file .spellwarden/config.yml and the baseline are read from the index too, so a file left out of the commit can neither fail it nor exclude what it holds.
At the pre-commit stage the index is the content being committed. At the pre-push and manual stages, a pre-commit run --all-files in CI among them, it is the checked-out commit plus whatever is staged. A change the filter misses is judged the next time the hook runs, and in CI. The filter does not match a change to the commands/ or agents/ folder of a local plugin, nor, with args: [--follow-links], a change inside the directory that a followed link names, such as shared-rules/. Outside a git repository, or when git cannot read the index, the scan stops with the error staged_unavailable: it never passes without reading.
The hook judges the staged content since 1.19.0. A hook pinned to v1.18.0, the first release with the hook, runs spellwarden scan --no-upload instead and judges the working tree: untracked files that git does not ignore count too, and so does an untracked settings file. Move rev to v1.19.0 or later to judge the staged content only.
When a commit is stopped
The hook's exit code is the scanner's:
| Exit code | The commit | Why |
|---|---|---|
0 | Goes ahead. | No unsuppressed finding at or above --fail-on (high by default). |
1 | Is stopped. | A finding at or above --fail-on. The scanner prints it with its fix. |
2 | Is stopped. | The scan is incomplete: something it was asked to judge could not be read, git could not read the index, or the settings are invalid. An incomplete scan never looks like a pass. |
3 | Is stopped. | With --locked in the hook's arguments: the lock file is absent or out of date. |
To commit once without the hook, for example to save work in progress: SKIP=spellwarden git commit. Accept a finding you have reviewed in the baseline file instead of skipping the hook every time, so the decision is recorded in the repository.
Options
The hook takes any option of spellwarden scan in args. Since 1.18.0 a common one is a preset, which changes the severity of named rules: args: [--preset, low-noise] keeps the hook quiet on rules that fire on most benign content, and args: [--preset, strict] stops commits on more. Presets has the table of every rule. Without args, the settings of .spellwarden/config.yml apply, in the version that is staged.
Since 1.20.0, args: [--follow-links] makes the hook also judge the files in a linked directory of an instruction folder, as the links and their targets are staged. Linked rule folders says what the option follows.
What the hook sends
The hook sends nothing to Spellwarden, on a developer's machine or in CI: it never uploads to an organisation in connected mode and never sends the usage ping. When SPELLWARDEN_ORG or SPELLWARDEN_API_KEY is set, the hook ignores them and says so once, with the notice staged_credentials_ignored. That is all it means: with --probe or --analyze in the hook's args, the scan still reaches the servers and the model endpoint you name, as any scan does.
A hook pinned to v1.18.0 passes --no-upload instead: it never uploads, and outside CI its scan sends no usage ping, but inside a CI job it sends the usage ping like any scan in CI; add --no-telemetry to the hook's args, or use any other switch of the usage ping, to turn it off (see the usage ping).
The hook and CI
The hook is a fast first check for the person committing. It does not replace the scan in CI: a developer can skip the hook, and only CI sees every pull or merge request, uploads to your organisation in connected mode and runs the registry check. Run both, with the same release, so that they agree (see Scan in CI with GitHub or GitLab).
On a pull or merge request in CI, the hook reads the request's own settings file and baseline from the index, so a request can change what its own hook run judges. The hook is therefore not the check that decides a merge: the GitHub Action, the GitLab component or a scan without --staged is, because they read the settings file and the baseline from the base revision, the commit the request targets. If pre-commit run is your only CI check, add one of them before you move the hook's rev to v1.19.0.
In CI, a settings file that says connected.required: true makes a scan without --staged connect to your organisation. The hook does not: it gives the notice staged_connected_required, which says that connected mode was not evaluated, so your organisation's rules and the registry check were not applied. It is a notice, so the exit code does not change.