---
title: "Concepts"
description: "How harnessd keeps your agent running."
canonical_url: "https://www.harness-sdk.dev/harnessd/docs/concepts"
markdown_url: "https://www.harness-sdk.dev/harnessd/docs/concepts.md"
x_farming_labs_generated_preamble: true
---

# Concepts
URL: /harnessd/docs/concepts
LLM index: /llms.txt
Description: How harnessd keeps your agent running.

On your laptop you restart Claude Code and answer its prompts. On the agent's machine nobody is there, so harnessd restarts it and answers its start-up prompts.

| What happens | What harnessd does | What the agent reads |
| --- | --- | --- |
| Claude Code exits | Starts it again after 5 s; the wait doubles up to 5 min and a 10-minute run resets it. | harnessd restarted Claude Code: it exited with code 1 after 4012s. This is the same conversation. |
| The machine restarts, or harnessd exits | launchd or systemd starts harnessd, at boot or at login, and harnessd resumes the conversation. | harnessd restarted Claude Code: harnessd started (a login, a reboot or an update). This is the same conversation. |
| A prompt appears | Answers the start-up prompts it knows and logs each answer. A tool's permission prompt waits for you; harnessd status names it. | Nothing. |
| The usage limit | With two accounts, restarts Claude Code on the next account within about 10 s. With one, or with both at the limit, picks "Wait here, then continue automatically". | With two accounts: harnessd restarted Claude Code: account work stopped at its usage limit, so Claude Code now runs on account spare. This is the same conversation. With one: nothing. |

## How it works

launchd or systemd keeps harnessd alive, and harnessd keeps Claude Code alive. When Claude Code exits, harnessd starts it again after 5 seconds. Each further wait is twice as long, up to 5 minutes. A run of 10 minutes sets the wait back to 5 seconds. [Restart rules](/harnessd/docs/reference#restarts).

When Claude Code's updater installs a newer version, harnessd restarts into it once the agent is idle:

```text
2026-12-01T16:04:11.201Z restarting Claude Code 2.1.334 into 2.1.335
```

## Conversations

Every restart resumes the conversation Claude Code was in. The agent's first message says why it restarted:

```text
harnessd restarted Claude Code: it exited with code 1 after 42s. This is the same conversation.
```

If the history is gone, or a resumed start exits within 30 seconds, the next start is a new conversation.

### Start a new conversation

Run [`harnessd attach`](/harnessd/docs/reference#harnessd-attach) and type `/clear`. From then on, restarts resume the new conversation.

## Prompts

harnessd reads Claude Code's screen and answers the start-up prompts it knows. Each answer is a line in the log:

```text
2026-12-01T23:21:57.905Z answered Claude Code's prompt: trust in the agent's folder
```

It answers a prompt only when the whole dialog matches, from its title to its last line. Text that an event or a tool prints can't pass for a prompt. It can't sign in for you. [Every prompt and answer](/harnessd/docs/reference#prompts).

### Permission prompts

harnessd starts Claude Code in auto mode (`--permission-mode auto`), where Claude Code decides whether each action is safe. When a tool still asks, harnessd leaves the answer to you, and `harnessd status` says so:

```text
Claude Code waits for an answer (permission: Bash command): harnessd attach, then answer it
```

## Accounts

Name more than one Claude account in the config file. When the one in use hits its usage limit or its sign-in fails, harnessd restarts Claude Code on the next one, in the same conversation.

```json
{
  "compatibilityDate": "2026-12-02",
  "folder": "~/agent",
  "accounts": {
    "work": { "env": { "CLAUDE_CODE_OAUTH_TOKEN": "sk-ant-oat01-…" } },
    "spare": { "env": { "CLAUDE_CODE_OAUTH_TOKEN": "sk-ant-oat01-…" } }
  }
}
```

Each token comes from `claude setup-token`.

```text
$ harnessd status
harnessd 612: Claude Code 2.1.334 running for 30s (pid 4821)
account spare
account work stopped at its usage limit; harnessd tries it again after 12/1/2026, 6:30:20 PM
```

With one account, Claude Code waits for the limit to reset. [Account rules](/harnessd/docs/reference#accounts).

### Keep tokens out of the file

A [`prestart`](/harnessd/docs/setup#fresh-values-at-each-start) command can fetch the token at each start. It gets the account's name in `HARNESSD_ACCOUNT`.

## Channels

The agent hears what happens in your apps without asking. harnessd follows the events you subscribe to and puts each one into the conversation as a message.

Diagram: A channel in two steps. One: something happens in your app, and its MCP server sends an event to harnessd, which puts it into Claude Code's conversation as a message. Two: the agent answers by running the server's command, which calls the server's tools. harnessd saves its place in channel.json once the event is in the conversation.

- Your app → harnessd: event
- harnessd → Claude Code: message
- Claude Code → harnessd: board command
- harnessd → Your app: tool call
- harnessd → channel.json

Name the app's MCP server and the events in `~/.config/harnessd/config.json`:

```json
{
  "compatibilityDate": "2026-12-02",
  "folder": "~/agent",
  "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" } }
    ]
  }
}
```

`${BOARD_TOKEN}` reads the environment. Set it in the config file's `env`.

Each event arrives as a message:

```text
<channel source="plugin:harnessd:channel" task="AUI-1" server="board" event="task.handed" delivery="9c1f04ab.1">Do it</channel>
```

The agent answers by running `board` in its shell. `board --help` lists the server's tools.

harnessd saves its place once an event shows in the conversation, so an event the agent missed during a restart comes when it's back. [Channel rules](/harnessd/docs/reference#the-channel).

### Check that events arrive

Run `harnessd stop`, then `harnessd start`, to load a changed config. After the next event shows in the conversation, `harnessd status` prints:

```text
server board: the board command, events task.handed (https://board.example.com/api/board/mcp)
channel: events arriving
  board task.handed --board main
```

## What it doesn't do

- It restarts a Claude Code that exited, not one that is alive and stuck.
- It doesn't alert you. You run `harnessd status`.
- It doesn't keep the machine awake.
- It answers the prompts of Claude Code 2.1. A newer version can show one it leaves to you.
- Each harnessd runs one Claude Code, on macOS or on Linux with systemd.
- It opens no network port, and it never turns permission prompts off itself.

## 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).
