Quick start
Write a first harness.config.ts, turn the hooks on, and watch a call being refused.
You'll: write a first configuration, turn the hooks on, and watch the agent being refused when it tries to delete a Kubernetes pod.
Before you start
Write the configuration
Create harness.config.ts at the root of the repository:
import { defineConfig, GIT_CONVENTIONS } from '@microeinhundert/harness-kit';
/**
* A team's first configuration: the git conventions preset, kubectl kept read-only by a command preset, and every
* edited TypeScript file formatted with Prettier.
*/
export default defineConfig({
policies: [
...GIT_CONVENTIONS,
{
id: 'kubectl',
options: {
preset: 'kubectl',
production: ['^prod-'],
},
use: 'command-policy',
},
{
id: 'format',
options: {
formatters: [
{
glob: '**/*.ts',
preset: 'prettier',
},
],
},
use: 'format-on-edit',
},
],
});Each entry turns on one built-in Policy: use names it, id names this entry, options configure it. defineConfig types the options, so your editor completes them and the type check refuses a wrong shape. GIT_CONVENTIONS is a preset: ready-made git entries you spread in.
Check it
npx harness-kit config checkIt loads the configuration the way a hook does and names every problem with its fix. A misspelt option is an error, so a typo never loosens a guardrail silently. For example:
The harness configuration harness.config.ts is invalid: the options of kubectl do not decode (Expected no excess property
at ["bogus"]).
Fix: Correct harness.config.ts, then run `harness-kit config check` until it passes.Turn the hooks on
npx harness-kit settings syncThis writes the hook entries into .claude/settings.json and leaves every other setting as it was. Commit harness.config.ts and .claude/settings.json together.
See it work
Start Claude Code in the repository and ask the agent to delete the pod web-1. The hook refuses, and the agent reads why and what to do instead:
`kubectl delete pod web-1` is refused: `delete` is on the deny list of the kubectl command table.
Fix: Do not run it; if it is needed, ask the developer to run it by hand.Fail CI when the settings drift from the configuration
Add a CI step that fails when .claude/settings.json no longer matches the configuration, for example after someone adds a Policy and forgets to sync:
npx harness-kit settings checkTry it without an agent
To test a call without starting Claude Code, save a hook payload (the JSON Claude Code would send) and let harness-kit explain show which Policies run and what each decides:
echo '{"session_id":"try","transcript_path":"","cwd":"'"$PWD"'","hook_event_name":"PreToolUse","tool_name":"Bash","tool_input":{"command":"kubectl delete pod web-1"}}' > payload.json
npx harness-kit explain < payload.jsonPreToolUse of Bash in session try
- kubectl denies (20.9 ms): `kubectl delete pod web-1` is refused: `delete` is on the deny list of the kubectl command table.
Fix: Do not run it; if it is needed, ask the developer to run it by hand.
- branch-name allows (31.2 ms)
- self-protection allows (45.6 ms)
- hook-bypass allows (47.7 ms)
…
The hook exits with 2 and writes to standard error:
`kubectl delete pod web-1` is refused: `delete` is on the deny list of the kubectl command table.
Fix: Do not run it; if it is needed, ask the developer to run it by hand.self-protection and hook-bypass appear although the configuration does not name them: they run in every configuration, so the agent cannot switch the guardrails off (Protection).
Next
You have a working guardrail. Add the ones your team needs by picking a recipe and pasting its configuration in.
To learn what happens behind the refusal, read How a hook call is decided. To look up an option, use the API reference. If something fails, see Troubleshooting.