Lesson file format
A lesson is one Markdown file with YAML front matter. This page lists every field, every check kind, and the rules Scarcheck follows to verify, compile and retire a lesson.
scar init, scar learn (from a commit or a session, with command guards), scar lessons ls, show, verify, archive and restore, scar check (grep, file-absent, command), scar compile, hooks for Claude Code, Codex and pre-commit, and scar doctor. It works offline and sends nothing anywhere. Anything marked Planned is not built.Anatomy of a lesson#
Each lesson lives in .scarcheck/lessons/, one file per lesson, named by its id. You can read, review and edit it in a pull request like any other file. This is L-142 from acme/web:
--- id: L-142 rule: Use pnpm. Never npm or yarn in this repo.1 scope: repo trigger: ["package.json", "tool:Bash"] status: verified evidence:2 - commit: a41f9e2 - correction: claude-code session 7f3c, turn 12 checks:3 - file-absent: [package-lock.json, yarn.lock] - block-command: "^(npm (i|install)|yarn add)\\b" instead: "pnpm add {args}" proof:4 before: { commit: 7c01d55, result: fail } # a41f9e2^ after: { commit: a41f9e2, result: pass } verified_at: 2026-10-21T09:14:03Z learned_by: alex@acme.dev review_after: 2027-01-235 --- The repo is a pnpm workspace. npm writes a lockfile pnpm ignores, so CI installs different versions. Fix: pnpm add <pkg> --filter <app>6
- The ruleOne or two short sentences, written as an instruction. This is what agents read.
- The evidenceThe fix commit, pull request or test that proves the rule, plus the correction that explains it.
- The checksWhat catches a repeat: a file, pattern or test check, and an agent guard with the command to run instead.
- The proofWritten by the replay: both commits, their results and when it ran. Never edited by hand.
- The review datePushed 90 days out each time a check catches a repeat.
- The bodyFree Markdown for people. The
Fix:line is also compiled next to the rule.
Front matter fields#
scar learn writes every field for you. Edit with scar lessons edit L-142 Planned: it opens your editor, validates the front matter on save, and verifies the lesson again if its checks changed. The real file changes only if the edit is valid.
| Field | Type | Required | What it means |
|---|---|---|---|
id | string | Yes | L- and the next number past every id in the repo, deleted ones too. An archived lesson keeps its id. |
rule | string | Yes | What the agent must do, in one or two short sentences. This is the text compiled into rules files. |
scope | repo org personal | Yes | Where the lesson applies. See Scope. |
trigger | list | No | File globs and tool:NAME entries. Checks run only when a trigger matches. Empty means always. |
status | state | Yes | Set by Scarcheck, not by hand. Only verified lessons compile. See Lesson states. |
evidence | list | To verify | commit, pr, test or correction entries. A correction alone is not enough to verify. |
checks | list | To verify | One or more checks. See Check kinds. |
proof | map | Set by Scarcheck | The replay result: before and after commits with fail or pass, and verified_at. Rewritten by every scar lessons verify. |
proposed_checks | list | No | Drafts only: a check that did not pass the replay. It never runs. |
learned_by | No | Who ran scar learn, from git config user.email; left out when that is not set. Shown in provenance and the audit log. | |
review_after | date | Yes | When the lesson comes up for review. Every repeat caught pushes it 90 days out. See Expiry. |
supersedes | id or list | No | Lessons this one replaces. They move to archived when this one verifies. |
aliases Planned | list | No | Old ids. If two people create the same id on different branches, Scarcheck will renumber the newer lesson and keep the old id here, so references still resolve. |
Scope#
Scope decides which repos and people a lesson reaches. The file format is the same for all three.
| Scope | Applies to | Stored in |
|---|---|---|
repo | One repo, for everyone who clones it. L-142 in acme/web. | The repo's .scarcheck/lessons/ |
org Planned | Every repo in the workspace. L-131 and L-119 at Acme. | Not built: today an org lesson lives in each repo that commits it |
personal | Only you, in every repo you work in. L-145. | ~/.config/scarcheck/lessons/ on this machine |
Share a lesson with your team by committing it. Review it in the pull request like any other change.
Check kinds#
A check is how Scarcheck tells a repeat from correct code. Five kinds look at the code; block-command looks at what an agent is about to run. A lesson can have several.
| Kind | Pre-commit | CI | Agent hook |
|---|---|---|---|
file-absent | Yes | Yes | Yes, on Write |
grep | Yes | Yes | Yes, on Edit and Write |
ast-grep | Yes | Yes | Yes, on Edit and Write |
semgrep | Yes, if installed | Yes | No |
command | Off by default | Yes | No |
block-command | No | No | Yes |
file-absent#
Passes when none of the paths exist. Globs work, like **/.env.local. L-142 uses it to keep npm and yarn lockfiles out of a pnpm repo.
checks: - file-absent: [package-lock.json, yarn.lock]
grep#
A ripgrep pattern over the paths you list. With must: absent, the default, any match fails. With must: present, a path without a match fails. L-104 makes sure every test script sets TZ=UTC:
checks: - grep: pattern: '"test": "TZ=UTC ' paths: [package.json, "apps/*/package.json"] must: present
ast-grep Planned#
Matches syntax, not text, so formatting and comments do not fool it. fix is shown in the failure and in the agent hook, and scar check --fix applies it. L-131 finds API dates parsed with new Date():
checks: - ast-grep: language: typescript pattern: new Date($OBJ.$FIELD) paths: ["apps/**/src/**/*.ts"] fix: parseISO($OBJ.$FIELD)
semgrep Planned#
Runs Semgrep with an inline pattern, or with config: pointing at a rules file you already have. If Semgrep is not installed, pre-commit skips the check with a warning and CI fails it. L-119 keeps the flag SDK behind flags.get():
checks: - semgrep: languages: [typescript] pattern: import $C from "@acme/flag-sdk" paths: ["apps/**", "packages/**", "!packages/flags/**"]
command#
Any command; exit code 0 passes. This is how a failing test becomes a check. Commands are slow, so pre-commit skips them unless check.precommit_commands is true; CI always runs them. L-131 keeps its evidence test as a second check:
checks: - command: run: pnpm vitest run src/lib/tz.spec.ts timeout_ms: 60000 # default 3000, from check.timeout_ms
block-command#
An agent guard. It runs only in agent hooks, against the command a tool call is about to run. A match blocks the call and tells the agent the command to run instead, where {args} is the rest of the command after the match. Guards in org lessons apply in every repo of the workspace. L-138 keeps agents off the shared database in acme/api:
checks: - block-command: '^(npx )?prisma migrate dev\b' instead: "make db-migrate"
Try a pattern without starting an agent, once scar hooks test ships Planned:
$ scar hooks test claude-code --command "npx prisma migrate dev" ● PreToolUse Bash npx prisma migrate dev ✗ exit 2 · blocked by L-138 stderr, read by the agent: │ Scarcheck blocked this command. Lesson L-138 (verified, acme/api): │ Run migrations with make db-migrate. Never prisma migrate dev │ against the shared database. │ Blocked: npx prisma migrate dev │ Instead: make db-migrate │ …2 more lines
A file-absent path is guarded the same way when an agent tries to write it: Blocked: write package-lock.json.
Verification rules#
A lesson becomes verified only when every one of these holds. If any fails, it stays a draft and never reaches a rules file.
- Real evidence. A fix commit, a merged pull request, a test that failed and now passes, or a correction recorded by an agent hook together with the commit that fixed it. A correction alone explains the rule; it does not prove it.
- Fail before, pass after. Every check must fail on the commit before the fix and pass on the fix:
a41f9e2^anda41f9e2. For a pull request that is the merge base and the head. Passing on both proves nothing; failing on both means the check would block good code. - Guards match the mistake only. A
block-commandmust match the bad command recorded in the session and must not match the command that replaced it. - Pass on HEAD. Or, with your consent, today's violations are written to
.scarcheck/baseline.jsonso only new ones fail. Otherwise enforcing the lesson would block every commit from now on. - Verify again on change.
scar lessons editPlanned replays a lesson whose checks changed. If it no longer verifies, it becomes a draft, after asking.scar lessons verifyrepeats the replay any time.
Your working tree is never touched. file-absent, grep, ast-grep and semgrep read files straight from git history; command checks run in a temporary folder that Scarcheck fills with the commit's files itself, with no checkout, so no git hook or filter runs; the folder is removed afterwards. With test evidence, both sides of the replay run the test:
No pair yet, like an imported lesson or a draft? scar lessons verify L-145 --search-history Planned walks up to 500 commits back for a commit where the check failed and then passed.
Lesson states#
Scarcheck sets status; you move a lesson along with scar learn, scar lessons, and later scar review Planned. Only verified lessons are in rules files, plus stale ones that have only gone quiet, until their review date.
Renewing a stale or expired lesson moves its review date 90 days out and replays it. Any state can be archived by hand.
| State | What it means | In rules files | Checks run |
|---|---|---|---|
| Draft | No replay has passed yet, or no check exists. L-145 has no automatic check. | No | No |
| Verified | The replay passed. L-142, 7 repeats caught. | Yes | Yes |
| Failing | A check fails on HEAD or cannot run. L-140 needs a yarn.lock that is not there. | No, held back | Reported only |
| Stale | 0 hits in 90 days, or the fact it rests on changed. L-088: .nvmrc is now 22. | Quiet: yes, until review. Premise changed: no | Yes |
| Conflict | Cannot pass on the same commit as a verified lesson. L-140 against L-142. | No, held back | Reported only |
| Expired | The review date passed and nobody renewed it within 14 days. | No | No |
| Archived | Retired with scar lessons archive and a reason, or superseded. Nothing is deleted; scar lessons restore undoes it. | No | No |
Conflicts Planned#
Two lessons conflict when one check requires what another forbids on overlapping paths, or when their rules name the same tool with opposite verbs. L-140 needs a yarn.lock; L-142 forbids it. Until you decide, the established lesson stays in force and the newer one is held back, so no agent reads both and picks one at random:
Resolve it in scar review, or without a terminal UI with scar review resolve L-140 and one action:
- Keep one (
--keep L-142). The other is archived with your reason, and its author is notified. - Scope both (
--scope-both). Each is narrowed by path or repo so they no longer overlap, and both verify again. - Merge (
--merge). One lesson with both sets of evidence. It stays a draft until it verifies again.
Every decision can be undone with scar lessons restore.
scar lessons ls lists what applies here, the lessons that need you first:
Compile targets#
scar compile writes the same verified lessons into each agent's native file. scar init turns on a target for every agent it finds; change the list with compile.targets in .scarcheck/config.toml.
| Target | File | Read by | Scarcheck writes |
|---|---|---|---|
claude-code | CLAUDE.md | Claude Code | Its fenced block only |
codex | AGENTS.md | Codex, and other agents that read AGENTS.md | Its fenced block only |
cursor | .cursor/rules/scarcheck.mdc | Cursor | The whole file, with alwaysApply: true; scoped lessons get globs |
cline | .clinerules/scarcheck.md | Cline | The whole file |
copilot | .github/copilot-instructions.md | GitHub Copilot | Its fenced block only |
A rules file that is a symlink to another, one file shared by two agents, is written once. Cursor and Cline get a file of their own, so Scarcheck never shares a file with your rules there. The Cursor file is always applied:
--- description: Verified lessons from Scarcheck. Generated by scar compile. alwaysApply: true --- - Use pnpm. Never npm or yarn in this repo. Fix: `pnpm add <pkg> --filter <app>`. (L-142) - API dates are UTC ISO strings. Parse with parseISO, never new Date(str). (L-131) ...
The fenced block#
In files you share with Scarcheck, it owns exactly the lines between two HTML comments. Everything above and below is yours, and scar compile never touches it.
## Testing Run `pnpm test` from the repo root before you push. <!-- scarcheck:start v1 sha=8b41e07 --> <!-- 18 lessons, 1,212 tokens. Edit .scarcheck/lessons, not this block. --> ## Scarcheck lessons - Use pnpm. Never npm or yarn in this repo. Fix: `pnpm add <pkg> --filter <app>`. (L-142) - API dates are UTC ISO strings. Parse with parseISO, never new Date(str). (L-131) - Read feature flags through flags.get(). Never import the flag SDK client directly. (L-119) ... <!-- scarcheck:end -->
- No markers yet?
scar compileappends the block at the end of the file. Move it anywhere; Scarcheck finds the markers. - Each line is the rule, the
Fix:line from the body, and the id, so anyone can look it up withscar lessons show L-142. shais a hash of what Scarcheck wrote. If the block changed since, compile skips that file and says why, so a hand edit is never lost.v1is the block format version. A newer CLI upgrades the markers in place.
Token budget#
Long rules files cost tokens on every request, and a 2026 study found context files did not improve task success on average. Each file has a budget, 1,500 tokens by default, counted with a BPE tokenizer that stays within 5% across vendors. Change it with scar config set compile.budget 1200 Planned. When verified lessons do not fit, Scarcheck ranks them:
- Repeats caught in the last 90 days, most first.
- Scope:
repo, thenorg, thenpersonal. - Then age.
Lessons that do not fit leave the text but keep their checks and guards, so a repeat is still caught. Try a smaller budget with a dry run first:
scar compile --dry-run shows the budget in use. scar status shows, on one screen, the lessons that apply in the repo, whether the rules files are up to date, and what needs you.
Expiry and review Planned#
Lessons earn their place by catching repeats. One that stops catching anything comes back to you instead of staying in context forever.
- Review date.
review_afterstarts 90 days after verification (review.after_days). Each repeat caught moves it to 90 days after that catch: L-142 caught one today, so it reviews on 2027-01-23. - Stale. A lesson goes stale with 0 hits in 90 days, when its trigger paths no longer exist, when the fact it names changed (L-088:
.nvmrcnow says 22), or when its check can no longer match anything. A changed premise holds it back from rules files at once; a quiet one stays until its review date. - Review. On its review date a lesson shows up in
scar review. Renew it for 90 more days, edit it, or archive it. - Expired. 14 days with no decision and it leaves every rules file and its checks stop.
scar review resolve L-088 --renewbrings it back after a fresh replay.
When the premise is gone for good, archive the lesson with a reason. Nothing is deleted:
Hit counts
Review dates use the hits seen on this machine and in this clone, so a lesson that only fires in CI can go stale on your laptop.