Stanza

Existing Codebases

Hold new changes to the rules without reformatting old code.

In a repository whose existing code does not follow the rules, a hook that checks whole files flags code nobody touched, and a Stop pass rewrites it. --hunks narrows a run to the lines you changed, so new work follows the rules and old code stays as it is until someone edits it.

Hooks

Add --hunks to the command in each hook:

.claude/settings.json
{
  "hooks": {
    "PreToolUse": [
      { "matcher": "Write", "hooks": [{ "type": "command", "command": "stanza hook --hunks" }] }
    ],
    "PostToolUse": [
      {
        "matcher": "Edit|MultiEdit",
        "hooks": [{ "type": "command", "command": "stanza hook --hunks" }]
      }
    ],
    "Stop": [{ "hooks": [{ "type": "command", "command": "stanza hook --hunks" }] }]
  }
}

The Stop pass, and the pass after each Edit or Codex patch, then fix only around the lines changed against HEAD, and the pre-commit hook checks only the lines the commit changes. On Write, Claude Code formats only new files, since the Write replaces a whole file and a file already tracked in HEAD is left to the Stop pass.

From the Command Line

stanza --check --changed --hunks
stanza --fix --changed --hunks

What Counts as Changed

A rule applies to a blank line when a statement next to it, or the blank line itself, is on a changed line. Braces come off a body only when the block holds a changed line or sits next to such a gap. A file that is not tracked yet counts as changed throughout. Braces Stanza removed do not count as a change, so a second run changes nothing. The exact rules are under Hunks.

Fixing Staged Lines

--fix has no staged line scope. When the pre-commit hook finds something in a file where only part of the file is in scope, it lists that file on stderr to fix by hand and restage with git add -p, instead of printing a command that would rewrite the whole file.

Dropping --hunks

To bring the whole codebase in line at once, run stanza --fix . from its root, commit the result on its own, and remove --hunks from the hooks.

On this page