---
title: "Set up"
description: "Install harnessd and reach your agent from anywhere."
canonical_url: "https://www.harness-sdk.dev/harnessd/docs/setup"
markdown_url: "https://www.harness-sdk.dev/harnessd/docs/setup.md"
x_farming_labs_generated_preamble: true
---

# Set up
URL: /harnessd/docs/setup
LLM index: /llms.txt
Description: Install harnessd and reach your agent from anywhere.

## Install

```sh
npm install -g @harness-sdk/harnessd
harnessd service install
```

It needs macOS or Linux with systemd, and Node.js 20.19 or newer. Install it globally first: a copy run through `npx` can't be installed.

When Claude Code is missing or signed out, the second command offers to fix that. Then it starts harnessd and waits until Claude Code runs. On a Mac it prints:

```text
harnessd runs Claude Code in /Users/you/agent (2.1.0 (Claude Code)), now and at every login.
  harnessd attach   its terminal; Ctrl-\ detaches
  harnessd status   what runs and whether events arrive
It starts when you log in: turn on automatic login (System Settings > Users & Groups), so it comes back after a power cut.
For a start at boot, with nobody logged in: harnessd service uninstall, then sudo harnessd service install
```

A boot service prints only the first three lines. When Claude Code doesn't start, the command shows the log's last lines and exits with `1`.

From a script it can't ask: when Claude Code is missing or signed out, it installs no service and exits with `1`. Two flags answer ahead: `--install-claude` and `--skip-sign-in`.

### Login item or boot service

| Command | Starts | Note |
| --- | --- | --- |
| `harnessd service install` | When you log in | Mac: turn on automatic login, so it comes back after a power cut. Linux: it stops when you sign out. |
| `sudo harnessd service install` | When the machine boots, with nobody logged in | It runs as your user, never as root. Linux: `sudo env "PATH=$PATH" harnessd service install`. |

A machine has one of the two. Run `harnessd service uninstall` before you switch to the boot service, and `sudo harnessd service uninstall` to switch back.

[Run it on a Mac mini](/harnessd/docs/mac-mini) has the settings that make a Mac turn on and log in by itself.

### Sign in

Install checks that Claude Code is signed in. When it isn't, it offers to run `claude auth login`.

A boot service, or a Linux machine with no display, uses `claude setup-token` instead. You paste the token, and harnessd stores it in the config file's `env` as `CLAUDE_CODE_OAUTH_TOKEN`. A boot service on a Mac needs the token because the keychain can't be read before a login.

