claustrum protocol reference¶
This page gives the rules that more than one method shares: the transport, the authentication, the message shapes, the error codes and the path handling. It lists the 24 methods with the page of each.
An untagged rule on this page matches build 5fd08069 or an earlier build. A section that names its systems or its build keeps that scope.
claustrum uses newline-delimited JSON-RPC 2.0 over an AF_UNIX
SOCK_STREAM socket. Three server.* methods share one page. The error texts,
the stream frames, the flags and the
shared git rules have their own pages. The life
of the daemon off the wire is on Running the daemon. The pinned
reference build is 87375cc7.
A rule marked "claustrum's own" is not a parity claim: the reference has
no such rule, or it does something else. A D-number marks a deliberate
divergence, not the reference. A rule marked "not measured" or "from the code"
was read from claustrum's code, with no reference run. A mark "measured on
DIVERGENCES.md.
Transport¶
- One JSON object per line (NDJSON), with an
endmember. No length prefix, no binary framing. - One request line has a cap of 1 MiB. The daemon serves a line of up to 1048575
bytes. A line of 1048576 bytes or more closes the connection with no reply.
Send a large
process.stdinpayload in chunks below this cap. - claustrum binds the socket, then sets mode
0600(from the code). - The connection is persistent. It stays open after a response, and id-less stream notifications arrive on it at any time.
- The daemon dispatches the requests of one connection concurrently. Responses
can arrive out of request order. Match them by
id. - Two error replies skip the concurrent dispatch. The daemon writes them on its read path, before it reads the next line. The reference does the same (measured on Linux).
- The parse error (
-32700) covers any line that does not decode into a request. A partial object, a line of only spaces,[1],123,"x"and a batch array all get it. The frame is{"jsonrpc":"2.0","id":null,"error":{"code":-32700,"message":"Parse error"}}. - The auth error (
-32001) covers a request with a missing or wrongauth. The linesnull,{}and{"jsonrpc":"2.0"}get it too. The frame echoes the requestid, re-encoded as in Message shapes. Anullor missingidgives"id":null. - The client can half-close its write side right after the line. These two frames still reach the wire before the close, with or without a final newline. A reply from the concurrent dispatch races the close.
- A request whose handler blocks does not delay a later auth error on the same connection.
- The daemon logs the parse error or the refusal (texts) before it writes the error reply, as the reference does (measured on Linux). When the reply write fails, the failure line comes after the parse-error line (measured on Linux). In a Go type-mismatch error, the type name differs from the reference (measured on Linux).
- A failed write of either reply closes the connection. Any other keeps it
(build
c8e2f083, measured on Linux). - At a client EOF the daemon logs
[Server] Connection closed: <addr>, then closes the socket (measured on Linux). Claustrum logs it only for a marked connection (claustrum's own, not measured). - On Windows, when the client half-closes, the daemon does not wait for a request in flight. The reply to that request is lost, and a partial last line does not change that (measured on Windows).
- Input that ends without a final newline. The daemon reads the last bytes
before EOF as one more line, and the rules above apply. A tail of only
\ris a blank line and gets no reply. - If an earlier valid line came first, the reply to it races the close. The client gets the parse-error frame for the tail (measured on Windows), and it cannot count on the earlier reply.
- On Windows this case has a timing difference, not parity. The reference sends the earlier reply in each measured run and closes later than claustrum. claustrum sends that reply in some runs only.
- At the idle close, the daemon also reads the last bytes as a line. It dispatches a valid request. It writes the error for a bad tail on the read path, but the connection is already closed, so the wire carries no bytes.
- On Windows either end of an
AF_UNIXconnection can miss the close of the other end. A reader gets the bytes before the EOF and then blocks. A new read returns the EOF. A-bridgeof claustrum or of the reference can hang in this way.
Named-pipe transport (Windows, opt-in)¶
This is claustrum's own extension, off by default (CT-5).
With -serve -listen-pipe, or listen-pipe = true in claustrum.conf, the daemon
also serves the same JSON-RPC dispatch over a Windows named pipe, beside the
socket. The framing, the field order and the "auth" member are the same.
- Windows-only. Other platforms ignore the flag and log a warning.
- Name and discovery. The name is
\\.\pipe\claustrum-<random-instance-id>, new at each start. The daemon writes it atomically torpc.pipein the socket's directory, before the pipe accepts and before the ready banner. A client reads the name from that file and does not build it. - Stale-file rule. At start the daemon removes or replaces any
rpc.pipethere, on every OS. At a graceful shutdown, if the file is still the one that it wrote (by identity, as fordaemon.token), the daemon removes it. Any other file stays. So after a graceful shutdown or a new start no stalerpc.pipestays, except a file whose identity the daemon could not record, and a successor keeps its own file. After a crash the file stays until the next start, and a dial of its name fails. - Owner-only and local. The pipe has an owner-only DACL, the analogue of the
socket's
0600on Linux and macOS, and it refuses remote clients. See SECURITY.md.
Authentication¶
Every request carries a top-level "auth":"<token>". Every method but
server.shutdown rejects a request with a missing or wrong token with
-32001 Unauthorized: invalid or missing auth token. It also logs an
Unauthorized line.
server.shutdown is not authenticated, as on the reference. A shutdown frame that
the daemon reads stops it, with any auth member or none. -stop sends no auth
member. Desktop stops the daemon with server --stop --socket <sock> from a bare
SSH command, with no CLAUDE_RPC_TOKEN in its environment
(driver claim). The
exemption covers auth only (Validation precedence).
The server's expected token comes from -token-file or from -token-fd
(token source). With -token-file the daemon
reads the file once at startup and then unlinks it.
No claustrum mode reads CLAUDE_RPC_TOKEN: not -serve, not -bridge and not
-stop. -bridge is a relay and adds no auth. The client that speaks through it
sends "auth" itself, from the daemon.token handshake or
from its launcher. claustrum unsets the variable before it daemonizes, and it strips the
variable from every spawned child. So a token never reaches a child through the
environment.
Message shapes¶
// request
{"jsonrpc":"2.0","id":<n>,"method":"<ns>.<method>","params":{…},"auth":"<token>"}
// success
{"jsonrpc":"2.0","id":<n>,"result":{…}}
// error
{"jsonrpc":"2.0","id":<n>,"error":{"code":<c>,"message":"…"}}
// id-less stream notification (server -> client)
{"type":"stream","processId":"<id>","stream":"stdout|stderr|exit","seq":<n>,"data":"<base64>","exitCode":<n>,"signal":"<SIG>","killedBy":"<who>"}
The reply's id is the request's id decoded and re-encoded. It is not the bytes
the client sent. The daemon accepts any JSON value and returns it canonicalized. A
number round-trips through a float64
(1.0 → 1, 1e2 → 100, 12345678901234567890 → 12345678901234567000). An
object comes back with its keys sorted ({"b":1,"a":2} → {"a":2,"b":1}).
Integers, strings, arrays and null are unchanged. A client that matches replies
by the id text must compare the decoded value instead.
Results are ordered structs, never maps. The field order on each method page, and under Stream notifications, is the wire contract.
Error codes¶
| code | meaning | send again |
|---|---|---|
-32700 |
parse error, a malformed JSON line (response id is null) |
no |
-32600 |
Invalid JSON-RPC version, meaning jsonrpc is absent or not "2.0" |
no |
-32601 |
Invalid method format: <m> (method has no .), Unknown namespace: <ns> (well-formed but unknown namespace), or Unknown method: <ns>.<m> (known namespace, unknown method) |
no |
-32602 |
invalid params (see per-method messages) | no for a fault in the request. A process or files.read refusal can pass after that state changes |
-32603 |
internal error, for example open <path>: no such file or directory. A recovered handler panic also gives this code, with recovered panic: <v> |
depends on the text, see error texts |
-32002 |
a full stdin queue, from process.stdin (see Errors) |
later, while the child reads its input |
-32003 |
an offset past the applied bytes, from process.stdin (see Errors) |
yes, from applied |
-32004 |
a refused launcher, from process.spawn (see The managed launcher) |
after its reason changes, never on Windows, or on macOS with a launcherCheck |
-32005 |
a launcher that does not start, from process.spawn (see Errors) |
depends on the reason |
-32006 |
Refused: this server could not confirm that the caller is in its own namespaces, on Linux with CLAUDE_SSH_PEER_CHECK=1 (see A refused caller) |
no, the connection closes |
-32008 |
a gitRead spawn in a repository in the git state fallback-git, from process.spawn (see The state fallback-git) |
after the git state changes |
-32010 |
a bad host settings file, from process.spawn on Linux (see host_settings) |
after a fix and a new start |
-32001 |
Unauthorized: invalid or missing auth token |
not with the same token |
The column send again is claustrum's own advice, read from its code.
Handler panic recovery¶
The per-request goroutine recovers a panic in any handler, so the daemon does not
crash. The reply is {"error":{"code":-32603,"message":"recovered panic: <v>"}},
and the daemon logs [Server] recovered panic: method=<m> id=<id>: <v>. A
recovered panic in server.shutdown writes no frame at all. Its only reply is
{"ok":true} (see server.shutdown).
The frame and the log line are claustrum's own, not a compatibility guarantee. No input is known to reach a handler panic.
Validation precedence¶
The daemon tests a request in the order parse, auth, version, method, params. So a
request with no auth and a missing or wrong jsonrpc gets -32001 Unauthorized,
not the version error. server.shutdown skips the auth test only. A shutdown frame
with a missing or wrong jsonrpc gets -32600 Invalid JSON-RPC version, and the
daemon stays up.
Params presence and typing¶
Every files.* / git.* / process.* method requires a params object.
server.* methods take no params. The daemon ignores a mistyped params on a
server.* method, and the call succeeds.
- Absent
paramsgives-32602 Invalid params. The daemon tests this after method existence, so an unknown method is-32601in every case. - The daemon accepts an empty
{}and then runs the method's own validation. - Mistyped
paramsgives-32602 Invalid params. This covers a wrong type in a member that the method reads ("maxBytes":"4","path":123) and a non-object value ("params":"x"or[…]). The daemon does not coerce the value, and it does not ignore the decode error. - The daemon ignores a member that another method of the namespace reads,
whatever its type.
So
files.stat {"maxBytes":"{"}answers asfiles.statwith nomaxBytes. The reference does the same on Linux, macOS and Windows.
Path handling¶
A path must be valid UTF-8 to be addressable at all¶
Before any expansion or method logic, the JSON decoder replaces bytes that are not
valid UTF-8 with U+FFFD. A file whose name contains such bytes therefore cannot
be named in any request. The daemon answers about a path that does not exist. It
returns exists:false, or a chdir or stat error that quotes the substituted
name. This is parity, not a divergence. Both daemons inherit it from the JSON
decoder. See
ARCHITECTURE.md → Inherited wire bytes.
Tilde expansion in path params¶
claustrum expands a leading tilde in every path-bearing param before the method
runs: files.* path, extract_tar's archivePath / destDir, git.* path /
baseRepo / worktreePath, and process.spawn's cwd. Branch names are refs,
not paths, so claustrum never expands them. Nor does it expand the parent of
files.mkdir. claustrum replaces a leading ~ with
the daemon user's home directory, and then cleans the remainder lexically. Bare
~ is the exception. It returns home verbatim, uncleaned.
| sent | reference replies | absolute-form control |
|---|---|---|
~ |
<home>, verbatim, not cleaned |
n/a |
~/ |
<home> (trailing separator stripped) |
unchanged |
~/f.txt |
<home>/f.txt |
unchanged |
~//f.txt |
<home>/f.txt (doubled separator collapsed) |
<home>//f.txt |
~/a/./b |
<home>/a/b (. resolved) |
<home>/a/./b |
~/a/x/../b |
<home>/a/b (.. resolved lexically) |
<home>/a/x/../b |
~user/f, /tmp/~/f, $HOME/f |
unchanged, not expanded | n/a |
Two consequences:
- Bare
~is the exception. AHOMEof/home/me/echoes back with its trailing slash.~/under the sameHOMEdoes not. - The cleaning is lexical, and it applies to the tilde form only. With
~/link -> b/c, the reference reads<home>/x.txtfor~/link/../x.txt. The absolute spelling walks the symlink and reads<home>/b/x.txt. Same request, different file.
Windows behaves the same way in Windows separator terms. Home comes from
USERPROFILE there, not from HOME.
| sent | reference replies |
|---|---|
~\a7 |
~\a7, not expanded, because ~\ is not a tilde form |
~/a1 |
<home>\a1, with / rewritten to \ |
~/a4\x\..\w |
<home>\a4\w, because \ is a separator for .. |
~/a5/ |
<home>\a5 |
~//a6 |
<home>\a6 |
~ |
<home> verbatim. A home of C:\h\ keeps its trailing \ |
The expanded spelling is wire-visible on eight frames, so it is contract.
git.worktree_create reflects worktreePath into result.path and into git's
error text. The expanded string also appears in the error text of files.stat,
files.read, files.list, files.validate, files.extract_tar and
process.spawn. Two places do not carry the spelling. files.list entry paths
are re-joined, and git.info's root comes from the walk with links resolved, and on Windows from git's confirmation of it. On a
trailing-separator spelling the difference is a change of verdict. POSIX
stat("f.txt/") gives ENOTDIR. Once the daemon removes the separator, a
-32603 error frame becomes a success frame. Ids 15, 16, 18 and 19 of
testdata/socket_tilde_expansion.golden.json pin this. Id 17 sends ~// to
files.list and is documentary only.
Stat failures other than "does not exist"¶
files.stat, files.read and files.validate distinguish a path that is absent
from a path the daemon cannot examine. files.read opens the path where the
other two stat it:
- A genuine
ENOENTis the "does not exist" answer in each method's own shape. The three shapes areexists:false,content:"" exists:false, andvalid:falsewitherror:"Path does not exist". - The daemon reports any other failure with the underlying message.
files.statreturns-32603 stat <path>: <reason>.files.readreturns-32603 open <path>: <reason>.files.validatekeeps its result shape and puts that text in itserrorfield instead. Reachable reasons includenot a directory(a path component is a regular file),file name too long, andinvalid argument(a NUL byte in the path). Forfiles.read,5fd08069gives these three withopenon Linux and macOS.
Methods (24)¶
server.capabilities lists the methods in the order of this table. The
reference build history records the builds that added or
removed a method.
| Method | Params → result | Page |
|---|---|---|
server.ping |
none → {"pong":true} |
server.* |
server.capabilities |
none → {"version","methods":[…24…],"instanceId","startedAt","features":[…],"peerCheck"[,"peerCheckBy"][,"unattendedLimitMinutes"][,"endedInstances"]} |
server.* |
server.shutdown |
none → {"ok":true}, when the reply wins the race with the close |
server.* |
server.adoptEnv |
{env[,noLoginShell][,kept]} → {"ok":true} |
server.adoptEnv |
files.list |
{path[,includeDotNames,junctionsAsDirs]} → {"entries":[{"name","path","isDir"},…]} (name-sorted) |
files.list |
files.validate |
{path} → {"valid":bool,"isDir":bool[,"error"]} |
files.validate |
files.stat |
{path} → {"exists","isDir","size","mode":"-rw-r--r--"} |
files.stat |
files.read |
{path[,maxBytes][,real]} → {"content":"<raw text>","exists":true[,"real":"<path>"]} |
files.read |
files.extract_tar |
{archivePath,destDir} → {"success":true,"fileCount":<n>} |
files.extract_tar |
git.info |
{path[,shadowDirOff]} → repo: {"isRepo":true,"repo":"<dir>","branch":"<b>","root":"<abs>","repoSlug":"<owner/repo>","defaultBranch":"<b>"[,"settingsControl":"<state>"]} · non-repo: {"isRepo":false,"repoSlug":"","defaultBranch":""[,"settingsControl":"<state>"]} |
git.info |
git.status |
{path,baseRepo[,shadowDirOff]} → clean: {"isRepo":true,"clean":true} · dirty: {…,"clean":false,"changes":["M a.txt"," M b.txt","?? new"]} |
git.status |
git.list_branches |
{path[,shadowDirOff]} → {"isRepo":true,"branches":[…sorted…]} |
git.list_branches |
git.worktree_create |
{baseRepo,branchName,worktreePath[,sourceBranch][,existingBranch][,worktreeRoot][,timeoutMs][,shadowDirOff]} → {"success":true,"path":"<worktreePath>","sourceBranch":"<b>","branch":"<b>"} |
git.worktree_create |
git.worktree_remove |
{baseRepo,worktreePath[,branchName][,worktreeRoot][,shadowDirOff]} → {"success":true}, or {"success":true,"branchKept":true} when the branch step keeps the branch |
git.worktree_remove |
launcher.resolve |
{cliPath[,path,launcherCheck]} → one of four shapes, or with path and launcherCheck {"status":"usable","argv":["<path>"],"hostPolicySeen":<bool>[,"checked"]} · {"status":"unusable","reason","fault","hostPolicySeen"[,"checked"]} |
launcher.resolve |
process.spawn |
{id,command[,args][,cwd][,env][,disableShellAgentSocket][,launcher][,wantPid]} → {"success":true}, then stream frames |
process.spawn |
process.stdin |
{id,data[,offset]} → {"success":true,"applied":<int>[,"duplicate":true]} |
process.stdin |
process.kill |
{id[,signal][,farewell,graceMs]} → {"success":true[,"farewellEnd":<end>]} |
process.kill |
process.killAndWait |
{id[,signal][,timeoutMs][,escalate][,farewell,graceMs]} → {"found":<bool>,"died":<bool>[,"alreadyExited":true][,"escalated":true][,"farewellEnd":<end>]} |
process.killAndWait |
process.reattach |
{id,fromSeq[,wantPid]} → {"found","running","firstSeq","lastSeq","stdinApplied"} |
process.reattach |
plugins.prune |
{[keep],[minAgeDays]} → {"root":"<per-install root>","pruned":[…],"prunedLegacy":[…],"staleArchives":0,"kept":0,"live":<n>,"young":<n>,"legacy":"<state>","minAgeDays":<clamped>} |
plugins.prune |
files.find |
{roots,suffix[,limit][,timeoutMs]} → {"paths":[…],"whole":<bool>[,"cut":"<word>"],"passedOver":[…],"links":[{"path","leadsTo"},…]}, Linux and macOS only (4c111e86) |
files.find |
files.mkdir |
{parent,name} → {"code":"<code>"[,"errno":<n>]}, Linux and macOS only (c9125eb8) |
files.mkdir |
files.realpath |
{path[,missingLeaf]} → {"exists":<bool>[,"real"][,"wouldBe"][,"dangling":true]} |
files.realpath |
Shared rules of the git methods¶
Shared git.* rules are on six pages: trust check, Windows paths, config refusals, settings copy, hardened calls and session folders.