Quickstart
Run the daemon from the CLI or supervise agents from code, then pair a viewer and drive the same daemon from another process.
@viewportai/daemon runs agent processes on your machine and streams them to viewers. Three ways in:
- CLI (
viewport-daemon, aliasvpd): a background daemon you start, pair and drive from a terminal. - Library (
@viewportai/daemon): a supervisor that starts sessions, records every event, and asks before tool calls. - Viewer (
@viewportai/daemon/client): pairs with a daemon by key and controls its sessions over an end-to-end encrypted channel. Browser-safe.
Status: v0.1, released as @viewportai/daemon 0.32.0. The CLI, the library, the server, the viewer client and the relay client work.
Install
npm install -g @viewportai/daemon # Node 22 or later; installs viewport-daemon and the alias vpd
cd ~/your-project # sessions run in the current directory, never in the cloneTo work from source instead, with Node 22.18 or later (on Node 25+, which ships without corepack, run npm i -g corepack first):
git clone https://github.com/viewportai/daemon.git
cd daemon
corepack pnpm install
corepack pnpm exec tsup # dist/, including the CLI at dist/cli/bin.js
alias viewport-daemon="node $PWD/dist/cli/bin.js"
cd ~/your-projectRun sessions from a project directory, not from the clone: the daemon's own code is protected from its agents, so a cwd inside the clone is refused. See Security.
The claude-code runner also needs @anthropic-ai/claude-agent-sdk (a dev dependency here) and a token, see
Security. Every example runs without either: make examples.
This rebuild ships as @viewportai/daemon 0.32.x. Versions 0.31.x on npm are the earlier codebase with a
different protocol.
Building needs Node 22.18 or later: older Node 22 releases bundle a corepack whose npm signing keys are out of date
(corepack pnpm install fails with "Cannot find matching keyid"), and the build tools require 22.18. The built
package runs on Node 22.0 or later. On Node 22, WebCrypto X25519 prints an ExperimentalWarning; it is safe to
ignore.
CLI
Start a background daemon. Its local API is the Unix socket ~/.viewport/daemon/daemon.sock, guarded by the token
in ~/.viewport/daemon/token (0600). Every other command talks to the daemon only through that socket.
viewport-daemon up # detached daemon; log in ~/.viewport/daemon/daemon.log
viewport-daemon status # daemon_id, endpoints, relay state, child isolation, warnings
viewport-daemon run -- npm test # start and wait: streamed here and to viewers, exits with its code
viewport-daemon start claude-code "fix the build" # background session, prints its id
viewport-daemon ls # sessions, newest first
viewport-daemon attach ses_01JDQ... # live stream; Ctrl-C detaches, the session keeps running
viewport-daemon stop ses_01JDQ...
viewport-daemon down # stop the daemon and every sessionserve runs the same daemon in the foreground, for a service manager or a container. up and serve take
--direct host:port (default 127.0.0.1:7070, port 0 picks one) or --no-direct, --relay <url>,
--name, --console <url>, --local-approvals and --no-local-pairing. A relay token never goes on the command
line, where ps would show it: set VIEWPORT_DAEMON_RELAY_TOKEN, or pass --relay-token-file with a 0600 file.
A plain ws:// relay URL must be on loopback; anything else needs wss:// (or --relay-allow-insecure-ws, which
sends the token in cleartext).
VIEWPORT_DAEMON_RELAY_TOKEN=... viewport-daemon up --relay wss://relay.example.com --no-direct
viewport-daemon up --home /srv/vpd --direct 0.0.0.0:7070 # another home; or set VIEWPORT_HOMErun forwards your keys to the session's terminal when stdin is a TTY. Otherwise Ctrl-C interrupts the session
and a second Ctrl-C stops it. Answering approvals from the terminal needs a daemon started with
--local-approvals; by default only paired controllers answer, so an agent running as your user cannot approve its
own tool calls with the local token.
viewport-daemon up --local-approvals
viewport-daemon approval show apr_01JDQ... # the full action: tool, call id, digest, every arg
viewport-daemon approve apr_01JDQ... --reason "read-only" # prints the full action, asks [y/N], answers with its digest
viewport-daemon deny apr_01JDQ...approve prints the full action before anything is sent. On a terminal it asks, and only y or yes allows.
Without a terminal (a script, a pipe) it refuses unless you pass --yes after reading the action, for example
from approval show.
Every command takes --home <dir> and --json, before or after the command name (viewport-daemon --home ~/.viewport/vpd-try up works). Put a throwaway home under ~/.viewport/: agents can never use or write a
directory there, and every daemon registers its home so the others deny it to their agents (see
Security). Commands print one JSON document; run, attach and pair print JSON lines
(the wire's event pushes, then a final {"type":"result",...}). Errors become {"error":{code,message},"exit_code"}
on stdout.
| Exit code | Meaning |
|---|---|
| 0 | OK |
| 1 | Error: the daemon refused, a request failed, a timeout, or start/run named a runner that is unavailable (for example claude-code without a login token) |
| 2 | Usage: bad flags or arguments |
| 3 | The daemon is not running |
| 4 | Child isolation unavailable (--child-isolation home with no working sandbox backend) |
| 130 | Interrupted while waiting (pair) |
run and attach exit with the session's own code once it ends (128 + n for signal n). down exits 0 when
nothing is running. viewport-daemon doctor adds checks: file modes, a stale writer lock, Node, PTY support.
status and doctor also report child isolation and which stop sweep is in use. See Security.
Next for the CLI: Pairing with viewport-daemon pair.
Library
Create a supervisor with the runners you need. command and claude-code are built in. The example registers a
scripted fake runner named agent so it runs without keys; a custom runner name is typed by declaration merging.
// A custom runner's name is typed by declaration merging. The built-ins ("command", "claude-code") need none.
declare module "@viewportai/daemon" {
interface RunnerOptions {
agent: object;
}
}approvals decides tool calls before any human sees them. Return "allow", "deny", or "ask" to hand the call
to the paired viewers. See Approvals.
const supervisor = createSupervisor({
runners: [
fakeRunner("agent", [
say("Running the tests."),
callTool("Bash", { command: "npm test" }, { approval: true, result: "1 failing" }),
callTool("Bash", { command: "rm -rf node_modules" }, { approval: true }),
say("Fixed the parser. Tests pass."),
exit(0),
]),
],
// Runs before any human sees the request: "allow", "deny", or "ask" to hand it to the humans.
approvals: ({ action }) => (/rm -rf/.test(String(action.args.command)) ? "deny" : "allow"),
});start returns a Session. It is an async iterable over its events; messages() yields final messages only;
result() resolves when the session ends.
// A session runs in a project directory, here a fresh one. Never the daemon's own checkout: agents may not write it.
const project = await fs.mkdtemp(path.join(os.tmpdir(), "quickstart-"));
const session = await supervisor.start("agent", { cwd: project, prompt: "Make the failing test pass" });
for await (const message of session.messages()) {
console.log(`${message.role}: ${message.content}`);
}
const { status, exitCode, events } = await session.result();
const asked = new Map<string, string>();
for (const event of events) {
if (event.type === "approval_requested") {
asked.set(event.approval_id, `${event.action.tool_name} ${JSON.stringify(event.action.args.command)}`);
}
if (event.type === "approval_resolved") {
console.log(`approval ${asked.get(event.approval_id)}: ${event.decision} (by ${event.resolved_by})`);
}
}
console.log(`session ${status}, exit code ${exitCode}`);Any program runs through the command runner. run is start plus result. terminal: false uses pipes;
the default is a PTY when node-pty is installed.
const run = await supervisor.run("command", {
command: process.execPath,
args: ["-e", "console.log('42 tests passed')"],
cwd: project,
terminal: false,
});
const printed = run.events.flatMap((e) => (e.type === "output" && e.data !== undefined ? [e.data] : [])).join("");
console.log(`command exited ${run.exitCode}: ${printed.trim()}`);Without home, the supervisor keeps sessions in memory and uses an ephemeral identity. With home, it writes an
append-only event log per session, a writer lock and identity.json there. See
Recovery and retries.
Viewer
Serve the supervisor, create a pairing offer, and hand the link to the viewer. The daemon below also asks the
operator to confirm full fingerprints (confirmPair).
const supervisor = createTestSupervisor({ runners: [fakeRunner("agent", [say("Hello from the agent."), exit(0)])] });
const confirmed: { peerId: string; daemonId: string }[] = [];
const server = await serve(supervisor, {
home, // daemon.sock, token and peers.json live here
direct: { host: "127.0.0.1", port: 0 }, // port 0 picks a free port
name: "build-box",
clock: supervisor.clock, // serve() takes its own clock and ids; share the test ones for a stable transcript
ids: supervisor.ids,
// pair --confirm: called once the viewer's first message decrypts, before the peer is stored.
confirmPair: ({ peerId, daemonId, role }) => {
console.log(`daemon | pairing request for role ${role}`);
console.log(`daemon | peer ${groups(peerId)}`);
console.log(`daemon | daemon ${groups(daemonId)}`);
confirmed.push({ peerId, daemonId });
return true; // the operator compared every group
},
});
const offer = await server.pair({ role: "controller", ttlMs: 60_000 });
console.log(`daemon | offer ${offer.offerId}, expires ${offer.expiresAt}`);The viewer brings its own identity and its own store of paired daemons. The client never reads or writes a default location.
const identity = await createIdentity({ privateKey: new Uint8Array(32).fill(7) });
const store = memoryPairedDaemonStore();
// Show the fingerprints before pairing: the daemon id of the link's key `k`, and this viewer's own peer id.
const link = parsePairLink(offer.link);
const daemonId = await fingerprint("vpd", link.daemonPublicKey);
const peerId = await fingerprint("vpp", identity.publicKey);
console.log(`viewer | link for ${link.name} via ${link.directUrl ? "direct" : "relay"}`);
console.log(`viewer | peer ${groups(peerId)}`);
console.log(`viewer | daemon ${groups(daemonId)}`);
const paired = await pair(offer.link, { identity, store, name: "laptop" });
console.log(`viewer | paired with ${paired.daemon.name} as ${paired.role}`);
paired.close();From then on the viewer connects in session mode by daemon_id, with no link and no secret.
// Later, from the stored record: session mode, no link and no secret.
const client = await connect(daemonId, { identity, store });
const started = await client.startSession({ runner: "agent", cwd: project, prompt: "say hello" });
for await (const event of started.events()) {
if (event.type === "message") console.log(`viewer | ${event.role}: ${event.content}`);
}
const { sessions } = await client.list();
for (const s of sessions) console.log(`viewer | ${s.id} ${s.runner} ${s.status} exit=${s.exit_code}`);Next: Pairing, Sessions and streaming, all examples.