---
title: "Reference"
description: "Every command, config key and file."
canonical_url: "https://www.harness-sdk.dev/harnessd/docs/reference"
markdown_url: "https://www.harness-sdk.dev/harnessd/docs/reference.md"
x_farming_labs_generated_preamble: true
---

# Reference
URL: /harnessd/docs/reference
LLM index: /llms.txt
Description: Every command, config key and file.

## CLI

| Command | What it does |
| --- | --- |
| [`harnessd service install`](#harnessd-service-install) | Starts harnessd now and at every login. With `sudo`, at every boot. |
| [`harnessd service uninstall`](#harnessd-service-uninstall) | Stops harnessd and removes its service. |
| [`harnessd start`](#harnessd-start) | Starts Claude Code after a stop. |
| [`harnessd stop`](#harnessd-stop) | Stops Claude Code until `start`. |
| [`harnessd status`](#harnessd-status) | Shows what runs. |
| [`harnessd attach`](#harnessd-attach) | Opens Claude Code's terminal. |
| [`harnessd tools <server>`](#harnessd-tools) | Runs a server's tools. |

### harnessd service install

```sh
harnessd service install        # a login item: starts when you log in
sudo harnessd service install   # a boot service: starts when the machine boots
```

It writes a first config file with today's `compatibilityDate`, creates the agent's folder, registers harnessd with launchd or systemd, and waits until Claude Code runs. Run again, it restarts harnessd, and the conversation resumes.

| Flag | What it does |
| --- | --- |
| `--user <name>` | With `sudo`: the user the boot service runs as. The default is the user who ran `sudo`. Never `root`. |
| `--dry-run` | Prints the service's file and changes nothing. |
| `--install-claude` | Installs Claude Code without asking when it is missing. |
| `--skip-sign-in` | Installs even when Claude Code isn't signed in, and prints how to sign in. |

Install checks two things first: that Claude Code is installed, and that it is signed in. On a terminal it offers to fix each. On a no, or from a script, it installs nothing and exits `1`, unless the matching flag is set. [Install](/harnessd/docs/setup#sign-in) has the details.

### harnessd service uninstall

Stops harnessd and Claude Code and removes the service. Use `sudo` for a boot service, with `--user <name>` when you named one. The config file, the conversation and the agent's folder stay, so a later install resumes.

### harnessd start

Starts Claude Code after a stop, in the same conversation. It waits until Claude Code runs. When it doesn't, it prints the log's last lines and exits `1`.

### harnessd stop

Stops Claude Code. harnessd itself stays up and answers `status`. Claude Code stays stopped, across reboots and installs, until `harnessd start`.

### harnessd status

```text
$ harnessd status
harnessd 612: Claude Code running for 3h (pid 4821)
conversation 6a0f3c1e-8f0b-4c58-9a57-2f1d6c0e7b11 in /Users/you/agent
server board: the board command, events task.handed, session.message (https://board.example.com/api/board/mcp)
channel: events arriving
  board task.handed --board main
  board session.message
log /Users/you/.local/state/harnessd/harnessd.log
  2026-12-01T16:04:16.530Z starting Claude Code: resuming conversation 6a0f3c1e-…
```

It shows what runs, the conversation, each server with the events the channel takes from it, the channel, and the log's last 10 lines. It exits `0` when harnessd runs and `1` when it doesn't. `--json` prints the same as [one JSON object](/harnessd/docs/reference#harnessd-status---json).

### harnessd attach

Opens Claude Code's terminal. You see the agent's screen and type to it. `Ctrl-\` leaves, and Claude Code keeps running. It needs a terminal.

### harnessd tools

```sh
harnessd tools board --help    # the board's tools
harnessd tools board login     # sign in, when the server asks for OAuth
```

The same command the agent runs as `board`. Its tools are its subcommands, with flags from each tool's input schema. It reads the server's `url` and `headers` from the config file, and `${VAR}` in a header from your environment. `--help` after the server's name is the server's help, not harnessd's.

### The rest

- `harnessd --version` prints the version. `harnessd help`, or `--help` after any command, prints the commands.
- `/clear` in Claude Code starts a new conversation. harnessd [follows it](/harnessd/docs/concepts#start-a-new-conversation).
- `harnessd run`, `harnessd channel` and `harnessd session-start` are internal. harnessd and Claude Code call them.
- A command refuses an argument it doesn't know: it exits `2` and runs nothing. Any other error exits `1`.
- Every command reads the same [config file and state folder](/harnessd/docs/reference#environment-variables). `XDG_CONFIG_HOME` and `XDG_STATE_HOME` move them, and `HARNESSD_HOME` puts both in one folder.

## Config

### Config file

`~/.config/harnessd/config.json`, read before every start of Claude Code. An unknown key or a wrong type fails the start.

An example with every key:

```json
{
  "compatibilityDate": "2026-12-02",
  "folder": "~/agent",
  "args": ["--model", "opus"],
  "env": { "CLAUDE_CONFIG_DIR": "/Users/you/.claude-agent" },
  "prestart": "./fetch-secrets.sh",
  "servers": {
    "board": {
      "url": "https://board.example.com/api/board/mcp",
      "headers": { "Authorization": "Bearer ${BOARD_TOKEN}" }
    }
  },
  "channel": {
    "subscribe": [
      { "server": "board", "event": "task.handed", "arguments": { "board": "main" } },
      { "server": "board", "event": "session.message" }
    ]
  },
  "accounts": {
    "main": {},
    "spare": { "env": { "CLAUDE_CODE_OAUTH_TOKEN": "…" } }
  }
}
```

| Key | Type | Default | What it sets |
| --- | --- | --- | --- |
| `compatibilityDate` | string, required | Today's date in the file `service install` writes | The date the file was written, as `YYYY-MM-DD`. harnessd behaves as it did on that date. |
| `folder` | string, required | `"~/agent"` in the file `service install` writes | The agent's folder. `~` is your home folder. harnessd creates it and marks it trusted in Claude Code. |
| `args` | string[] | `[]` | Extra arguments for `claude`. `["--dangerously-skip-permissions"]` turns permission prompts off; the default is auto mode. |
| `env` | object of strings | `{}` | Extra environment for `claude`. |
| `prestart` | string | none | A shell command run before each start. |
| `servers` | object | `{}` | MCP servers by name. Each server's tools become a command of that name for the agent. |
| `channel` | object | `{ "subscribe": [] }` | The one channel: which servers' events reach the agent. |
| `accounts` | object | `{}` | Claude accounts the agent can run on, by name, in the order harnessd tries them. |
| `heartbeat` | object or `false` | `{ "everySeconds": 3300 }` | How often harnessd checks that the agent still answers. `false` turns the heartbeat off. |

#### `servers.<name>`

| Field | Type | What it sets |
| --- | --- | --- |
| `url` | string, required | The MCP server, over Streamable HTTP. `https`, or `http` on `localhost`, `127.0.0.1` or `[::1]`. |
| `headers` | object of strings | Headers for every request. `${VAR}` reads the environment. A variable that isn't set is an error. |

- A server's name starts with a lowercase letter and holds up to 32 lowercase letters, digits and dashes.
- The name is a command in Claude Code's shell, ahead of any other command of that name: `board --help` lists the board's tools.
- A server with no subscriptions sends no events. Its tools still work.

#### `channel.subscribe`

A list of the events that reach the agent. No other event does.

| Field | Type | What it sets |
| --- | --- | --- |
| `server` | string, required | One of `servers`. |
| `event` | string, required | One of the server's push event types. |
| `arguments` | object of strings, numbers or booleans | The subscription's arguments, as the event type declares them. |

- The same event can be listed more than once, with different arguments. The same event with the same arguments is an error.
- An event the server doesn't offer, or arguments it doesn't take, is a line in the log, and harnessd tries again with the usual wait.

#### `accounts.<name>`

| Field | Type | What it sets |
| --- | --- | --- |
| `env` | object of strings | The environment that signs Claude Code in to this account, such as `CLAUDE_CODE_OAUTH_TOKEN`. It can't set `CLAUDE_CONFIG_DIR`. Without it, the account signs in the way the config file's `env` does, or with the Mac's own sign-in. |

An account's name starts with a lowercase letter and holds up to 32 lowercase letters, digits and dashes.

#### `heartbeat`

| Field | Type | What it sets |
| --- | --- | --- |
| `everySeconds` | whole number | How long the agent may go without a tool call through harnessd or a turn's end before it gets a heartbeat, and how long its answer may take. 3300 (55 minutes) by default, at least 60. |

#### `prestart`

- Runs with `/bin/sh -c` in the agent's folder, with the environment Claude Code is about to get. With accounts, `HARNESSD_ACCOUNT` holds the name of the account this start uses.
- Has 60 seconds.
- Prints nothing, or one JSON object: `{ "env": { "NAME": "value" }, "args": ["--flag"] }`. Both keys are optional. Any other key is an error.
- Its `env` and `args` apply to that start only.
- It can't set `CLAUDE_CONFIG_DIR`. Set that in the config file's `env`.
- Lines it writes to stderr go to the log.
- A non-zero exit, a timeout or bad JSON fails the start. harnessd retries with the usual wait and keeps the conversation.

### Files

harnessd follows the XDG convention: the config file sits in `~/.config/harnessd`, and everything harnessd writes sits in its state folder, `~/.local/state/harnessd`. Only your user can read the two folders and the config file.

| Path | What it holds |
| --- | --- |
| `~/.config/harnessd/config.json` | The config file. |
| `~/.local/state/harnessd/state.json` | The conversation's id, the account in use, and whether the agent is stopped. |
| `~/.local/state/harnessd/harnessd.log` | The log. Past 5 MB it moves to `harnessd.log.1`. |
| `~/.local/state/harnessd/service.log` | What harnessd itself prints, such as why it couldn't start. |
| `/var/log/harnessd/<id>.log` | The boot service's `service.log`, named by a short hash of the state folder. |
| `~/.local/state/harnessd/harnessd.sock` | The socket the commands use. |
| `~/.local/state/harnessd/channel.json` | Where each subscription's events resume. |
| `~/.local/state/harnessd/auth/` | Sign-ins made with `harnessd tools <server> login`. |
| `~/.local/state/harnessd/plugin/` | harnessd's Claude Code plugin: the channel, a command per server in `bin/`, and a `SessionStart` hook that tells harnessd the conversation. Written at every start. |
| `~/Library/LaunchAgents/dev.harnessd.plist` | The login item's launchd entry, on macOS. |
| `~/.config/systemd/user/harnessd.service` | The login item's systemd user unit, on Linux. |
| `/Library/LaunchDaemons/dev.harnessd.<user>.plist` | The boot service's launchd entry, on macOS. |
| `/etc/systemd/system/harnessd-<user>.service` | The boot service's systemd unit, on Linux. |

### Environment variables

| Variable | What it does |
| --- | --- |
| `XDG_CONFIG_HOME` | Moves the config file to `$XDG_CONFIG_HOME/harnessd/config.json`. |
| `XDG_STATE_HOME` | Moves the state folder to `$XDG_STATE_HOME/harnessd`. Each state folder is its own harnessd with its own launchd or systemd entry, so one machine can run several agents. |
| `XDG_RUNTIME_DIR` | Holds the socket when the state folder's path is too long for one (macOS allows 104 bytes). Without it, that socket goes in `/tmp/harnessd-<uid>`. |
| `HARNESSD_HOME` | Puts the config file and the state folder in this one folder. It wins over the XDG variables. |
| `CLAUDE_CONFIG_DIR` | Set in the config file's `env`, it moves where Claude Code keeps its settings and conversations. |

Every command reads the first four. `harnessd service install` hands them to launchd or systemd, and harnessd hands them to Claude Code, the channel and the servers' commands. Run the other commands with the same ones.

## Behavior

harnessd 0.1.0, npm package `@harness-sdk/harnessd`. It runs on macOS, and on Linux with systemd (x64 or arm64, glibc), with Node.js 20.19 or newer and needs the `claude` command on `PATH` or in `~/.local/bin`.

### The `claude` command

harnessd runs `claude` in the agent's folder with these arguments, in this order:

```text
claude --permission-mode auto               unless your args pick a permission mode
       --plugin-dir <state folder>/plugin
       --dangerously-load-development-channels plugin:harnessd@inline    when the channel subscribes to events or the heartbeat is on
       --resume <id> | --session-id <id>    resume, or a new conversation
       "<first message>"                    when it resumes
       <args from the config file>
       <args from prestart>
```

The environment is harnessd's own, then the config file's `env`, then the account's `env` and `HARNESSD_ACCOUNT`, then `HARNESSD_HOME`, `XDG_CONFIG_HOME` and `XDG_STATE_HOME` as harnessd read them, then `prestart`'s `env`. Later ones win. `PATH` then starts with the folder of the servers' commands. harnessd's own environment holds the `PATH` of the shell that ran `harnessd service install`, with the folders of `claude` and `node` added when it lacks them. A boot service also gets the user's `HOME`, `USER` and `LOGNAME`.

### Restarts

| Rule | Value |
| --- | --- |
| First wait after an exit | 5 seconds |
| Each further wait | Twice the last, up to 5 minutes |
| A run that resets the wait | 10 minutes |
| A resumed run that counts as a failed resume | Exits within 30 seconds. The next start is a new conversation. |
| A start with no saved history for the conversation | A new conversation |

The conversation a start resumes is the one Claude Code was last in. harnessd's plugin hooks Claude Code's `SessionStart`, so after `/clear`, `/resume` or a fork, harnessd follows the conversation Claude Code moved to, for restarts and account switches alike. It was checked against Claude Code 2.1.334.

A start that resumes the conversation opens with the message `harnessd restarted Claude Code: <reason>. This is the same conversation.` A new conversation gets no such message.

### Accounts

- A start runs on the account the last start ran on, while that account can go on. Otherwise it runs on the first account in the config's order that can.
- The start's environment gets the account's `env` on top of the config file's `env`, and `HARNESSD_ACCOUNT` with the account's name.
- With two or more accounts, harnessd reads the conversation's new lines every 10 seconds, and once more when Claude Code exits. It was checked against Claude Code 2.1.334.

| Claude Code reports | harnessd leaves the account alone |
| --- | --- |
| A usage limit (`rate_limit` with HTTP 429, not marked transient) | Until the reset time in the report. Without one, or with one in the past, 5 hours. |
| A failed sign-in (`authentication_failed`) | For 24 hours |

- A stopped account is tried again early when its `env` in the config file changes.
- harnessd keeps the list of stopped accounts in memory. Restarting harnessd clears it.
- When another account can go on, harnessd restarts Claude Code on it at once and resumes the conversation, with the message `harnessd restarted Claude Code: account <name> stopped at <reason>, so Claude Code now runs on account <next>. This is the same conversation.`
- When none can, Claude Code stays on the current account.

### Heartbeat

- When `everySeconds` pass with no tool call through harnessd and no turn's end, harnessd sends a heartbeat on the channel: `<channel source="plugin:harnessd:channel" event="heartbeat">`.
- The agent answers with the channel's `ack_heartbeat` tool. A call of any server's command, or the end of a turn, answers too.
- Unanswered after another `everySeconds`, harnessd restarts Claude Code in the same conversation, with the message `harnessd restarted Claude Code: it didn't answer a heartbeat within <interval>. This is the same conversation.`
- It waits another `everySeconds` instead while the conversation's transcripts, its subagents' included, or Claude Code's screen changed since the heartbeat.
- It also waits while Claude Code waits at a prompt harnessd knows for a person, such as a sign-in or a tool's permission prompt. Those never restart.
- A dialog harnessd doesn't recognise counts as a freeze: still on screen at the deadline, with nothing else changing, Claude Code is restarted. The message adds `, with a dialog harnessd doesn't recognise on screen`.
- The heartbeat needs the channel. When managed settings refuse channels, no heartbeat is sent and nothing restarts.

### Prompts

harnessd reads Claude Code's screen and answers these prompts. It was checked against Claude Code 2.1.334.

| Prompt | Answer |
| --- | --- |
| Choose the text style | Enter, which keeps the default |
| Security notes | Enter |
| Accessing workspace: is this a project you trust? | Yes, I trust this folder |
| WARNING: Claude Code running in Bypass Permissions mode (only when your `args` hold `--dangerously-skip-permissions` or `--permission-mode bypassPermissions`) | Yes, I accept |
| WARNING: Loading development channels (every start with subscriptions or the heartbeat on, when it lists only `plugin:harnessd@inline`) | I am using this for local development |
| Detected a custom API key in your environment | Yes |
| Allow external CLAUDE.md file imports? | Yes, allow external imports |
| What do you want to do? (at a usage limit) | Wait here, then continue automatically |
| Autocompact now defaults to 400k tokens | Apply (all models), the default |
| Select login method | None. A person signs in. |
| A tool's permission prompt ("Do you want to proceed?") | None. A person approves it. The status names what asks: `permission: Bash command`. |
| Any other screen that ends with "Enter to confirm" | None. A person answers. Still there at a heartbeat's deadline, with nothing changing, it restarts Claude Code. |

- harnessd reads the screen once Claude Code's output has been quiet for half a second.
- It answers the same prompt up to 3 times per start. After that the prompt waits for a person.
- Each answer is a line in the log: `answered Claude Code's prompt: <name>`.
- harnessd recognizes only the screens in this table. At any other screen it types nothing, and the status names no prompt.
- A prompt that waits for a person is a line in the log and in `harnessd status`: `Claude Code waits for an answer (<name>): harnessd attach, then answer it`.

### The channel

- The channel runs as a local MCP server inside Claude Code, `harnessd channel`. It follows each subscription in `channel.subscribe` with its own `events/stream`, and nothing else.
- An event arrives as `<channel source="plugin:harnessd:channel" server="<server>" event="<event name>" delivery="<id>">`. The text is the event's `text` field, or else its data as JSON. The data's other text, number and boolean fields become attributes.
- harnessd saves an event's cursor once the event shows in the conversation, for each subscription. After a restart each subscription asks for events from its cursor. A subscription that is new, or whose arguments changed, starts from now.
- When the server no longer has the missed events, the agent gets `Some <event> events were missed (<server> no longer had them): read its state again.`
- When an event stream ends, or the server refuses the subscription, harnessd follows it again after 5 seconds, doubling up to 5 minutes. The log names the subscription and why.
- The channel serves one tool, `ack_heartbeat`, which answers a heartbeat. The agent answers events with the servers' commands.

#### How Claude Code loads it

- harnessd writes its plugin on the machine before each start and loads it with `--dangerously-load-development-channels`, Claude Code's flag for channels made on the same machine.
- At every start with subscriptions or the heartbeat on, Claude Code shows "WARNING: Loading development channels". harnessd picks "I am using this for local development" when the screen lists only `plugin:harnessd@inline`.
- When your `args` load more channels with the same flag, the screen lists them too and waits for you: run `harnessd attach` and answer it.
- Other channel plugins, such as Anthropic's `telegram` or `discord`, go in `args` with `--channels`, as in any Claude Code session. Claude Code accepts the ones on its approved list. An `allowedChannelPlugins` list in managed settings replaces that list.
- Managed settings can turn channels off (`channelsEnabled`), for a Team or Enterprise organization or for this machine. Claude Code then drops every channel's events, with either flag. The log and `harnessd status` say so, and harnessd leaves the setting alone: whoever manages those settings sets `channelsEnabled`.

#### Channel states in `harnessd status`

| `events` | Meaning |
| --- | --- |
| `arriving` | An event sent since this start showed up in the conversation. |
| `sent, not in the conversation yet` | An event was sent since this start. Claude Code hasn't shown it. |
| `none yet` | No event since this start. |
| `off (Claude Code isn't running)` | Claude Code is stopped or waiting to start. |
| `refused` | Managed settings block channels. Claude Code drops the events. |

### The servers' commands

- Each server in `servers` is a command of the same name in Claude Code's shell, in `<state folder>/plugin/bin`. That folder comes first on Claude Code's `PATH`.
- The command is `harnessd tools <server>`: its tools are its subcommands, with flags from each tool's input schema. `<server> --help` lists them.
- Each call reads the config file, so it sends the server's current `url` and `headers`. `${VAR}` in a header reads the environment Claude Code runs with.
- `<server> login` signs in to a server that asks for OAuth. The sign-in is kept in `<state folder>/auth` and also serves the channel's subscriptions to that server.

### Commands

- `service install` and `start` wait until Claude Code runs. They give up when it exits again, or after about 90 seconds (a `prestart` command has 60 of them), then print the log's last 10 lines and exit `1`.
- `stop` sends Claude Code `SIGTERM`, then `SIGKILL` after 10 seconds.
- `start`, `stop`, `status` and `attach` talk to the running harnessd over a socket that only your user can open. When none runs they print `harnessd isn't running` and exit `1`.
- `service install` refuses to run from an `npx` copy, as `root`'s agent, or while the other kind of service is installed for the same state folder.
- `harnessd run` is harnessd itself, and `harnessd channel` is the channel's MCP server. The service and Claude Code start them.

#### `harnessd status --json`

```json
{
  "running": true,
  "home": "/Users/you/.local/state/harnessd",
  "config": "/Users/you/.config/harnessd/config.json",
  "status": {
    "state": "running",
    "pid": 4821,
    "sessionId": "6a0f3c1e-8f0b-4c58-9a57-2f1d6c0e7b11",
    "startedAt": "2026-12-01T16:04:16.530Z",
    "restarts": 2,
    "lastExit": { "code": 1, "at": "2026-12-01T16:04:11.512Z" },
    "daemonPid": 612,
    "folder": "/Users/you/agent"
  },
  "servers": {
    "board": {
      "url": "https://board.example.com/api/board/mcp",
      "events": ["task.handed", "session.message"]
    }
  },
  "channel": {
    "events": "arriving",
    "subscribe": ["board task.handed --board main", "board session.message"],
    "pushedAt": "2026-12-01T16:05:02.000Z",
    "heardAt": "2026-12-01T16:05:07.000Z"
  },
  "log": "/Users/you/.local/state/harnessd/harnessd.log",
  "logTail": ["2026-12-01T16:04:16.530Z starting Claude Code: resuming conversation 6a0f3c1e-…"]
}
```

- `state` is `starting`, `running`, `waiting` or `stopped`. `waiting` carries `nextStartAt`.
- `status.account` names the account in use. `status.accountsStopped` maps each stopped account to `{ why, until }`.
- `status.waitingOn` names the prompt Claude Code waits at for a person.
- `status.heartbeat` is there when the heartbeat is on: `everySeconds`, `activeAt` (the last tool call through harnessd or turn's end), and `sentAt` and `deadlineAt` while a heartbeat waits for its answer.
- `configError` holds the message when the config file is wrong. The exit code is then `1`.
- `servers` lists each server with the events the channel takes from it. An empty list means the server sends no events.
- `channel` is there when the config subscribes to events. Its `events` is one of the [channel states](#channel-states-in-harnessd-status).
- `status.channelsRefused` is `true` when managed settings block channels. The channel's `events` is then `refused`.
- When harnessd isn't running, `log` and `logTail` come from `service.log`, which says why it couldn't start.

### The terminal

- The terminal is 160 by 50 while nobody is attached, and takes the size of the terminal that attaches.
- An attach replays up to the last 2 MB of output.
- harnessd passes your keys through, except `Ctrl-\`.

## Sitemap

See the full [sitemap](/sitemap.md) for all pages.
Docs-scoped sitemap: [/docs/sitemap.md](/docs/sitemap.md).
Well-known sitemap: [/.well-known/sitemap.md](/.well-known/sitemap.md).
