Skip to Content
harness-kit

The configuration

Where harness-kit finds its configuration, how entries are written, how a repository extends a central configuration, and how a person loosens one Policy on purpose.

How do I read and shape the file that decides which guardrails a repository has? The configuration is a TypeScript module whose default export is typed by defineConfig, or the same object as JSON. Its policies list holds one entry per guardrail. This page goes from one entry to presets, scoping, a shared central configuration and personal overrides.

defineConfig also types each entry's options by the built-in Policy its use names, so options of the wrong shape fail the type check.

A typo fails loudly

The kit decodes the configuration on every hook call and refuses a key it does not know, so a misspelt option never leaves a Policy looser than written.

Where it is found

  • harness-kit looks for harness.config.ts or harness.config.json in the repository root, the top of the git working copy Claude Code runs in. Having both is an error.
  • Every command takes --config <path> to use another file, which is how a plugin passes its own.
  • In a git worktree, the worktree's own root counts, so each worktree can be on its own version of the configuration.

Turn on a Policy with an entry

An entry is a plain object that names a built-in Policy:

FieldRequiredWhat it does
useyesThe built-in Policy, such as command-policy or stop-command.
idyesThis entry's name, unique in the configuration.
optionsdependsThe Policy's options. Unknown options fail the configuration.
failModenoopen or closed, replacing the Policy's default.
timeoutMillisnoIts timeout in milliseconds, replacing the default.
stacknoRun only where the folder belongs to this stack, and work in that folder.
whenFilenoRun only below a folder that holds this file, and work in that folder.
overridenoLet a person loosen this one Policy (overrides).

A configuration may use one built-in Policy in several entries, each with its own id and options, such as two command-policy tables for two tools.

Presets

A preset is ready-made data for a common tool. A preset is never code of its own, so a field written beside it replaces the preset's:

  • Command tables for command-policy: preset: 'kubectl', preset: 'helm', preset: 'package-manager' and more (Commands).
  • Formatters for format-on-edit: preset: 'prettier', preset: 'biome', preset: 'gofmt' and more (Formatting).
  • GIT_CONVENTIONS, the git Policies with their defaults, which you spread into policies. An id names one entry of a file, so change one of its entries by mapping over the preset, or filter it out and write your own (Git and forge); a second entry with the same id is an error, not an override.

The presets reference lists them all with their values.

Scope an entry to part of a monorepo

stack and whenFile scope an entry to part of a monorepo (the stack names come from Projects and stacks). The Policy then runs where the nearest folder up from the file a call touches holds the stack's marker or that file, and works there; elsewhere it lets the call through without running:

harness.config.ts
import { defineConfig } from '@microeinhundert/harness-kit';

/**
 * Entries scoped to a part of a monorepo: the Ruby formatter runs only where a folder holds a `Gemfile` (the `ruby`
 * stack), and the migration guard only below a folder that holds `bin/rails`.
 */
export default defineConfig({
  policies: [
    {
      id: 'format-ruby',
      options: {
        formatters: [
          {
            preset: 'standardrb',
          },
        ],
      },
      stack: 'ruby',
      use: 'format-on-edit',
    },
    {
      id: 'migrations',
      options: {
        glob: 'db/migrate/*.rb',
        nameRegex: '^(\\d{14})_',
      },
      use: 'new-file',
      whenFile: 'bin/rails',
    },
  ],
});

Extending a central configuration

A team keeps one configuration every repository starts from. A repository names it with extend, a path relative to the file, and may then only tighten it:

  • every Policy of the extended configuration stays;
  • an entry with the same id must use the same Policy, and may close its fail mode, lengthen its timeout, and change options only where that makes the Policy stricter (add protected paths, narrow allowed ones);
  • entries with new ids add Policies.
central.config.ts
import { defineConfig } from '@microeinhundert/harness-kit';

/**
 * A central configuration every repository of a team extends: every edit of a lockfile is refused, and work is
 * committed and pushed before an agent stops.
 */
export default defineConfig({
  policies: [
    {
      id: 'lockfiles',
      options: {
        paths: ['**/package-lock.json', '**/pnpm-lock.yaml'],
      },
      use: 'protected-paths',
    },
    {
      id: 'work-saved',
      use: 'work-saved',
    },
  ],
});
harness.config.ts
import { defineConfig } from '@microeinhundert/harness-kit';

/**
 * A repository's configuration that extends the central one: it keeps every Policy of it, tightens two of them (one
 * more protected lockfile, and a `work-saved` that fails closed), and adds a stop check of its own.
 */
export default defineConfig({
  extend: './central.config.ts',
  policies: [
    {
      id: 'lockfiles',
      options: {
        paths: ['**/package-lock.json', '**/pnpm-lock.yaml', '**/bun.lock'],
      },
      use: 'protected-paths',
    },
    {
      failMode: 'closed',
      id: 'work-saved',
      use: 'work-saved',
    },
    {
      id: 'lint',
      options: {
        run: 'npm run lint',
        whenChanged: ['src/**'],
      },
      use: 'stop-command',
    },
  ],
});

An entry that loosens the central configuration, such as dropping a protected path or opening a closed Policy, fails the whole configuration and names each loosening. The extended configuration's own files are protected from the agent just like the repository's.

Overrides: a person loosens one Policy on purpose

Overrides are for one person, on one machine. Sometimes a person needs to do what a Policy refuses: run a production kubectl command, regenerate a lockfile by hand. An entry's override lets them, without editing the configuration and without letting the agent do it:

harness.config.ts
import { defineConfig } from '@microeinhundert/harness-kit';

/**
 * Two ways a person, never the agent, loosens one Policy on purpose: `kubectl` lets through what it refuses while the
 * session was started with `ALLOW_KUBECTL=1`, and `lockfiles` while the user's own allow file names it.
 */
export default defineConfig({
  policies: [
    {
      id: 'kubectl',
      options: {
        preset: 'kubectl',
      },
      override: {
        env: 'ALLOW_KUBECTL',
      },
      use: 'command-policy',
    },
    {
      id: 'lockfiles',
      options: {
        paths: ['**/package-lock.json'],
      },
      override: {
        allowFile: '~/.config/harness-kit/allow.txt',
      },
      use: 'protected-paths',
    },
  ],
});
  • env names an environment variable. When it is set to anything but empty or 0 in the environment Claude Code was started with (ALLOW_KUBECTL=1 claude), the Policy's refusals become notes. A NAME=value written in front of a command by the agent is never read.
  • allowFile names a file in the user's home folder (~/…). A line holding the Policy's id lets its refusals through. A file inside the project is never read, so the agent cannot write one.

The refused call then goes through, and the agent reads what was let through:

What the agent reads
Override: the environment variable ALLOW_KUBECTL lets through what Policy kubectl refuses (`kubectl delete pod web-1` is refused: `delete` is on the deny list of the kubectl command table.).

An extending configuration may not add an override; only the configuration that defines a Policy may.

Every key of a configuration

KeyWhat it holds
policiesThe entries, each turning on one Policy. The only key most configurations need.
extendA configuration this one tightens (extending).
adaptersThe forge, the tracker and executables of the protocol (Adapters).
projectsWhere the project catalog comes from.
stacksHow a folder's stack is detected.
gatesExtra gates derived from the repository's files.
packageManagerThe project's package manager, when detecting it is not wanted.
trackerSettings of harness-kit tracker: the title rule and the duplicate window.
hookBinWhere the hook entries find the kit, when it is not in the project's own node_modules.

The configuration reference lists each with its schema.

On this page