Install skips the check when the config file has a `prestart` command. With [accounts](/harnessd/docs/concepts#accounts) it checks the first one and offers nothing.

### Upgrade or remove

After you upgrade harnessd, run `harnessd service install` again. The [conversation resumes](/harnessd/docs/concepts#conversations).

`harnessd service uninstall` removes the service. Your settings and the conversation stay.

Every flag is in the [CLI reference](/harnessd/docs/reference#harnessd-service-install).

Before you start, also fetch [/harnessd/docs/reference.md](/harnessd/docs/reference.md).

## The config file

`harnessd service install` writes `~/.config/harnessd/config.json`:

```json
{
  "compatibilityDate": "2026-12-02",
  "folder": "~/agent",
  "servers": {},
  "channel": { "subscribe": [] }
}
```

| Key | What it does |
| --- | --- |
| `compatibilityDate` | The day the file was written. harnessd behaves as it did on that day. |
| `folder` | Where Claude Code runs. |
| `args` | Extra `claude` arguments, such as `["--model", "opus"]`. |
| `env` | Extra environment variables for Claude Code. |
| `prestart` | A shell command run before every start. |
| `servers`, `channel` | The apps the agent hears. See [Channels](/harnessd/docs/concepts#channels). |
| `accounts` | More than one Claude account. See [Accounts](/harnessd/docs/concepts#accounts). |

The first two are required. The [reference](/harnessd/docs/reference#config-file) lists every field and rule.

### When a change takes effect

harnessd reads the file each time it starts Claude Code:

```sh
harnessd stop
harnessd start
```

The conversation resumes.

### When the file is wrong

Claude Code doesn't start. `harnessd status` prints the error and exits with `1`:

```text
config.json: it has no "channels"; it takes compatibilityDate, folder, args, env, prestart, servers, channel, accounts
```

harnessd keeps retrying, so Claude Code starts once the file is fixed.

## Claude Code settings

`CLAUDE.md`, skills and `.claude/settings.json` in the agent's folder work as in any Claude Code project.

Diagram: Three inputs to each start of Claude Code. The agent's folder holds CLAUDE.md and Claude Code's own settings. The config file adds arguments and environment. The prestart command adds more of both, fresh at every start. harnessd puts them together and starts Claude Code.

- Config file → harnessd
- Prestart command → harnessd
- harnessd → Claude Code: starts
- The agent's folder → Claude Code: reads

### Arguments and environment

`args` adds `claude` flags, and `env` sets environment variables for Claude Code:

```json
{
  "args": ["--model", "opus", "--remote-control"],
  "env": { "TZ": "America/Los_Angeles" }
}
```

- `--remote-control` lets you reach the agent from the Claude app. It works only with a claude.ai sign-in.
- Claude Code starts in auto permission mode, unless `args` pick another with `--permission-mode <mode>`.
- The [reference](/harnessd/docs/reference#the-claude-command) shows the full command line.

### Fresh values at each start

A token that expires should not sit in a file. `prestart` runs in the agent's folder and prints JSON. harnessd adds it to that start only:

```json
{ "env": { "BOARD_TOKEN": "…" }, "args": ["--model", "opus"] }
```

It has 60 seconds. If it fails, harnessd waits and tries again. The conversation is kept.

## Check on the agent

| You want to know | Use |
| --- | --- |
| Is it running, and in which conversation? | [`harnessd status`](/harnessd/docs/reference#harnessd-status). `--json` prints the same facts for a script. |
| What does the agent see? | [`harnessd attach`](/harnessd/docs/reference#harnessd-attach). Type as in any Claude Code session. `Ctrl-\` leaves, and Claude Code keeps running. |
| Why did it restart? | The last 10 log lines that `harnessd status` prints. |

```text
$ harnessd status
harnessd 612: Claude Code 2.1.0 running for 3h (pid 4821)
conversation 6a0f3c1e-8f0b-4c58-9a57-2f1d6c0e7b11 in /Users/you/agent
restarts 1, last exit code 1 3h ago
log /Users/you/.local/state/harnessd/harnessd.log
  2026-12-01T19:04:11.512Z Claude Code exited with code 1 after 42s
  2026-12-01T19:04:11.513Z starting again in 5s
  2026-12-01T19:04:16.530Z starting Claude Code: resuming conversation 6a0f3c1e-8f0b-4c58-9a57-2f1d6c0e7b11 (it exited with code 1 after 42s)
```

With a [channel](/harnessd/docs/concepts#channels), status adds its state. Right after a start it reads `channel: events none yet`, and once the first event shows up in the conversation `channel: events arriving`. The reference lists [every state](/harnessd/docs/reference#channel-states-in-harnessd-status).

## Secure remote access

harnessd opens no port: it listens on a socket file that only the agent's user can open. You reach the agent over SSH.

Diagram: Two layers. Your device reaches the agent's machine over Tailscale, where Tailnet Lock keeps other devices out. On the machine, the agent runs in an account of its own, apart from your home folder.

- Your device → The agent's account: SSH over Tailscale
- The agent's account → Claude Code: harnessd attach

### The network: Tailscale with Tailnet Lock

1. Put the agent's machine and your own devices on [Tailscale](https://tailscale.com). The machine gets one private address that works from anywhere. Don't forward a port to it, and don't give it a public SSH address.
2. Turn on [Tailnet Lock](https://tailscale.com/kb/1226/tailnet-lock). A new device then joins your network only after one of your trusted devices signs it.

   ```sh
   tailscale lock status                  # is Tailnet Lock on, and which devices can sign
   tailscale lock sign nodekey:<key>      # on a trusted device: let a new device in
   ```

3. Turn on SSH on the agent's machine. On a Mac, open System Settings, then General, then Sharing, and turn on Remote Login. Remote Login also answers on your local network.
4. Open a shell as the agent's user and attach.

   ```text
   $ ssh agent@<tailscale name>
   $ harnessd attach
   ```

Several people can attach at once. All see the same screen.

### The agent's own account

Plan for the agent doing anything its user can. Give it a machine of its own, or a user of its own, so your browser profiles, SSH keys and password manager are out of its reach.

```sh
sudo harnessd service install --user agent
```

That installs harnessd as a boot service for the user `agent`. Create the user first. It needs no admin rights, and signs in with a token, as [Sign in](#sign-in) shows.

The agent also reads whatever a connected server sends. Connect only servers you trust.

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