Skip to Content
harness-kit

Session start

codegraph, workspace-links and worktree-health check the session's own checkout when it starts and tell the agent what to fix.

Start every session knowing its checkout is healthy. A fresh git worktree has no installed packages, may be based on an old commit, and many of them fill a disk.

These checks look at the checkout the session works in and add what they find to the agent's context, with the command that fixes it: context. A healthy checkout adds nothing.

Never blocking

A check that cannot finish says why, and the session starts anyway.

API reference

The defaults and every option, with its type: codegraph, workspace-links, worktree-health.

Configure the session-start checks

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

/**
 * The session-start checks of a monorepo: the CodeGraph index synced, the workspace's `@acme/` packages loaded from
 * this checkout, and a worktree warned when its base is stale or the disk runs low.
 */
export default defineConfig({
  policies: [
    {
      id: 'codegraph',
      use: 'codegraph',
    },
    {
      id: 'workspace-links',
      options: {
        scope: '@acme/',
      },
      use: 'workspace-links',
    },
    {
      id: 'worktree-health',
      options: {
        lowDisk: '20 GiB',
      },
      use: 'worktree-health',
    },
  ],
});

codegraph

Keeps a CodeGraph index of the checkout current, and tells the agent to ask it before reading files. It runs codegraph sync; a checkout without an index (a fresh worktree) gets codegraph init in the background, and the context names its log.

It also screens calls of the codegraph_explore MCP tool, whose server answers from the index of the checkout the session started in. An agent in a git worktree would read another branch's code, so its call is refused until it passes the worktree as projectPath. The worktree then gets an index of its own:

  • built in the background where it has none, the call refused until it exists;
  • synced before each call, since no server watches it; a sync another call's sync turns away lets the call through with how to sync by hand.

When the checkout has no CodeGraph installed, the agent reads:

What the agent reads
CodeGraph sync skipped: /work/repository has no node_modules/.bin/codegraph. Run `npm ci` in /work/repository, then `npx codegraph sync`.

API reference

Every option of codegraph, with its type and default.

Turn it off by removing the entry.

Warns when the checkout would load another checkout's packages, so the agent would test code it did not change:

  • its node_modules is a link into another folder, or
  • a workspace package resolves, as Node would find it, to a folder other than its own (a worktree without node_modules finds the main clone's).

The context names the first such package, counts the rest, and tells the agent to run the install command there. The workspace packages are the folders the workspaces of the checkout's root package.json names, as npm and Yarn write them; a checkout that declares its workspaces elsewhere, such as pnpm's pnpm-workspace.yaml, names them with the manifests glob.

API reference

Every option of workspace-links, with its type and default.

Turn it off by removing the entry. No message of its own is quoted here: it is the context described above.

worktree-health

Warns about a linked worktree whose HEAD is neither the main checkout's nor a descendant of it, and names the git -C <worktree> merge --ff-only <sha> that brings it up. Warns when the disk holding the checkout has less than lowDisk free, listing the node_modules of every other worktree with its size and the commands that remove them.

API reference

Every option of worktree-health, with its type and default.

Turn it off by removing the entry. Like workspace-links, it adds context only.

Agents in a worktree

A subagent Claude Code starts in a worktree of its own gets no session start, so workspace-links and worktree-health also run at its first Bash or editing call from the worktree and add what they find to that call: the call goes ahead.

Once per worktree

A mark per check in the worktree's git dir keeps it to once per worktree. A call from the main checkout, which its session start already checked, costs a few file reads.

If a check times out

Claude Code stops a session-start hook after its timeout, and the checks run at the same time. Each check gets deadlineMillis (6 seconds) and its Policy 3 seconds more, time to stop a slow command and say why.

Sync after raising a deadline

A longer deadline, say for a CodeGraph sync after a large branch switch, needs harness-kit settings sync again, so the hook's own timeout grows with it.

Since these checks guard nothing, no change of their options counts as loosening a central configuration.

On this page