# `harborloop`

Your team's knowledge, in your terminal. Recall in Claude Code, Codex, Cursor
and GitHub Copilot (the CLI and VS Code's agent mode); capture on the way back
out; and a `doctor` that can tell you it is not working. The CLI for
[Harbor](https://gethrbr.com), shared memory for AI coding agents.

```
npx harborloop init
```

Zero runtime dependencies. Node ≥ 18. Signing in needs a Harbor account, free
for up to 2 people with no card: https://app.gethrbr.com/sign-up

Or install Harbor from inside your agent, as a plugin:

```
claude plugin marketplace add gethrbr/harbor-plugins && claude plugin install harbor@harbor
codex plugin marketplace add gethrbr/harbor-plugins && codex plugin add harbor@harbor
```

Then `/harbor:login` in Claude Code, or `$harbor:login` in Codex. See
[gethrbr/harbor-plugins](https://github.com/gethrbr/harbor-plugins).

## Commands

| | |
|---|---|
| `harbor init` | Sign in, install the hooks, turn Harbor on in this repo (in its Space; `--no-bind` leaves it off). Idempotent. Wires every agent it finds; `--cursor` / `--no-cursor`, `--codex` / `--no-codex` and `--copilot` / `--no-copilot` override detection. Asks before sending the repo's committed `CLAUDE.md` / `AGENTS.md` to your team's review queue, once per file; `--import-rules` sends without asking, `--no-import-rules` never sends, and `harbor update` never sends. `--headless` is for a cloud agent's setup script, see below. |
| `harbor doctor` | Is it actually working? `--offline`, `--json`, `--days N` |
| `harbor status` | This repo, from local files only. No network. |
| `harbor scan` | The coding agents on this machine (Claude Code, Cursor, Codex, Copilot) and the MCP servers each one is set up with: what each server is, where it is set, and whether a credential is written in the config. Reads their config files only: no sign-in, no network, and it never prints a token or header value. `--json` |
| `harbor bind [Space]` | Turn Harbor on in this repo, in a Space: the only one, or it asks. On a bound repo, `harbor bind --project <Space>` moves it (an owner, admin or curator can). Harbor stays off in every repo you do not bind. |
| `harbor workspaces` | Which workspaces you can reach, and the one this machine uses. `--json` |
| `harbor daily` | What the hooks run once a day in the background: renew the sign-in, send each connected repo's facts, report this machine's harborloop version, check for a newer release. |
| `harbor off` | Pause this repo. In a folder that isn't a repo, pause every such folder on this machine. `--capture` keeps recall. `--global` for the machine. |
| `harbor on` | Resume. `--global` clears a machine-wide pause. |
| `harbor login` | Re-authenticate. `--no-browser` to paste a code instead. `--workspace <id>` switches workspace **without** the browser. |
| `harbor logout` | Sign this machine out: removes `~/.harbor/auth.json` and the MCP entry (and its bearer) from each agent's config. The hooks stay installed and do nothing until you sign in again. |
| `harbor uninstall` | Take Harbor off this machine: the hooks, the MCP entries and `~/.harbor`. |

There is deliberately no `ask`, no `learnings`, no `sources`. Your agent reaches
those over MCP and you reach them in the webapp; a second copy of the product in
your terminal is not a feature.

**Harbor runs only in repos your team connected.** Anywhere else (a repo nobody
bound, a folder with no git origin, or a repo paused with `harbor off`) the
hooks send nothing, and your agent's calls to Harbor's own MCP tools are refused
on this machine before they leave. A repo you opened to try something out gets
none of your team's rules and adds nothing to them. `harbor off --capture` keeps
the tools working.

**Folders that aren't a git repo with a remote** (a scratch folder, a notebook, a
training run) are off too, unless an admin picks a Space for them in Harbor:
Settings → Spaces → Work outside a repo. Then your agent gets that Space's rules
in those folders and what it learns there is saved to that Space. Harbor never
sends the folder's path. An agent started directly in your home folder stays off;
the folders inside it count. Run `harbor off` in such a folder to turn this off on your
machine, and `harbor on` to turn it back on. An admin's change reaches your
machine within about ten minutes. A repo with a remote that nobody bound stays
off either way: run `harbor bind` in it.

## In a cloud agent

Claude Code on the web and other containers have no browser to sign in with.
Create a workspace agent key in Harbor's settings, then give the environment
this setup script:

```
HARBOR_AGENT_KEY=<your key> npx -y harborloop@latest init --headless
```

The key goes on the line itself. Claude Code on the web does not pass the
environment's "Environment variables" to the setup script, so a key set there
is never seen by `init --headless`.

**Network access.** Claude Code on the web's default "Trusted" policy blocks
Harbor. Choose "Custom", add `app.gethrbr.com` and `mcp.gethrbr.com`, and tick
"Also include default list of common package managers" so `npx` can still
reach npm.

If the setup script runs inside a repo that has its own package named
`harborloop`, `npx` picks that one up instead. Install it globally there:

```
npm i -g harborloop@latest && HARBOR_AGENT_KEY=<your key> harbor init --headless
```

`init --headless` wires Claude Code with the key: the MCP entry, the hooks, the
repo's origin, and the workspace's guardrails. The setup script usually runs in
the parent of the clone (`/home/user`, with the repo at `/home/user/<repo>`),
so it uses the repo it is standing in, or else every repo directly under it.
`--repo <path>` names one instead.

It never opens a browser and never writes `~/.harbor/auth.json`. It prints one line and exits 0 whatever happens, so a
Harbor problem cannot stop the session. With no `HARBOR_AGENT_KEY` it prints
`Harbor: no HARBOR_AGENT_KEY, skipping` and changes nothing.

**Blocked commands reach Harbor.** When a guardrail blocks a command in the
container, the Stop hook at the end of that turn sends the record to Harbor
with the key: the rule, the program name, the session, never a path or an
argument. If Harbor cannot be reached, the record waits for the next turn.

**A guardrail armed later still arrives.** While the agent works, the hook
fetches the workspace's guardrails again in the background, at most every 30
seconds, so a rule armed mid-session blocks within a minute. The tool call
never waits for that fetch, and it sends only the key. The same holds on a
laptop.

**A repo that commits its own hooks.** If the repo's `.claude/settings.json`
already runs Harbor's hooks, add `--no-hooks`. It sets up everything else and
leaves the hooks unregistered, so each one runs once instead of twice.

### Codex cloud

In the Codex environment's settings, add the key as a secret named
`HARBOR_AGENT_KEY` (secrets reach the setup script, and only the setup script),
then use this setup script:

```
npx -y harborloop@latest init --headless --codex --origin https://github.com/<owner>/<repo>
```

- **Agent internet access** must be On, with `app.gethrbr.com` and
  `mcp.gethrbr.com` allowed. With it Off only the guardrails synced at setup
  still block; nothing reaches Harbor.
- `--codex` writes Harbor's hooks and MCP entry into the Codex the agent runs
  (`/opt/codex` in Codex cloud), and has that Codex trust the hooks: Codex runs
  no hook it has not trusted. The line reports how many it trusted.
- The key goes into the MCP entry's header on disk, because Codex starts hooks
  and MCP servers without the environment's variables.
- `--origin` names the repo. Codex clones it with no `origin` remote, and
  Harbor stays off in a repo it cannot name. An origin the clone already has
  is never replaced.

Cursor and Copilot cloud agents are not supported yet.

## Why a CLI at all

Three config-lifecycle jobs used to be owned by a *running* desktop app, and
each of them failed **silently** without it:

| Job | Without the app running |
|---|---|
| MCP token refresh | expires, never re-mints |
| Hook command path | absolute into the app bundle — move or uninstall it and the path is dead |
| Repo allowlist | bind a repo on the web, the terminal never learns |

The hook is a read-only consumer of all three and exits 0 on any failure,
because a `UserPromptSubmit` hook must never block a prompt. So *"install the
app once, close it, live in the terminal"* was broken by construction, and what
you saw was nothing at all: no error, no injection, a product that appears
inert.

`doctor` exists because of that last sentence.

## `doctor`

```
  Endpoint        ✓ https://app.gethrbr.com/v1
  Signed in       ✓ workspace "acme"
  Token           ✓ valid, expires in 11 months
  Hooks           ✓ 5 installed from ~/.harbor/bin
  This repo       ✓ https://github.com/acme/repo
  Recording       ✓ on

  Recall          ✓ last 7 days   41 sessions · 28 of 41 (68%) received context
  Fit             ⚠ avg bundle 7.2   200 of 300 of served atoms go uncited
  Attribution     ✓ 41/41 recalls counted
  Contributed     ✓ 3 learnings   2 approved · 1 pending review
```

The first block is *am I connected*. The second is *is it working* — every line
with a denominator, because a percentage you cannot see the bottom half of is a
number you cannot disbelieve.

`Fit` is the one worth staring at. It is the only place in the product that
tells you how much of what gets injected is actually used.

**`doctor` can say no.** Run it on an unbound repo, or with a dead token, and it
fails with the fix on the next line. A health check that only ever prints green
is not a health check.

**A partial install is one of the things it says no to.** `init` registers seven
events in Claude Code; a hand-edited `settings.json` that kept one of them gets
`Hooks ⚠ 1 of 7 events registered — capture, the end-of-session report and tool
context are not wired`, not a tick over a count. Counting what is there answers
a narrower question than the one you are asking it.

**A paused repo prints `⏸ paused, on purpose`,** never a red error. Reporting a
silence you asked for as a fault just teaches you to stop reading the output.

## `off` — the part people actually use

A lot of sessions are throwaway: a spike, a rename, an afternoon of
vibe-coding. None of it belongs in your team's graph.

```
harbor off              # this repo: no context in, nothing recorded
harbor off --capture    # keep the recall, record nothing
harbor off --global     # the whole machine
harbor on               # back on. Beats a --global pause.
```

The pause is stored **locally** and read by the hook before it touches the
network, so it still works on a plane — and so a toggle cannot fail at exactly
the moment you need it.

## Guardrails your agent cannot switch off

Every way to switch a guardrail off is a file in `~/.harbor`: the pause,
`"toolGuard": false` in `synced-origins.json`, and the exceptions
`harbor allow-once` writes. Your agent runs as you, so it can write those files
too. The hook refuses the agent's own `harbor off`, `harbor allow-once` and the
other commands meant for you, but a shell has more ways to write a file than a
hook can recognise. The boundary that holds is the agent's own sandbox, told to
refuse writes to `~/.harbor`. Harbor's hooks run outside that sandbox, so they
keep working.

**Claude Code.** Merge into `~/.claude/settings.json`:

```json
{
  "sandbox": {
    "enabled": true,
    "allowUnsandboxedCommands": false,
    "filesystem": { "denyWrite": ["~/.harbor"] }
  },
  "permissions": { "deny": ["Edit(~/.harbor/**)"] }
}
```

The sandbox covers shell commands. Claude's own Write and Edit tools run
outside it, so the `Edit` rule covers them. `allowUnsandboxedCommands: false`
stops Claude retrying a refused command outside the sandbox. The sandbox also
sends shell network traffic through an allow-list; `/sandbox` shows it.

**Codex.** In `~/.codex/config.toml`:

```toml
sandbox_mode = "workspace-write"
```

and keep `~/.harbor`, and your home folder, out of
`[sandbox_workspace_write] writable_roots`. A session started with
`--sandbox danger-full-access` or `--dangerously-bypass-approvals-and-sandbox`
skips it.

While a rule is refusing commands, `harbor doctor` checks both and says what is
missing.

## Switching workspaces

One account, several workspaces — `harbor workspaces` lists them and marks the
one this machine is bound to:

```
  * Acme             ws_2f9c1a4b
    Beta Industries  ws_7d3e08f2

Switch with:  harbor login --workspace <id>
```

The switch needs **no browser**. The runner credential is scoped to the *user*,
not the workspace, so `login --workspace <id>` re-points it in place and
re-mints the MCP token against the new one. That matters more than it sounds:
the login rate limit is 5 requests per 15 minutes per IP and a browser sign-in
spends two of them, so a switch that went through the browser would let you
change your mind about twice.

If the list says you are signed in to a workspace that is not on it, you were
removed from it. Every request and mint against it will fail until you switch.

## What it writes

```
~/.harbor/auth.json             your credential (0600)
~/.harbor/synced-origins.json   which repos are yours, the Space for work outside a repo, and what is paused
~/.harbor/bin/*.mjs             the hook scripts
~/.harbor/cli-sessions/         per-session bookkeeping
~/.harbor/daily-at              when the hooks last started `harbor daily`
```

Then one entry per agent you actually have — **its own bearer, in its own file,
in its own vocabulary**, so each agent gets its own connection row and a 401 in
one never re-mints another:

```
~/.claude.json                  `mcpServers.harbor` — the MCP entry and its bearer
~/.claude/settings.json         seven hook events (NOT the MCP entry: Claude Code
                                reads `mcpServers` from `~/.claude.json` only)
~/.codex/config.toml            the MCP server, plus the trust stamps Codex will not run hooks without
~/.codex/hooks.json             six hook events (Codex has no SessionEnd)
~/.cursor/mcp.json              `mcpServers.harbor`, Cursor's `{url, headers}` shape
~/.cursor/hooks.json            seven events, in Cursor's own event and tool names
~/.copilot/mcp-config.json      `mcpServers.harbor`, in the shape `copilot mcp add` writes
~/.copilot/hooks/harbor.json    seven events, in a file of Harbor's own (`$COPILOT_HOME` if set)
```

Nothing else. Until 0.6.0 a background job wrote the team's skills, documents and
memories into `~/.claude`, `~/.codex`, `~/.cursor` and your checkouts every 15
minutes. That job is retired: your agent gets the same knowledge through recall.
The first `harbor init` or `harbor update` on 0.6.0 unloads the job and takes back
the files it wrote, only where the bytes still match what it wrote. A file you
edited stays, and the command names it.

⚠️ **Cursor recalls at session start, not on every prompt.** Its prompt event has
no field to inject context into, so a Cursor session gets the bundle when it
opens and on every edit, and no per-turn delta. `doctor` says so on its healthy
line rather than implying parity.

⚠️ **Copilot shows no ⚓ line.** Its hooks have no channel to the person, so
the rules reach the agent on every prompt and after each file it touches, and
nothing tells you so in the terminal. A rule set to ask first refuses with a code
instead, as on Codex and Cursor. VS Code's agent mode runs the same hook file
(unless `"chat.useHooks": false`, which `doctor` warns about), but it starts the
harbor MCP server only when you do: once, from **MCP: List Servers**, **harbor**,
**Start Server**.

Every one of these files is yours, not ours: each write is a merge that leaves
your other MCP servers, your other hooks, and every key we do not recognise
exactly as it found them, under a cross-process lock so the desktop app and this
CLI cannot clobber each other. `~/.cursor/*` is parsed as JSONC, so if you have
put comments in it we **decline to rewrite it** rather than delete them — and
`doctor` names the file when that happens.

The credential is a `0600` file rather than the OS keychain — the same choice
`gh` and `npm` make. A keychain needs a native module (and there goes the
zero-dependency `npx` install) and a running secret service that headless boxes
do not have, to defend against an attacker who can already read your files as
you — and who could equally read the same bearer out of your agent's own config.

## Without installing anything

Any MCP client can have **pull** recall today, with no install:

```
claude mcp add --transport http harbor <your-mcp-url>
```

What that does not get you: push injection at the start of a session, the write
-back that closes the loop, or a session key — so none of it is measurable, and
`doctor` has nothing to report. That is the difference `init` buys.

## Configuration

| Variable | Default |
|---|---|
| `HARBOR_API_URL` | `https://app.gethrbr.com/v1` |
| `HARBOR_MCP_URL` | `https://mcp.gethrbr.com/mcp` |
| `HARBOR_WEB_URL` | `https://app.gethrbr.com` |
| `HARBOR_HOME` | `~/.harbor` |

You need none of them to install — the defaults are the hosted harbor. Set them
to run against your own backend, or against a local stack:

```
export HARBOR_API_URL=http://localhost:8100/v1
export HARBOR_MCP_URL=http://localhost:8101/mcp
export HARBOR_WEB_URL=http://localhost:5174
```

The local web port is **5174**, not 5173. 5173 is another product's vite on the
same machine, and `/desktop-auth` redeems its auth code against *its own* API —
so pointing this at 5173 signs you into a different database and the CLI then
fails on a token the local backend has never heard of.

`doctor` prints the endpoint it resolved, and marks it `(local)` when it is one,
so a run never quietly reports on a workspace you did not mean.

## Guides

- [Quickstart](https://gethrbr.com/docs/quickstart) and the [CLI docs](https://gethrbr.com/docs/cli)
- [Why does Claude ignore my CLAUDE.md?](https://gethrbr.com/blog/why-claude-ignores-claude-md)
- [AGENTS.md vs CLAUDE.md: which tools read which](https://gethrbr.com/blog/agents-md-vs-claude-md)
- [Claude Code hooks: a practical guide with examples](https://gethrbr.com/blog/claude-code-hooks)
- [Claude Code memory vs Codex, Cursor and Copilot memory](https://gethrbr.com/blog/claude-code-memory-vs-codex-cursor-copilot)
- [We checked 3,905 CLAUDE.md and AGENTS.md files on GitHub](https://gethrbr.com/blog/claude-md-agents-md-github-study)
