Skip to Content
harness-kit

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

It allows every call and formats once the call is answered.

API reference

The defaults and every option, with its type: 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:

harness.config.ts
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:

What the session shows
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.

PresetRunsTakes
prettiernode_modules/.bin/prettier --write --ignore-unknownevery file
biomenode_modules/.bin/biome format --writewhere biome.json is
oxfmtnode_modules/.bin/oxfmt --writeevery file; reads only .oxfmtrc.json or .oxfmtrc.jsonc
standardrbstandardrb --fix, behind bundle exec with a Gemfile.lockRuby files, where .standard.yml is
rubocoprubocop --autocorrect, behind bundle exec with a Gemfile.lockRuby files, where .rubocop.yml is
gofmtgofmt -wGo files
ruffruff formatPython files

A preset's glob and whenFile can be replaced in the entry. To write a formatter out:

OptionWhat it does
runthe program and its arguments; one must hold {file}, the edited file's absolute path
globone glob or a list, relative to the Policy's folder, of the files it takes
whenFilea 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
missingHintwhat to do when the program is missing

{file} keeps every formatter on the one edited file, never the whole repository.

On this page