hq host is HQ’s built-in host for long-lived agents: coding agents, and the
general-purpose agents (Hermes, OpenClaw) that HQ uses for monitoring,
research and review but never for code (see “General-purpose agents” in
AGENT_SESSIONS.md). It runs each agent
in a pseudo-terminal, keeps an emulated screen and scrollback you can read back,
and accepts typed input. It is where every agent session HQ starts runs,
on this machine or on a machine you paired (see JOIN_A_MACHINE.md; on Windows the host runs inside WSL2, see WINDOWS.md; HQ Lite on native Windows has no host).
macOS: a stable signature
macOS ties its folder-access approvals (Documents, Desktop, Downloads) to a program’s code
signature, and an ad-hoc signature changes with every build, so every update would ask again,
and an agent started with no one at the screen hangs waiting. hq host install therefore
makes a certificate for this machine (HQ Local Code Signing, in
~/.hq/hq-signing.keychain-db, an empty-password keychain holding nothing else) and signs
hq with it. Approve the prompt macOS shows the first time; it stays approved.
After that, hq update signs each new build with the same certificate before it replaces the
old one, and so do a source rebuild through scripts/install-hq.sh and a self-update. They do
this only on a machine that has already run hq host install, so an update never creates a
keychain for someone who did not ask for one. hq host sign <path> does the same for a binary
you put in place yourself. If signing fails, the update and the host still go ahead with a
warning, and macOS asks again. hq doctor shows whether the running hq has the stable
signature.
The update that first brings this in is applied by the older hq, which does not sign, so it
lands ad hoc. Run hq host sign "$(command -v hq)" once afterwards (it only replaces the file,
nothing running is touched); macOS asks once more at the next host restart, because this is a
new identity to it. Later updates sign by themselves.
The certificate’s key sits in that keychain and codesign uses it without a prompt. A program
running as you can therefore sign its own binary with it, and macOS would treat that binary as
HQ for folder approvals. HQ’s host-run agents cannot reach it (the host sandbox hides ~/.hq),
and the keychain files are masked from agent file tools and from the chat shell’s sandbox (unless
governance.bash.sandbox is off). A
program that may run codesign can still ask macOS to use the key without reading the file, so
treat it like the other keys in your home folder. A Developer ID signature held in CI would
close this and replace the local certificate; the project has no Apple developer account yet.
Run it
hq host serve # run the host in this terminal (Ctrl-C stops it)
hq host status # protocol and host version, pid, number of agents, lockdown
hq host stop # ask a running host to exit
hq host lockdown "why" # emergency stop: stop every agent, start none (see Lockdown)
hq host unlock # lift a lockdown; only works on this machine
hq host sign <path> # macOS: give an hq binary the stable local signature (see above)
All of them take --dir <path> (default ~/.hq/run/host). The directory is
created with mode 0700 and holds:
host.sock: the control socket, mode 0600.operator.token: a random secret, mode 0600, created on first start. A token file that is not a regular file owned by you with mode 0600 is refused, and so is a--dirthat is a symlink or belongs to someone else.host.lock: held while a host runs. A secondserveon the same directory fails; a socket left behind by a host that died is replaced.
Protocol
One JSON object per line over the socket, at most 1 MiB per line. Requests are
{"id", "method", "params"}, replies are {"id", "result"} or
{"id", "error": {"code", "message"}}.
The first request on a connection must be hello with
{"protocol_version": 1, "token": "<operator token>"}. Anything else before it
gets unauthenticated. A wrong token gets unauthorized, a different protocol
version gets protocol_mismatch.
| Method | Params | Result |
|---|---|---|
host.status |
none | protocol_version, host_version, pid, agents, agents_working, agents_blocked, binary_stale, lockdown (reason, source, at, or null) |
host.lockdown |
optional reason |
{"lockdown"}; stops every agent and refuses every start until hq host unlock (see Lockdown). There is no unlock method. |
host.workspace |
none | root (the HQ folder, ~/Documents/HQ, created if missing), os, wsl, explorer_path (the \\wsl$\... path on WSL2, else null) |
host.dirs |
optional path (the HQ folder when absent) |
path, parent, dirs (name, path), truncated; only folders inside the HQ folder, symlinks out of it refused |
host.mkdir |
name, optional parent |
{"path"}; one folder name (no slashes, colons, ~, $ or backticks), idempotent |
host.stop |
none | {} |
worktree.add |
repo (a folder in the repository), session (names the worktree’s folder), and branch (with an optional from ref the new branch starts at; send no from key when there is none) or detached (a commit or ref) |
path, repo (the repository’s main folder), branch, head, created, and copied and not_copied (the gitignored paths a .worktreeinclude brought in, and those it could not) when not empty; a git worktree at <HQ folder>/worktrees/<repository>/<session>. A branch that does not exist is made at from, else at the repository folder’s current commit; one checked out in another worktree is refused with branch_in_use. Names that could be read as options are refused. Called again for the same session and branch, it returns the existing worktree. |
worktree.status |
path (a worktree under <HQ folder>/worktrees/), and optionally against (a commit or ref) |
{branch, head, changed, ahead, behind}: the count of paths with uncommitted changes, and the commits ahead of and behind against; both null without against or when it names no commit. HQ passes the commit the session started at. Allowed over the gate. |
worktree.remove |
path |
{removed, dirty}; only a worktree under <HQ folder>/worktrees/, and only when git status is clean, otherwise it is kept (dirty: true). The branch keeps every commit. |
agent.spawn |
name, argv, cwd, optional agent (kind, for state detection), resume_argv (see Restarts), env (object), rows, cols, scrollback_rows |
agent info |
agent.list |
none | {"agents": [...]} |
agent.get |
name |
agent info |
agent.head |
name |
{"head": {sha, subject, branch} or null}: the commit the agent’s folder is at |
agent.read |
name, optional source (visible, recent, recent_unwrapped, styled; default recent_unwrapped; styled is recent with color and style as ANSI escape sequences), optional lines (last N, 0 or absent for all) |
{"text", "truncated"}; text is cut to its last 400 KiB, at a line start, when longer |
agent.send_text |
name, text |
{} (raw bytes, as given) |
agent.paste |
name, text |
{} (bracketed paste when the program enabled it) |
agent.prompt |
name, text |
{} (paste, short pause, Enter) |
agent.send_keys |
name, keys (enter, esc, tab, arrows, pageup, ctrl+c, …) |
{} |
agent.resize |
name, rows, cols |
{} |
agent.wait |
name, until (exit, quiet or state), optional timeout_ms; for quiet quiet_ms; for state states (list, required) and stable_ms (default 300) |
exit_code, or agent info |
events.poll |
optional after (a last_seq), timeout_ms (default 25000, at most 60000) |
{events, last_seq, lost}: waits for events after after; without after it returns the current last_seq at once. An event is {seq, name, kind (spawned, state, exited, removed), state, rule}. lost means events were dropped, so re-read agent.list. Numbers start from the clock, so they keep rising across host restarts. |
agent.report |
event (a hook event name), optional session_id, notification_type; name for the operator (a pane token implies its own) |
{} |
agent.set_resume |
name, argv |
{}; replaces the command a restart runs (the agent must have been spawned with resume_argv) |
agent.awaiting |
none | {"agents": [{name, agent, cwd, env_keys}]}: restored agents waiting for their environment |
agent.resume |
name, env (object, must cover every name in env_keys) |
agent info; missing_env leaves it waiting |
agent.kill |
name |
{} |
agent.remove |
name |
{} |
Unknown fields in params are an invalid_params error. Rows and columns must be
1 to 1000, scrollback_rows is capped at 100000, and cwd must be an existing
absolute directory (otherwise spawn_failed; the host never falls back to the
home directory).
At most 64 connections are served at once (one more gets too_many_connections),
a connection that sends no hello within 5 seconds is closed, and a reply that
cannot be written within 10 seconds drops the connection. host.stop answers
first and then stops the host.
agent.kill and agent.remove stop the process and everything it started: the
process group gets SIGHUP, then SIGKILL after 2 seconds if the leader is still
running. agent.wait with until: exit returns only after the output the
process printed last has been read, so a read right after it sees the tail.
Agent names match [a-z][a-z0-9_-]{0,31} and are unique. Agent info has name,
argv, agent, resumable, title, state, rule, pending, pending_seq, cwd, pid, status (running or exited), exit_code, rows,
cols, bytes_seen, quiet_ms, age_ms. Error codes include agent_not_found,
name_taken, invalid_name, invalid_keys, spawn_failed, agent_exited,
agent_blocked, no_dialog, stale_dialog, invalid_option, typed_option,
no_cursor, answer_unverified, timeout, invalid_params, unknown_method,
bad_request.
Agent state
When a pane is spawned with an agent kind that has a rule file (claude,
claude-code, codex, copilot and github-copilot today), the host works out its state from the screen and
the terminal title: idle, working, blocked or unknown. Agent info carries
state and rule (the rule that decided; absent when nothing matched, which
means idle). A kind with no rule file has no state. agent.wait with
until: "state" returns once the state is one of states and has held for
stable_ms, so a one-frame flicker is not taken for a change.
Rule files are TOML (the format and its provenance are in docs/provenance/herdr.md): each rule names a screen
region and a gate of phrases or patterns, and the matching rule with the highest
priority decides. They are built into the binary (crates/hq-host/src/detect/manifests/);
there is no fetching from anywhere at run time. Screens captured from real
Claude Code, Codex, Copilot CLI, Antigravity CLI and pi sessions, each labelled with the state the agent was really
in, are in crates/hq-host/tests/fixtures/ and are checked on every test run.
Dialogs as data
A blocked rule can also say how to read the dialog it recognised, so a caller
gets the question and its options instead of a screen to interpret. A rule file
names dialog shapes in a [dialogs.<name>] table and a blocked rule points at one
with dialog = "<name>" (or writes it inline as [rules.dialog]). This needs
engine version 4. The table gives:
| Key | Meaning |
|---|---|
kind |
command, edit, path, question, trust or other; kind_when refines it when a line matches |
top, footer |
The dialog’s first line, found by searching up from the footer, and its key hints (the footer must be within the last few lines) |
question |
The question line; options are read only below it, so numbered lines inside a command are never options |
command_block or command_line |
The command, file or path: the lines between two markers, or a line’s first capture |
option |
An option line, with a label capture and a num capture when options are numbered |
selected, remember, typed |
The option the cursor is on; options that widen what the agent may do from now on (“don’t ask again”, “remember this path”); options that open a text field |
answer, decline |
arrows (default) or digit, and the keys that dismiss the dialog (esc by default) |
The dialog is read from the screen, and from up to 2000 lines of scrollback when
it is taller than the screen, so a long heredoc arrives whole up to 32 KiB; past
that it is cut and marked truncated. Box borders are stripped.
Agent info carries a short pending (kind, question, command, options; long
fields shortened) and pending_seq, the number an answer must name. A new
dialog gets a new number and a state event with pending_seq set, even when
the agent was already blocked; a dialog read a moment after its block was
announced takes that event’s number, so one block is one alert. The cursor
moving within a dialog does not change it.
agent.pending {name}returns{state, rule, pending_seq, pending}with the whole dialog, itstextand itsdecline_keys.agent.answer {name, seq, option | decline: true}answers it. Aseqthat is not the current dialog’s isstale_dialog, so an answer never lands on a dialog the caller did not read. Witharrowsthe host moves the cursor, waits until the screen shows it on the chosen option, and only then presses Enter (answer_unverifiedwhen it never gets there; Enter on whatever is highlighted can be a “remember” option). It then waits up to 3 seconds for the dialog to go and replies{registered, agent};registered: falsemeans it is still there. Atypedoption is refused (typed_option): decline and send the message as a prompt instead.
The host does not judge who may pick which option. HQ does: only the owner may
pick a remember option (see harness_session_answer in
docs/AGENT_SESSIONS.md).
Reading from a cursor
agent.read_since {name, cursor?, lines?} returns the lines that scrolled off
the screen since cursor, the screen as it is now, and next, the cursor for
the following call (no cursor starts one at the end). Only scrollback is final:
an agent redraws its screen in place, so the screen comes whole every time, and
one that draws a full-screen view (Copilot) scrolls nothing off. The cursor is
opaque; when the rows it marks are gone it is placed again by content, and when
that fails the reply says reset and holds the newest lines. At most lines
(default 200, at most 5000) come back, newest kept, with skipped counting the rest.
Done, the change counter and events
Agent info also carries done (a turn finished and the agent has not worked
since) and state_seq, a number that goes up each time the
state changes. HQ alerts once per state_seq value, which is how a finished
turn or a blocked dialog is reported once and not once a minute. The host sends
an events.poll event for every change, whether an agent reported it or its
screen showed it, and HQ’s daemon long-polls it so the supervisor runs within
seconds of a change; its once-a-minute sweep stays as the safety net.
Agent-reported state
Claude Code can tell the host what it is doing. HQ launches it with
--settings <run dir>/hooks/<name>.json, a per-launch file (mode 0600), so
nothing is written to your own Claude configuration. The file runs
hq host report on SessionStart, UserPromptSubmit, Stop and
Notification; the command prints nothing and always succeeds, so a missing
host never disturbs the agent. The host then knows the agent’s state as the agent
reports it, and the agent’s own conversation id (agent_session_id, the id
claude --resume takes). Agent info shows rule: "hook:<event>" when a report
decided the state.
The screen still has the last word where it is more reliable: a dialog on screen
is blocked, a reported blocked ends when the dialog is gone (approving one
fires no hook), and a reported working that has printed nothing for 15 seconds
while the screen reads idle gives way to idle (an interrupted turn fires no
Stop).
Each pane gets its own token (HQ_HOST_TOKEN) and the socket directory
(HQ_HOST_DIR). That token can call agent.report for its own agent and
nothing else: any other method, or another agent’s name, is forbidden. It
lives in memory only and stops working when the agent is removed. Anything the
agent runs can read it, so it can also misreport its own state, which the
agent could do by printing to its screen anyway.
What the host does not protect against
Without a sandbox an agent runs as the same operating-system user as the host.
It can read operator.token in the host directory (HQ_HOST_DIR is in its
environment) and do everything the operator can, and it can read the MCP config
files under mcp/, which hold the HQ tokens of the other sessions. The pane
token and the scope check only keep an honest agent in its lane.
The process sandbox
agent.spawn takes a sandbox; HQ sends one for every launch on a built-in
host (agent_host.sandbox, default mode process). In process mode the host wraps
the agent in sandbox-exec (macOS) or bwrap (Linux) and refuses to start it
when that is not possible. How much it takes away depends on the profile,
agent_host.sandbox.profile:
open(the default): the agent works as you would in a terminal. What is walled off is HQ itself, other accounts’ logins and, by default, your credential stores.strict: a narrow allowlist for reads, writes and the network, for agents nobody is watching and machines that hold more than you want them to see.
agent_host:
sandbox:
profile: open # or strict
hide_credentials: true # open only; false lets agents use ~/.ssh, gh, aws, ...
The host’s own gate (hq host serve refuses unsandboxed agents) looks at the mode, so an
open agent counts as sandboxed. A host that predates profiles ignores the setting and
applies the strict policy; HQ sends the strict allowlist along in either case so such a host
still reaches the model. hq host status shows each agent as process/open, process/strict
or none.
Client folders: strict_paths
Folders whose code is confidential run under strict even when the default profile is open:
agent_host:
sandbox:
strict_paths: ["~/clients/*"] # a path or a glob; `*` matches inside one folder name
allow_domains: ["registry.npmjs.org", "github.com", "crates.io", "static.crates.io"]
A session whose working directory (or worktree) lies under a listed path gets the strict
profile: the network is the allowlist, credential stores are hidden and writes stay in the
project. The allowlist is api.anthropic.com, the HQ MCP endpoint and allow_domains; add the
package registries, the git host and the model APIs your project needs, then read the denied
hosts the proxy logs. If the strict sandbox cannot be applied the launch fails; it never falls
back to open. The list is empty by default. hq doctor prints the strict paths and the
allowlist in force.
The open profile
An open agent can read and write anything your user can, use the machine’s network directly
(no proxy and no allowlist, so a package registry, a git remote, a database or a dev server on
localhost, and a Docker socket all work), share /tmp, /var/tmp and /run, and use the
machine’s devices. git push -u, a repository’s own hook installer, brew install,
cargo install and npm install behave as they do in your terminal.
What it cannot do:
- Read or write HQ’s own files. The host directory except its own
agent.sock, hook and MCP files (the operator token and every other session’s token live there);~/.hq; the vault’s_datafolder (the database with sign-in tokens, owner approvals and paired devices, and the TLS and web push keys); and the config file in force (HQ_CONFIG_PATH,~/.hq/config.yamlor/opt/hq/config.yaml) with its backups and every*.envfile beside it. A server installed withdeploy/install.shkeeps its env files in/etc/hq, root-only, out of every agent’s reach. The env files older service units loaded from beside the config (mcp.env,openrouter.env,gws.env,gh.env) are still masked even when you have none, so an agent cannot create one for such a unit to load at its next start; under bubblewrap the host makes each missing one, empty and private, so the mask has a file to land on. The host resolves the vault and config the way HQ does on its own machine whenhq host servestarts, so restart the host after moving either.hq host installwritesHQ_VAULT_PATHandHQ_CONFIG_PATHinto the service when they are set in the shell you run it from, and the host logs an error at start when the vault it would protect does not exist. Hiding the host directory stops reads ofhost.sock, and on macOS, where a unix-socket connect counts as outbound network rather than a file read, a connect to it is denied as well, so a pane cannot sit on the host’s pending connection slots; the agent’s ownagent.sockstays reachable for its hooks. - Change what HQ loads into its own sessions or acts on. The vault’s
_system,_threads,Agents,_agents,skills(and its older spellingsSkillsand_skills),_commands,_mailboxes,_moc,_plansand_embeddingsfolders are read-only to it, and the folders above them cannot be renamed. A file in_mailboxes/relayis acted on as a request, so a pane cannot leave one there. Notes elsewhere in the vault stay writable. - See other processes’ environments (
ps eww,/proc/<pid>/environ), which hold the daemon’s and the other agents’ tokens. The price is thatps,lsofandkillshow only the agent’s own processes: a server an earlier session left running is invisible, so pick another port. - Read other accounts. Other Claude profiles (
~/.claude-<name>); the default~/.claudeand~/.claude.jsonwhen a launch profile sets its ownCLAUDE_CONFIG_DIR; and the login and history directories of the other coding agents (~/.codex,~/.gemini,~/.cursor,~/.hermesand so on). Each agent keeps its own and none can read another’s. - Read or write the credential stores (by default):
~/.ssh,~/.gnupg,~/.aws,~/.kube,~/.docker,~/.config/gh,~/.netrc,~/.npmrcand~/.git-credentials. This is the one default kept on purpose: anything an agent can read it can send anywhere, and a prompt-injected agent would use your keys as readily as you would. The cost is thatgitover ssh,gh,awsandkubectldo not work from an agent until you allow them.hide_credentials: falselifts it for every agent.agent_readablereveals one directory, read-only, to one kind of agent without that. - Write the files your own tools run later, outside the sandbox: shell startup files
(
~/.zshrc,~/.bashrc,~/.profileand the others),~/.gitconfigand~/.config/git, login items (~/.config/autostart,~/.config/systemd/user,~/Library/LaunchAgents),~/.claude.json, and Claude’ssettings*.jsonandhooksin its config directory. Also what HQ itself runs or serves: thehqbinary (~/.local/bin/hq,~/bin/hq, the binary the host runs from and the path it was started as, andself_update.install_paths), the MCP client configshq mcp installwrites (~/.cursor/mcp.json, VS Code’s usermcp.jsonandsettings.json, Claude Desktop’s config,~/.copilot/mcp-config.jsonandmcp.json, opencode’s and Antigravity’s) and Codex’s~/.codex/config.toml, each of which names commands its client runs later; and the web UI HQ serves (web_static_dir, or each folder HQ would look in up to the one it serves from), unless it lies in the agent’s own project. HQ no longer looks for its UI in awebfolder beside the binary (except on Windows) or, with the vault at~/.vault, in~/web/distor~/apps/hq-web/dist/client, all of which any program you run could create ahead of the installed UI. The directories above them cannot be renamed, so~/.local/bincannot be moved aside for a planted copy; other files in them stay writable. Codex cannot record a folder as trusted in its ownconfig.tomlfrom inside the sandbox. A project’s own.git/hooks,.git/config,.mcp.jsonand.claude/settings.jsonare writable. - Start
open,osascriptorlaunchctl(macOS), or look up the launcher service. An app started that way runs outside the sandbox. - Drive the machine’s control sockets. The open profile shares
/run, so the Docker daemon socket and the user’s systemd-manager and session-bus sockets underXDG_RUNTIME_DIR(systemd/private,bus,docker.sock) are masked: a connect to one fails, sosystemd-run --useranddockercannot reach a manager that would start a process outside every namespace. The agent’s own SSH, gpg and keyring sockets in the same directory stay reachable. On macOS the equivalent is blocked by the denied launcher service.
This leaves one residual on Linux under this profile: the network namespace is the machine’s
own, so a service listening on an abstract unix socket (one with no filesystem path) is still
reachable, and an X11 server at /tmp/.X11-unix is reachable if one is running. Neither carries
HQ’s own authority; both come with sharing the machine’s network, which the open profile does on
purpose. Use profile: strict (it gets a private empty /run and its own network namespace) for
agents running on untrusted content on a machine where that matters.
One more thing shares the machine’s network: HQ’s own web server. An open-profile agent keeps
loopback, so if HQ’s web runs on this machine with no web_auth_token set, the agent can call
http://127.0.0.1:<web port>/api/... with curl and act as the owner through the web API (a
command-line request sends no Origin, so the origin guard does not stop it). This is the
tokenless-loopback convenience working as designed, not a hole the sandbox can close while the
network is shared: the API is the owner’s, reached from the owner’s machine. When you run agents
on untrusted content, set web_auth_token (every web and API call then needs the bearer token,
which is not in the agent’s environment) or run those agents under profile: strict (its proxy
network reaches only the model and the listed hosts, never loopback). The strict profile’s
loopback_ports opens a named local port to an agent deliberately; the web port is not one of
them unless you add it.
This is a wall around HQ, not a boundary against an agent that means harm. It reaches
everything else you can, and a prompt-injected agent can read a file and send it anywhere.
The guard against that is the agent’s own permission mode and classifier, as in your terminal.
Under bubblewrap a rule needs a path that exists, so before each launch the host makes every
protected directory you do not have yet, private to you (mode 0700): ~/.config/systemd/user,
~/.config/autostart, ~/.config/git, Claude’s hooks, the vault folders above and a web UI
folder HQ would look in. It does not make files, since an empty one would change what your
tools do, so a protected file you do not have can still be created by an agent there: a
~/.zshrc or other shell startup file, ~/.gitconfig, Claude’s settings.json, an MCP client
config you have never written, or hq in a bin directory it is not installed in. Nor does it
make skills in a vault that keeps its skills under an older spelling (Skills, _skills):
HQ would switch to the new empty folder. The host warns about that case instead; rename the
folder to skills. Seatbelt denies a path whether it exists or not. The directories above a protected
path (~/.config, ~/.claude and the like) cannot be renamed or removed, so a protected path
cannot be moved aside and replaced; work inside them is unaffected. allow_domains, writable,
readable and loopback_ports do nothing under this profile.
The strict profile
The agent:
- cannot read the run directory except
host.sockand its own hook and MCP files, nor~/.ssh,~/.gnupg,~/.aws,~/.kubeor~/.hq, nor the vault’s_datafolder or HQ’s config file and the env files beside it, wherever they are, and cannot write the vault folders HQ loads into its sessions (as under the open profile); - can write only its project,
~/.claude, caches and the temporary directories (plusagent_host.sandbox.writable); - cannot see other processes’ environments;
- can read under your home directory only what the policy lists (its own state,
tool installs, shell and git configuration, caches, and
agent_host.sandbox.readable), and cannot write~/.claude.json: the host records trust for the project itself, so the agent cannot plant an MCP server command there; - can connect only to its own egress proxy, the agent socket (
agent.sock, pane tokens only, with its own connection limits, so an agent cannot crowd the operator offhost.sock) and anyagent_host.sandbox.loopback_ports(below). The proxy allowsapi.anthropic.com, the HQ MCP endpoint andagent_host.sandbox.allow_domains, resolves names itself, and refuses private, loopback and link-local addresses unless the endpoint is the MCP one or a listed loopback port. A tunnel must open with a TLS hello naming the host it asked for. Every decision is logged (agent.egress); a denied host shows up there so you can add it.
Two opt-in settings widen the strict profile for one machine’s own needs:
agent_host:
sandbox:
# A local model server and the adb server on the agent's machine.
loopback_ports: [11434, 5037]
# Only Claude Code may read gh's configuration, and never write it.
agent_readable:
claude: ["/home/alice/.config/gh"]
loopback_ports lets an agent reach those ports on its own machine. A client
that sends loopback requests to the proxy (curl does) gets there through it as
plain HTTP, logged like any other request, on every platform. On macOS the sandbox also allows a
direct connection of any protocol to exactly those ports, which is what adb and
clients that ignore HTTPS_PROXY (Dart’s HttpClient) need. Under bubblewrap
loopback inside the sandbox is the sandbox’s own, so only the proxied HTTP path
works there. Every agent on the host gets these ports: a port that drives
something (adb reaches every attached phone and emulator) is a capability, so
list only what agents should have.
agent_readable maps an agent kind (claude, codex, agy, hermes, …;
not a harness or profile name such as claude-code) to paths only it may read.
Naming one of the credential directories exactly (such as ~/.config/gh) lifts
its hiding for that agent alone and keeps it read-only. ~/.hq is never
revealed.
Paths use the agent machine’s absolute paths; one that does not exist there is
skipped.
The host itself decides whether the sandbox is optional. hq host serve refuses
to start any agent that is not under the process sandbox (either profile), whoever asks over the
socket or through the gate; start it with --allow-unsandboxed to lift that, and
agent_host.sandbox.mode: none in HQ only matters then.
Agents nobody is watching are stopped: a session silent and not working for
agent_host.idle_reap_hours (default 24, 0 turns it off) is stopped by the host, even
if HQ is down, and is not restored at the next start. HQ marks it exited and
tells you, and the conversation can be resumed. hq host status lists every
agent with its state, sandbox mode, idle time and age. A busy agent is never
reaped.
Under the strict profile each agent also gets what it needs to be that agent: its own login and history directory
(~/.gemini for Antigravity, ~/.codex, ~/.cursor, ~/.copilot, ~/.pi, ~/.hermes,
~/.openclaw and so on, and never another agent’s) and the HTTPS hosts it
signs in and reaches its models through. Those defaults are verified for Claude Code and
Antigravity; for agents that talk to whichever provider you configure (opencode, kimi, qwen,
and the general-purpose agents hermes and openclaw) add the provider’s host to
agent_host.sandbox.allow_domains. Only Claude Code is handed an HQ session token and MCP
configuration; a general-purpose agent is never wired into HQ that way.
The sandbox policy is kept in session.json and applied again on restore.
agent.list shows each agent’s mode and profile and host.status counts agents running
with none.
A strict agent cannot write ~/.claude/settings*.json, ~/.claude/hooks, or in its
project .git/hooks, .git/config, .mcp.json and .claude/settings*.json,
where it could plant code you run later outside the sandbox, and it cannot start
open, osascript or launchctl. The host refuses to start a strict agent in a
directory that contains your home, the host directory or a secret directory.
What the strict profile does not stop: the agent still reads and writes your project and
~/.claude (outside the read-only files above); on macOS the Keychain stays reachable because Claude Code keeps its
login there; your own MCP servers, plugins and connectors are refused until you
allow their hosts; a kernel flaw or an allowed domain is out of scope. On Linux
(including WSL2) bwrap has no network of its own, so the agent reaches the proxy
through a unix socket and a relay inside the sandbox; a path that does not exist
(a .mcp.json the project lacks) cannot be protected there, and each agent gets a
private empty /tmp, /var/tmp and /run.
The host bounds what a client can make it hold: 128 agents, 64 KiB of command
line each, window titles cut to 256 bytes, conversation ids limited to short
plain tokens, agent.wait to 10 minutes, a reply that would not fit one
protocol line replaced by an error, and a pane that stops reading its terminal
fails a write after 5 seconds instead of holding the connection. A client also
refuses a host directory that is not owned by you and private to you.
Git the host runs
The host itself runs git, outside every sandbox, in repositories an open agent can write:
worktree.add, worktree.status, worktree.remove, the .worktreeinclude copies, and
agent.head. A repository’s configuration can name commands git runs on its own, and those
would run with the host’s reach rather than the agent’s. So host git runs with
core.fsmonitor=false, no hooks (core.hooksPath=/dev/null, which also stops
post-checkout on worktree add), no transport at all (protocol.allow=never, so no lazy
fetch, core.sshCommand or remote helper), log.showSignature=false (no gpg.program), and
every filter driver the configuration names emptied for that command. The host never asks
for a diff, so textconv and external diff drivers never run.
The one operation that does use the network is worktree.publish, which pushes a branch the
host has checked and opens its pull request. Its own checks and limits are in
docs/security/PUBLISH.md.
The git it runs, like the bwrap it wraps agents in, is taken from a directory only root
can write (/usr/bin, /bin, /usr/local/bin, then any such PATH entry), never from the
first match on PATH: a service’s PATH can include ~/.local/bin, which an open agent can
write. Only when no root-owned copy exists does it use the first on PATH, with a warning.
The services hq host install writes also list ~/.local/bin and ~/bin after the system
directories.
HQ’s own git tools (git_status, git_log, git_diff, git_commit, git_pr) run git the
same way, since they too run outside any sandbox in repositories an agent may have written.
Two differences: a diff is always taken with --no-ext-diff --no-textconv, and a push
(git_pr) needs a transport, so it keeps every other pin and refuses outright when the
repository’s own configuration names a program a push would run (core.sshCommand,
core.gitProxy, core.askPass, a credential helper, a remote’s receive-pack). A signing
program set in the repository’s configuration falls back to the standard one; one the owner set
globally is used as it is. git_commit therefore no longer runs the repository’s hooks.
What is left: filter drivers are read from the configuration just before each command, so an
agent that adds a new driver in the moment between the two can still have it run once by the
host. The strict profile closes that, since a strict agent cannot write .git/config. Running
host git inside the agent’s own sandbox would close it for the open profile too; that is not
built yet.
Agent compatibility
What each agent needed to start under the strict sandbox, and whether it has been run signed in end to end. Under the open profile none of the state directories or hosts below need listing; the agent only needs its login. A launch that fails for a reason on this list is a known quirk, not a new bug. Login state is the user’s: HQ cannot sign an agent in for you, and an agent with no login shows its own sign-in screen.
| Agent | Run signed in | What HQ does for it |
|---|---|---|
| Claude Code | yes | Writes only its config directory; DISABLE_AUTOUPDATER=1; project trust recorded by the host. Hooks named in its settings must live in a readable path (add the directory to agent_host.sandbox.readable, and any state directory to writable), or the prompt hook fails and every prompt is blocked. |
Antigravity (agy) |
yes | Own state in ~/.gemini; Google sign-in and model hosts allowed; trust dialog answered at launch. |
| Codex | yes | Starts with --no-daemon (its daemon check reads other processes, which the sandbox forbids), also on resume. |
| Cursor | yes | No --trust (headless only); the workspace trust dialog appears on first use in a folder and the first prompt can be lost to it, so send the prompt again. *.cursor.sh allowed. |
| pi | yes, reaches its model | Session directory is {home}/.pi/hq-sessions/<id> on the host that runs it. Uses whichever provider you logged into, so add that provider’s host to agent_host.sandbox.allow_domains (Google’s Gemini API is built in). |
| GitHub Copilot, opencode, kimi, qwen | no | Hosts for the first are built in from its documented domains; the others depend on the model provider you configure, so add it to agent_host.sandbox.allow_domains. |
Every Node-based agent (Cursor, pi) needs NODE_USE_ENV_PROXY=1 to send its requests through the
egress proxy; the host sets it for all agents.
Lockdown
The kill switch for agents nobody asked for. While lockdown.json (mode 0600)
sits in the host directory, agent.spawn and agent.resume answer
locked_down, and a host that starts up restores nothing. A lockdown forgets
the agents it stopped and any waiting ones, so unlocking brings none of them
back by itself; the agents’ own transcripts stay, and HQ keeps what it needs to
resume one on purpose (harness_session_resume).
- Locking is open to everyone who can drive the host:
hq host lockdown "<reason>"on the machine, thehost.lockdownmethod (also through the ssh gate), HQ’shost_lockdowntool, which locks every host when none is named (from a claude.ai connector it waits for the owner’s approval like the other host tools, since one call stops every agent everywhere), and the Stop all button on the web app’s Workbench page (beside New agent, one tap and a confirmation on a phone;POST /api/workbench/lockdown). The Workbench names any locked computer above its agent list. It kills every agent the host runs with its whole process group at once (no grace period, so a child that ignores SIGHUP dies with its running agent; children left behind by an agent that already exited are not reached). A start that raced the lockdown is killed as soon as it lands.hq host lockdownwrites the file before it asks the host, so new starts are refused even when the host is wedged or down. A host that cannot write the file stays locked in memory until it restarts. - Unlocking is only
hq host unlockon that machine, which deletes the file. No method unlocks, so a key that can drive the host from elsewhere cannot lift a lockdown, and sandboxed agents cannot reach the directory. - The breaker.
hq host servelocks itself when more than--max-startsagents (default 50) start within 10 minutes. It refuses the start that went over but stops nothing already running. Only starts that succeeded count; agents restored or resumed after a restart do not. - The cap.
--max-agents(default 64) bounds the agents running or waiting at once, so a slow leak stops at a known number. A host running a large fleet (more than 64 agents, or a burst of more than 50 starts in 10 minutes) passes higher values tohq host serve, for example--max-agents 256 --max-starts 300, and raises the matchingagent_hostceilings (spawn_limits,teams,max_driven_sessions), which go up to 500 live sessions and 6000 starts an hour. Saved agents over the cap at startup wait instead of being dropped. - Alerts. A lockdown is an event (
kind: lockdown, the reason inrule). HQ’s daemon raises an action-needed inbox item and an interrupting relay message for it. - Tests. A cargo test binary that resolves a real host through
NativeBackendrefuses every call it makes to the machine’s own host directory or to a remote over the realssh; a test uses a temporary host directory or a stand-in program. A test that forgot its folder once started real agents this way.
The lockdown covers agents this host runs. Agents a person starts in a terminal, and other tools that start agents, are outside it.
Restarts
The host keeps session.json in its directory (mode 0600). It lists every
running agent that was spawned with a resume_argv: the command that continues
the old session, for example ["claude", "--continue"], together with its
working directory, agent kind, size and the names (never the values) of the
extra env variables it was started with, so no key or token is ever written
to disk. The file is rewritten when an agent is spawned, removed, told to stop, or
exits.
On hq host serve the host starts each listed agent again with its
resume_argv, in the same name and directory. These are fresh processes: what
survives is whatever the agent itself resumes (Claude Code’s conversation, for
instance), not the old process or its scrollback. An agent that exited, was
removed or was told to stop is not listed. One that cannot be started (its
directory is gone, say) is reported and skipped; the others still come back.
Agents spawned without a resume_argv are not brought back.
An agent that was started with extra env is not started on its own, because
the host no longer has those values. It is listed by agent.awaiting and starts
when whoever launched it calls agent.resume with the values again (HQ rebuilds
them from the same profile and session id it used at launch). An agent started
without extra env still comes back by itself.
A host that stops cleanly (hq host stop, SIGTERM, Ctrl-C) stops its agents but
leaves them listed, so the next start brings them back. A host that is killed or
crashes leaves the file as it was, with the same result.
session.json holds commands the host will run, so it is used only when it is a
regular file owned by you with mode 0600 inside a directory you own; otherwise it
is ignored and reported. A file that does not parse is moved to
session.json.unreadable.
host.status has binary_stale: true when the executable the host started from
has been replaced on disk (a new build was installed). A running host keeps
working after its binary is replaced; restart it when agents_working and
agents_blocked are 0, or when you choose to. Restarting means stopping the host
and starting it again, normally through the service manager, for example
systemctl restart hq-host.
Example service files (not installed by HQ yet). On macOS use a LaunchAgent (a login-session job), not a LaunchDaemon: Claude Code’s login lives in your Keychain, which a system daemon cannot reach. Keep the hq binary outside ~/Documents, ~/Desktop and ~/Downloads, which launchd jobs may not read:
# /etc/systemd/system/hq-host.service
[Service]
User=hq
ExecStart=/usr/local/bin/hq host serve --dir /var/lib/hq/host
Restart=on-failure
KillMode=process
<!-- ~/Library/LaunchAgents/com.example.hq-host.plist -->
<dict>
<key>Label</key><string>com.example.hq-host</string>
<key>ProgramArguments</key><array>
<string>/usr/local/bin/hq</string><string>host</string><string>serve</string>
</array>
<key>KeepAlive</key><true/>
</dict>
What an agent process inherits
A pane starts from an empty environment plus: PATH, HOME, USER, LOGNAME,
SHELL, LANG, LANGUAGE, LC_*, TMPDIR, TZ, COLORTERM,
XDG_CONFIG_HOME, XDG_DATA_HOME, XDG_CACHE_HOME, XDG_STATE_HOME,
TERM=xterm-256color, and whatever env the spawn request passes. Credential
handles are deliberately not inherited: SSH_AUTH_SOCK would let an agent sign
with your keys and XDG_RUNTIME_DIR reaches your dbus, gpg and systemd
sockets. Pass one in env when an agent really needs it (for example git over
ssh). Markers and secrets of whatever
started the host (for example another agent session’s CLAUDE_CODE_*
variables, which switch transcript saving off) never reach an agent.
Using it from HQ
HQ_HOST_DIR overrides where HQ looks for the host (default ~/.hq/run/host),
which is also how a second, isolated host is run for testing. A launch is
reported ready only after the agent has drawn its first screen and gone quiet;
an agent that is still starting, or sits at a dialog such as Claude’s folder
trust prompt, is reported as blocked with its screen and no prompt is typed.
A Claude Code session resumes into its own conversation: once its hooks report
the conversation id, HQ stores it as the session’s resume token and gives the host
a restart command that uses --resume <id>. Until the id is known, resume falls
back to -c (the most recent conversation in the directory).
New coding-agent sessions start on agent_host.default_host in ~/.hq/config.yaml
(native, the host on the machine HQ runs on, unless you name a paired machine).
native and local both mean that host. A session keeps the host it was started
on, so changing the default never moves a running session. After a host restart the
supervisor starts any held agent again with the env HQ built for it at launch
(profile variables and the session id), once per sweep.
host_overview: one snapshot of every host
host_overview (read-only, crates/hq-tools/src/agent_host/overview.rs) asks every
configured host at once and returns one row each: reachability (reachable,
unreachable or unknown), checked_at, version, a short reason when it is not
reachable, the agents the host sees (only for a reachable host), which harness programs
the host can start (true, false, or "unknown" where the host cannot tell), and the
lane quota rows.
- Each host runs on its own blocking thread with its own time limit (
HOST_TIMEOUT), and the whole call is capped byOVERALL_BOUND. A host that says nothing in time isunknownwith the reasonno answer from the host within the time limit; it is never shown as reachable. Reachability comes from a live call, never from config. - A host reports in steps (version, agents, quota) and what finished before the deadline is kept, so one slow step or one failing host never hides the others.
- Reachable means the host answered. It does not mean an agent is signed in or that a session can start.
- Quota rows carry
status:available(read now or within the sampling interval),stale(an earlier reading, with its age; also anything older than the sampling interval),not_exposed(the lane has no balance to read, such as the spend ledger) orcheck_failed(the reader failed, with the reason). Each row namesmetric,units,observed_atandsource. A configured limit is not a remaining balance, and unknown is never turned into zero. Seedocs/LANE_QUOTAS.md. mode:cached(default; reuses readings taken within the sampling interval) orrefresh(asks the hosts now). Both obey the time limits.- It does not scan any filesystem and reads no credentials.
A host on another machine
HQ on a server reaches a host on your laptop (or any machine) over ssh. Pair it with
hq host join on the machine and hq host add (or the host_add tool) on the HQ,
which creates the key and the config entry and prints the one hq host authorize
command the machine runs; the steps, including WSL2, are in
JOIN_A_MACHINE.md. The result is a pinned line in the machine’s
authorized_keys:
restrict,from="<hq-server-address>",command="/home/you/.local/bin/hq host gate" ssh-ed25519 AAAA... hq-gate-laptop
and a config entry:
agent_host:
hosts:
laptop:
ssh: "you@laptop.example.ts.net"
identity_file: "/opt/hq/.ssh/hq_gate_laptop"
# port: 2222 # when ssh does not listen on 22
Sessions started with host: laptop run there. hq host gate reads one request
from stdin (a JSON array of a method name and its params as JSON text, so no
shell parses either), refuses any method outside an allowlist (host.stop and
agent.report are left out), forwards it to the local socket and prints the
reply. The key cannot run anything else: a command passed to ssh is ignored.
agent.spawn still starts whatever command it is given, so treat the key as
shell access as you. A missing agent binary on the remote machine comes back as
the host’s own spawn_failed error naming the command. The hook settings file is
written on the remote machine by the host (agent.hook_flags), so hooks,
conversation ids and resume work the same as locally.
agent.hook_flags also takes policy, the command policy a Claude Code agent runs under
(a JSON object of at most 64 KiB, which the host stores and never reads). The host writes it
next to the hook settings (hooks/<name>.policy.json, 0600) and adds a PreToolUse hook on
the shell tool that runs hq host policy-check <that file>. The hook reads the tool call on
stdin and prints a deny decision when the policy denies the command, so a deny holds under
--dangerously-skip-permissions too. It fails closed: a policy file it cannot read, or a call
too long to read whole (256 KiB), is refused. A later agent.hook_flags without policy (a
restart) keeps the stored one, and the file goes with the agent’s other files.
Over a private tunnel instead of ssh
A host can also be reached over TCP on a private tunnel address (for example a
WireGuard network between your server and your laptop), with no ssh on either side.
The caller proves itself with an Ed25519 key, so there is no shared secret and no
password to leak. Nothing listens unless agent_host.gate_listen is set. hq net sets up the
WireGuard tunnel itself without hand-written wg commands: see PRIVATE_NETWORK.md.
On the machine that runs the host:
agent_host:
gate_listen: "10.77.0.2:7747" # the machine's tunnel address, never 0.0.0.0
gate_allowed_sources: ["10.77.0.1"] # the server's tunnel address; required
On the HQ server, make a key for the host and read its public half:
hq host gate-key laptop
Then, on the machine, authorize it from the server’s tunnel address only:
hq host authorize --gate-key <public key> --from 10.77.0.1 laptop
and point the server’s config at the machine:
agent_host:
hosts:
laptop:
transport: tcp
addr: "10.77.0.2:7747"
How it holds up:
- The listener refuses to start on an unspecified address, on an address that is not loopback
or private (a public one), or with an empty
gate_allowed_sources. A gate that is configured but invalid stopshq host servebefore it starts anything, instead of leaving you unsure whether it is open. If the address is one the machine does not have yet (the tunnel comes up after login), the host starts and the gate binds as soon as the address exists. A config file that cannot be read at all leaves the gate off, with a warning. - A source outside
gate_allowed_sourcesgets a closed connection and nothing else. An allowed source gets a one-line challenge with a fresh random nonce. A caller whose key is not in~/.hq/gate_authorized_keys(or who connects from an address that key is not pinned to withfrom=) gets a closed connection, with no reply to tell it why. - The signature covers the nonce and a digest of the request, so a recorded exchange
cannot be replayed, and the request is read only after the key is known. The request
then goes through the same method allowlist as
hq host gate. - Limits: 5 s to authenticate, 10 s to read and write, 16 connections at once. There is no
lockout after failures, because keys cannot be guessed and a lockout would let anyone who
can reach the gate from the allowed address shut the real caller out. Whoever can connect
from an allowed address can still hold the 16 slots for a few seconds each, which is why
gate_allowed_sourcesshould be only the server’s address on the tunnel. - The authorized keys file is read on every connection, so revoking a key takes effect at once. It and the key files must be plain files (no links) owned by the user running HQ; the authorized keys file must not be writable by group or others, and a key file not readable by them. Otherwise the gate refuses every key.
- The chat shell cannot read
~/.hq/gate/*or write~/.hq/gate_authorized_keys. If you pointgate_key_fileorgate_authorized_keyssomewhere else, keep that path out of reach of agents yourself. - The key can start any command as you inside the agent sandbox, like an ssh login: keep
gate_allowed_sourcesto the one address the server uses on the tunnel.
What the gate does not do: it does not encrypt, and the server does not prove who it is to the
caller. Both come from the tunnel (WireGuard encrypts and only the peer holding the other key
can answer on that address). Use it on a machine only you log in to: on a shared machine
another local user could listen on the tunnel address while the host is down and receive the
server’s calls, which include the HQ MCP token. Use the ssh transport there. Signed replies and a
pinned server key would close this and are listed in TECHDEBT.md.
The wire protocol is written out in crates/hq-gate/src/lib.rs.
Day to day
- A call costs one ssh round trip plus about 40 ms for the gate on the laptop;
agent_host.ssh_multiplexkeeps the ssh connection open between calls. State changes arrive as events instead of one poll a minute. - A laptop that is asleep or off the tailnet is skipped, not marked dead; its
sessions are picked up again when it answers. After
agent_host.unreachable_alert_minutes(5 by default) of silence HQ raises one alert, and says when it is back. agent_host.keep_awake: while_sessionsin the laptop’s own config makeshq host servehold a sleep assertion while at least one agent’s process runs, and let go when the last one ends:caffeinate -i -w <host pid>on macOS,systemd-inhibit --what=sleep:idleon Linux. The assertion watches the host’s pid, so a host that dies does not keep the machine awake. Off by default. Closing the lid on battery still sleeps a Mac, and a Linux machine that refuses the inhibitor (no permission for it) is told once on the host’s stderr.- No terminal UI:
hq host statuson the machine andharness_session_listin HQ show every session. A session silent and not working foragent_host.idle_reap_hours(24 by default) is stopped by the host itself and can be resumed; HQ tells you it ended. Set it to 0 to keep sessions until stopped. - Your own MCP servers, plugins and connectors are refused inside the sandbox until their hosts are allowed; the host’s egress log names each denied host.
Not built yet
Rule files for agents other than Claude Code and Codex, hooks, MCP config and sandbox-aware launching for agents other than Claude Code, Host-header fronting inside TLS, and reads outside your home directory. Provenance of anything adapted from the project this host replaced is recorded in docs/provenance/herdr.md.