Formatting
format-on-edit formats each file the agent edits with the project's own formatter, and never blocks.
Get every file the agent edits formatted by your project's formatter, so diffs stay clean and lint does not fail at the end of the turn. format-on-edit runs the formatter on the one file an Edit, MultiEdit or Write changed, right after the change.
Never blocking
API reference
format-on-edit.Format edited files
Vite+ projects
A project formatted through Vite+ (vp fmt) should write out a formatter that runs vp fmt, as the example does: the oxfmt preset does not read the fmt block of vite.config.ts.
Name the formatters your project uses. The first one that takes the edited file runs:
import { defineConfig } from '@microeinhundert/harness-kit';
/**
* Every edited file formatted by the first formatter that takes it: Ruby by standardrb where the project uses it,
* TypeScript by the project's own `vp fmt`, and everything else by Prettier.
*/
export default defineConfig({
policies: [
{
id: 'format',
options: {
deadlineMillis: 10_000,
formatters: [
{
preset: 'standardrb',
},
{
glob: ['**/*.ts', '**/*.tsx'],
missingHint: 'run npm ci; a fresh worktree has no node_modules',
run: ['node_modules/.bin/vp', 'fmt', '{file}'],
whenFile: 'vite.config.ts',
},
{
preset: 'prettier',
},
],
},
use: 'format-on-edit',
},
],
});The formatter must be installed first: a program below node_modules/ needs npm ci (or your package manager's install) in the checkout.
What the agent reads
Nothing: allow. The file is formatted in place, with the hook's PATH, and the formatter's output and exit code are ignored.
When the program is missing, cannot start or outlasts deadlineMillis (10 seconds), a note goes to standard error, which Claude Code shows in its transcript view:
format-on-edit: node_modules/.bin/prettier is missing, so the edited file was not formatted; run `npm ci`; a fresh worktree has no node_modules.A file that is missing, not a regular file or outside the Policy's folder (a symbolic link out of it included) is left alone. A program below node_modules/ is looked up in every folder the project's package manager installs into, so pnpm's layout works too.
Turn it off
Remove the entry. Since it guards nothing, no change of its options counts as loosening a central configuration.
Choose and write formatters
formatters is a list; the first formatter that takes the edited file runs. A formatter takes a file when its glob (one glob or a list, relative to the Policy's folder) matches it and, if it names a whenFile, the folder holds that file.
| Preset | Runs | Takes |
|---|---|---|
prettier | node_modules/.bin/prettier --write --ignore-unknown | every file |
biome | node_modules/.bin/biome format --write | where biome.json is |
oxfmt | node_modules/.bin/oxfmt --write | every file; reads only .oxfmtrc.json or .oxfmtrc.jsonc |
standardrb | standardrb --fix, behind bundle exec with a Gemfile.lock | Ruby files, where .standard.yml is |
rubocop | rubocop --autocorrect, behind bundle exec with a Gemfile.lock | Ruby files, where .rubocop.yml is |
gofmt | gofmt -w | Go files |
ruff | ruff format | Python files |
A preset's glob and whenFile can be replaced in the entry. To write a formatter out:
| Option | What it does |
|---|---|
run | the program and its arguments; one must hold {file}, the edited file's absolute path |
glob | one glob or a list, relative to the Policy's folder, of the files it takes |
whenFile | a file the folder must hold for it to take a file |
wrapIf | { file, prefix }: a prefix before the command where the folder holds a file |
missingHint | what to do when the program is missing |
{file} keeps every formatter on the one edited file, never the whole repository.
Related
- Debugging a configuration:
harness-kit explaindoes not format, since formatting happens after the answer. - Troubleshooting: the common messages and how to clear them.
Paths and new files
protected-paths, generated-paths, allowed-paths and new-file keep files where they belong and out of the agent's reach.
Stop checks and hand-off
stop-command, work-saved and the hand-off checks keep the agent working until lint passes, the work is saved and the pull request and issue tell the truth.