Quickstart
Install the CLI, set up a repo, and turn your next correction into a verified lesson that every agent reads and every commit is checked against.
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.Before you start#
You need three things. The examples use acme/web, a pnpm monorepo, but any git repo works.
- A git repository you can commit to.
- At least one agent: Claude Code, Codex, Cursor, Cline or GitHub Copilot.
- macOS or Linux on x86_64 or arm64, or Windows through WSL. Go 1.25 or later only if you build from source.
1Install the CLI#
The binary is scarcheck, with the short alias scar. Releases are built for macOS and Linux on x86_64 and arm64, starting with v0.1.0. On Windows, install inside WSL, in the same environment your agent runs in: hooks for an agent in WSL need scar inside WSL.
os=$(uname -s | tr A-Z a-z); arch=$(uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/') curl -fsSL "https://github.com/buildwithme/scarline/releases/latest/download/scarcheck_${os}_${arch}.tar.gz" | tar xz sudo mv "scarcheck_${os}_${arch}/scarcheck" /usr/local/bin/ && sudo ln -sf scarcheck /usr/local/bin/scar
git clone https://github.com/buildwithme/scarline && cd scarline/cli && go build -o ~/.local/bin/scar .
To see the whole loop first, run bash cli/demo.sh from a clone. It builds scar (Go needed), learns a lesson in a throwaway repo, catches the repeat and writes CLAUDE.md, then deletes the repo. It installs no hooks.
Check that it worked:
Shell completion for zsh, bash, fish and PowerShell: scar completion zsh Planned.
2Set up a repo#
Run scar init anywhere inside the repo. It finds the agents you already use, creates .scarcheck/, offers to import the rules you already wrote as drafts, and installs hooks. It writes nothing to your rules files until you compile.
The config is plain TOML. This is the file scar init wrote:
version = 1 repo = "acme/web" workspace = "acme" [compile] targets = ["claude-code", "codex", "cursor", "cline", "copilot"] budget = 1500 [check] timeout_ms = 3000 precommit_commands = false [hooks] suggest = "end-of-session" digest_budget = 400 [guards] fail = "open" agent_allow = false
Change a setting with scar config set compile.budget 1200 Planned, or keep it to yourself with --scope local, which writes the git-ignored .scarcheck/config.local.toml. Commit .scarcheck/. Targets and the budget are explained in Compile targets and Token budget.
3Learn your first lesson#
Work with your agent as usual. When you correct it, the Stop hook can name one commit that landed after the correction. It says this session did not record making that commit. Moving HEAD is not a fix. You name the commit:
Leave off --rule and Scarcheck drafts the rule from the commit subject. A guard is not this replay: scar learn --from-session --guard '<regex>' matches the command the hook recorded and does not claim a commit.
A merged pull request works too (--from-pr 812 Planned), and so does a test that failed before the fix and passes now (--test "pnpm vitest tz.spec.ts"). Pass --rule "..." to word the rule yourself.
No evidence, no lesson
The check has to fail before the fix. After it, the file that matched has to be gone, or read and clean. A file that was already unread can stay unread. Replacing that file with a binary, an oversized file, an excluded path, or a link is not a pass, and neither is moving those bytes onto a path the check does not read. The lesson stays a draft. Drafts never reach a rules file and never block. The full rules are in Verification.
4Write it into your rules files#
scar compile writes every verified lesson into all five rules files, ranked and trimmed to the token budget. Run it after scar learn, or pass --compile to scar learn to do both. It also rebuilds the index the agent hooks read.
Inside CLAUDE.md, the new line lands between Scarcheck's markers:
<!-- 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) ... <!-- scarcheck:end -->
Read how the block is ranked and what happens to hand edits in The fenced block and Token budget.
5Check before every commit#
If you said yes during scar init, this is done. Otherwise run scar hooks install pre-commit. The hook runs scar check --staged on staged content only. Slow command checks are left to CI.
The installer writes to the hook manager you already use:
| Manager | File | Entry |
|---|---|---|
| husky | .husky/pre-commit | scar check --staged |
| lefthook | lefthook.yml | pre-commit.commands.scarcheck.run |
| pre-commit | .pre-commit-config.yaml | hook scarcheck-check |
| none | .git/hooks/pre-commit | a script that runs any hook you had first |
If a teammate has not installed scar, the hook prints one line and lets the commit through. git commit --no-verify skips it, as usual; CI catches what it lets through.
6Check in CI Planned#
CI catches what was committed with --no-verify or from a machine without the hook. scar hooks install ci writes this workflow:
name: Scarcheck on: pull_request: push: branches: [main] permissions: contents: read jobs: lessons: runs-on: ubuntu-latest timeout-minutes: 5 steps: - uses: actions/checkout@v4 with: fetch-depth: 0 # scar check --base needs the merge base - uses: buildwithme/setup-scarcheck@v1 with: version: 0.1.0 - run: scar compile --check - run: scar check --ci ${{ github.event_name == 'pull_request' && format('--base origin/{0}', github.base_ref) || '--all' }}
Pull requests check the files they change; pushes to main check everything. scar compile --check fails the job if someone changed a lesson and forgot to compile. --ci prints workflow annotations, so a repeat shows on the exact line of the pull request diff, and writes a table to the job summary.
Any other CI: install a pinned release, then run the same two commands. --format junit feeds any CI test report, and --format sarif feeds GitHub code scanning.
# scar 0.1.3 into $HOME/.local/bin mkdir -p "$HOME/.local/bin" curl -fsSL "https://github.com/buildwithme/scarline/releases/download/v0.1.3/scarcheck_linux_amd64.tar.gz" | tar xz mv scarcheck_linux_amd64/scarcheck "$HOME/.local/bin/scar" export PATH="$HOME/.local/bin:$PATH" git fetch --no-tags origin "$CI_MERGE_REQUEST_TARGET_BRANCH_NAME" scar compile --check scar check --ci --base "origin/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME" --format junit > scarcheck.xml
7Catch repeats inside the agent#
Pre-commit catches a repeat after the agent made it. Agent hooks catch it before the tool call runs, using the lesson's block-command guard, and remind the agent of your lessons after it compacts its context. If you said yes during scar init, they are installed. Otherwise install them per agent.
Claude Code#
The installer adds five entries to .claude/settings.json, next to yours. Each runs scar hook claude-code with the event name and never uses the network:
| Event | Matcher | What it does |
|---|---|---|
SessionStart | all | Gives the agent a short digest of your lessons, again after it compacts its context. |
UserPromptSubmit | all | Notices when you correct the agent, and honours a scar:allow you type. |
PreToolUse | Bash|Write | Blocks a guarded command or a forbidden file before it runs. |
PostToolUse | Edit|MultiEdit|Write | Points out a repeat right after an edit, so the agent fixes it next. |
Stop | all | Offers one lesson candidate when the session has evidence. At most once per session. |
Every entry has the same shape. The command exits at once if scar is not installed, so a committed hook never breaks a teammate's agent:
"PreToolUse": [{ "matcher": "Bash|Write", "hooks": [{ "type": "command", "command": "command -v scar >/dev/null || exit 0; scar hook claude-code pre-tool-use", "timeout": 5 }] }]
Codex#
scar hooks install codex writes ~/.codex/config.toml. It is user level, because Codex reads one config per user, and the hook does nothing outside Scarcheck repos. A notify program you already had is kept and called after Scarcheck's.
# Added by scar hooks install codex. Remove with: scar hooks uninstall codex notify = ["scar", "hook", "codex", "notify"] [[hooks.session_start]] command = ["scar", "hook", "codex", "session-start"] [[hooks.user_prompt_submit]] command = ["scar", "hook", "codex", "user-prompt-submit"] [[hooks.pre_tool_use]] matcher = "shell|apply_patch" command = ["scar", "hook", "codex", "pre-tool-use"] timeout_ms = 5000 [[hooks.stop]] command = ["scar", "hook", "codex", "stop"]
The installer reads codex --version and writes the hook tables that version supports. Older Codex versions get the notify line only: corrections are still recorded, but there is no block inside Codex, so pre-commit and CI catch the repeat.
Try a guard without starting an agent Planned. scar hooks test will send one fake event through the installed hook and print what the agent would receive:
What the agent sees#
When a guard matches, the hook exits with code 2 and writes six lines to stderr: the lesson, the blocked command, the command to run instead, why, and the only legitimate way past it. Claude Code cancels the call and hands the text to the agent. You see the same text under the tool call, so nothing happens behind your back:
Agents cannot allow themselves. If you want an exception, reply scar:allow L-142 <reason> in your next prompt: it allows the next matching command once, within 10 minutes, and is recorded with who, when and why. The status line at the bottom is optional: scar hooks install claude-code --statusline Planned.
Each block counts as a repeat caught and pushes the lesson's review date 90 days out. Guards are written in the lesson file; see block-command.
Troubleshooting#
Start with scar doctor. It checks every piece this guide set up, says how to fix each problem, and changes nothing unless you pass --fix, which applies only the fixes it lists as safe.
The agent hook never fires#
Agents started from a GUI app get a short PATH. If scar is in a folder only your shell knows about, the hook cannot find it and lets everything through. Run scar hooks install for that agent again with --absolute-path to pin the full path, then check with scar hooks status.
Compile says the block was edited by hand#
Someone changed a line between the markers, so scar compile skipped that file rather than overwrite the edit (SC020). Move the text above the scarcheck:start line and compile again, turn it into a lesson with scar learn, or discard it with scar compile --force. Details in The fenced block.
Next steps#
You have a verified lesson, read by five agents and checked in three places. From here: