Skip to main content
Gas City’s exec session provider delegates each runtime.Provider operation to a user-supplied script. This allows any terminal multiplexer or process manager to be used as a session backend without writing Go code.

Usage

Set the GC_SESSION environment variable to exec:<script>:
Prefer an absolute path. A PATH lookup resolves in each gc process’s own environment, so the supervisor, gc start and a cron job can run different files under one name, and reconciler v2’s admission (see observe.v1) reads the handshake of the file the deciding process resolves.

Pack-Declared Runtimes

A pack can ship (or install) a runtime executable and bind it to a selection name in pack.toml:
City composition registers the name into the runtime selection registry, so city.toml selects it like a builtin:
Rules:
  • A command containing a path separator resolves relative to the pack directory; a bare name resolves on PATH at session start.
  • protocol declares the RPP version the executable speaks (version 0 is the only version today); any other value fails composition.
  • Name collisions with builtin runtimes or other packs are composition errors — no silent shadowing. Identical re-declarations of the same pack reached through a diamond import graph dedupe.
  • The pack-runtimes doctor check verifies each declared executable is installed and that its RPP handshake works. An executable with no protocol op is the version-0 floor and passes; a present-but-broken handshake fails.
  • Config reload enforces the same registration rules, and rebuilds the session provider when the declaration behind the selected name changes (the executable binding is fixed at provider construction).
  • gc runtime check <name> and gc runtime conformance <name> both resolve the declared name and run against the pack’s executable: check is the smoke test, conformance the full requirement-coded suite.

Calling Convention

The script receives the operation name as its first argument:
No shell invocation — the script is exec’d directly.

Exit Codes

Exit code 2 is the forward-compatibility mechanism. When Gas City adds new operations in the future, old scripts return exit 2 and the provider treats it as a no-op success. Scripts only need to implement the operations they care about. An operation a script declares in its handshake cannot be unknown, so declared operations do not read exit 2 as success: under proc.exec, exec returns it as the command’s own exit code, and under proc.provision, report-attachment and server-lifecycle, provision, is-attached and server-stop report it as a failure. start cannot be unknown either, so its exit 2 (for example a helper’s grep or jq exit status escaping a set -e script) is a failed start. Under carrier.ops, the five driving operations (nudge, peek, send-keys, interrupt and clear-scrollback) cannot be unknown either: gc has no other way to drive the script’s sessions, so their exit 2 is a failure.

Cancellation

Each invocation runs in its own process group. When an operation is canceled (its timeout expires, or Gas City abandons the call), the script is stopped in two steps: A canceled call is reported as canceled whatever the script’s exit code, so a TERM handler may exit with any status, including 2. Trap TERM (or EXIT, which bash also runs when TERM ends the script) to clean up. SIGINT is not sent: a script that traps only INT gets no chance to roll back. Keep the rollback inside the grace period; prefer one bounded step (for example docker rm -f <id>) over a graceful stop that waits out its own timeout.
Each call has a deadline. start and provision get 120 seconds, attach none (it holds your terminal), and watch-startup runs only while gc clears startup dialogs. Every other operation gets 30 seconds, and a caller can cancel a call sooner. Two operations are stopped differently from the steps above: a canceled exec or watch-startup call is killed outright, with SIGKILL to the script process and no SIGTERM first.

Operations

Box without agent (the un-weld). provision is start MINUS the agent launch: it creates/prepares the box (PreStart, SessionSetup, SessionSetupScript, SessionLive — every box step start runs EXCEPT spawning the agent in tmux) and returns. The orchestrator then launches the agent itself by exec-ing tmux new-session / respawn-pane -k over the exec op, so a launch-only config change relaunches the agent in the warm box instead of reprovisioning (B2.3). A pack using the default tmux carrier opts in by declaring proc.provision and proc.exec. Without both, or with carrier.ops, the welded start op provisions and launches, and the orchestrator issues no provision or separate launch. The op is gated by the RPP-PROVISION-001 conformance requirement. The connection primitive (slim RPP). exec is the connection op (RPP-CONN-001). It is optional; conformance checks output and command exit codes when implemented. Runtimes declaring env.* capabilities need it. Without a carrier declaration, gc tries tmux over exec first, even without proc.exec. Dedicated-op fallback happens only when exec exits 2 and proc.exec is undeclared. Declared proc.exec makes exit 2 the command’s own exit code, never a fallback signal. Declare carrier.ops to select the existing nudge, peek, send-keys, interrupt and clear-scrollback ops directly, without tmux. All five are required for this carrier, so an exit 2 from one fails like any other non-zero exit: a nudge the script never delivered is not reported delivered, and a missing peek is not read as an empty screen. gc runtime check exercises all five and fails unsupported or broken ops. gc runtime conformance checks only the peek read under idle-boundary, not the other four driving ops. With idle-boundary, both checkers also require the ready-prompt store. watch-startup stays a dedicated streaming op for either carrier.

Protocol Handshake (protocol)

The protocol operation declares which Runtime Provider Protocol version the script speaks and which optional capabilities it implements:
locality is optional: "local" says the script’s boxes run on gc’s own host. Absent, or any other value, reads as remote. A container on gc’s host is local too; that its boxes also share gc’s filesystem and user is what fs.host adds (see Host filesystem (fs.host)). Scripts that do not implement protocol (exit 2) are treated as version 0 with no optional capabilities — every pre-handshake script remains valid. Unknown capability strings are ignored, so scripts may declare capabilities for newer Gas City versions without breaking older ones. Malformed handshake JSON is an error: capability probes fall back to the no-capability behavior and the failure is reported by conformance and doctor checks. Capabilities: A successful handshake is cached for the provider’s life. A failed one is cached for 30 seconds, then retried, so a transient failure does not leave the script on the no-capability floor until gc restarts. Before the first successful handshake, gc retains tmux-first behavior. A non-tmux pack with a broken handshake can therefore receive tmux text through a generic exec until a retry selects carrier.ops. Both checkers report the broken handshake. A first driving call can read protocol before exec, even if the provider has not started a session.

Idle sleep

An idle sandbox still costs money and capacity. With a [session_sleep] policy (or an agent’s sleep_after_idle), the orchestrator stops a session that has been idle long enough and starts it again when work, a nudge, or an attach arrives. Which sessions a script-backed runtime can put to sleep depends on its handshake: full needs a safe idle boundary, so an interactive session is never stopped in the middle of a turn. A runtime with a full idle boundary must:
  • Show the agent’s screen. The default carrier reads tmux session main over exec with tmux capture-pane -t main -p -S -120. carrier.ops reads peek <name> 120 under the wait’s context. It treats the session as idle after two consecutive captures, 200 ms apart, that show the agent’s ready prompt (ready_prompt_prefix, default ❯ ) and no busy indicator such as esc to interrupt. This is the same check a local tmux session gets.
  • Answer is-attached honestly. Print false and exit 0 for a session that does not exist. Exit non-zero only when you cannot tell; any non-zero exit, 2 included, keeps the session awake.
  • Treat stop as the sleep. Sleeping a session calls stop, and waking it calls start. Anything the runtime keeps only inside the box, such as the agent’s conversation, is lost across a sleep unless stop preserves it.
Each capture is a full round trip to the box, so the orchestrator gives one idle check 5 s, not the 1 s a local tmux session gets. Two captures and the pause between them fit in 5 s when each capture finishes in under 2.4 s. A check in a process that has not yet remembered the session’s ready prompt (see below) first reads it from the box within the same 5 s, so that check needs three round trips, each under 1.6 s. Every check needs the read while GC_READY_PROMPT_PREFIX is absent from the session. Treat 2.4 s and 1.6 s as limits, not targets: a capture that ends exactly at the 5 s mark does not count. A slower check fails closed: the session stays awake, and the check runs again on the next orchestrator tick. For carrier.ops, after start the orchestrator publishes the effective prompt using set-meta <name> GC_READY_PROMPT_PREFIX with the prefix on stdin. Another provider instance recovers it with get-meta under the wait’s deadline. A missing key or failed read uses the default without caching, so the next wait retries. Publication is best effort and retried only on the next start; a failed set-meta is reported on the orchestrator’s stderr. Pack metadata may outlive stop. If a new start’s set-meta fails, another provider instance can recover the previous incarnation’s prompt. Packs should drop session metadata on stop to prevent stale prompt recovery. Trailing newlines and a trailing carriage return are trimmed from metadata, so prefixes ending in either cannot be recovered. A carrier.ops script that declares idle-boundary must therefore implement set-meta and get-meta, and get-meta must answer the stored prompt byte for byte, non-ASCII characters and a trailing space included (gc trims only the trailing newlines and carriage returns above). Without them, every gc process that did not start the session, such as a restarted orchestrator or a gc command, looks for the default prompt, so a session whose agent shows another prompt never reads as idle there, although the runtime reports full. gc runtime check (capability carrier.ops: ready-prompt metadata) and gc runtime conformance (RPP-CONN-002) store a non-default prompt and fail a script whose store does not return it. An unimplemented set-meta (exit 2) on a script that is not v2-ready reads as success at the orchestrator, like any unknown operation, so only the checkers catch it. For the default carrier, once the agent’s tmux session exists, the orchestrator stores the session’s ready_prompt_prefix in that session’s environment as GC_READY_PROMPT_PREFIX (tmux -u set-environment -t main; a blank prefix stores the default prompt, ❯ ), as local tmux sessions do. A process that did not start the session, such as a restarted orchestrator or a gc command that cannot reach the API, reads it back with tmux -u show-environment -t main and then remembers it. Like local tmux, gc passes -u to these commands, so the prompt survives an exec environment without a UTF-8 locale. Do not clear the main session’s environment. While the read fails or the variable is absent, that process looks for the default prompt and reads again on its next wait. The variable is absent when storing it failed (gc does not retry; the next start stores it again) and for a session started by an older gc. A session whose agent shows another prompt then never reads as idle. It stays awake, and every wait for its idle boundary runs to its timeout: interrupting it (interrupt_now) can restart the session, and stopping a turn reports an error. A script written before idle-boundary existed, which declares only the first three, gets timed_only until it adds idle-boundary: its interactive sessions stop sleeping, and gc stops waiting for its idle boundary. A wait-idle nudge is queued instead of delivered at the boundary, and interrupt_now and stopping a turn get no idle wait. Non-interactive sleep, attachment and exec are unchanged. gc no longer reads the first three as proof that the box runs tmux, because a runtime without tmux declares them too. gc runtime check warns about a script in this state. The is-attached rule above applies to every runtime that declares report-attachment, even without the other capabilities. gc runs the op directly and treats any non-zero exit, including 2, as “attached”: the session stays awake and destructive actions on it are held.

Fenced input over exec

A carrier.ops runtime takes no fenced input, even if it declares proc.exec and input-fence. Fenced nudges, keys, interrupts and dialog dismissal refuse before sending any op. Unfenced input is unaffected. A runtime using the default carrier that declares both proc.exec and input-fence takes fenced input: gc sends a nudge, keys or an interrupt only to the agent incarnation it is meant for. The fence is the pane option @gc_fence on the agent pane of the in-box tmux session main, and gc manages it over exec. Declare input-fence only for a runtime that:
  • Runs tmux 3.0 or later in the box. gc sets and clears the fence with set-option -p (pane options), which older tmux rejects. With older tmux every start fails and the box is torn down, and a separable launch fails as a whole, because gc appends the fence command to the launch’s own tmux command list.
  • Has the main session when start returns. gc publishes the fence right after start. A publish that fails fails the start and tears the box down, unless the box was running before the attempt.
  • Provides sh in the box. gc reads the fence, sends guarded input and loads nudge text into a tmux buffer through short sh -c scripts.
A runtime that declares proc.exec without input-fence starts and takes unfenced input as usual: gc touches no fence in its box, and refuses only a fenced request to it. Before a start of a box that may already be running, gc reads and clears the pane’s fence, so a start that reuses the pane never leaves the previous incarnation’s fence on it. When start, or the fence publish after it, then fails and the box stays up (it reports that the session already exists, or is-running said it was running before the attempt), gc puts the fence back on the same pane, as long as the pane’s root process is unchanged and no other fence has been set since. Fenced input sends nothing until tmux in the box answers the fence read. A live tmux server without the main session or its agent pane answers that the session is absent. A command the box does not answer, because the exec op fails (its own non-zero exit) or tmux in the box fails (no server, a missing tmux, a socket it cannot reach), is an outage (ErrRuntimeUnavailable), unless is-running then answers false, which makes it an absent session. Either way, a failure after part of the input went in (nudge text without its Enter) reports the input as partly delivered. An exec op that is canceled or cannot be run at all is an outage too, without asking is-running, and it does not say whether part of the input went in before it stopped. A pane started before gc published fences takes no fenced input until its agent is relaunched.

Server teardown (server-lifecycle)

A script whose boxes run under a server of its own (a terminal multiplexer, a daemon its start brings up) declares server-lifecycle so that server does not outlive the city. gc then runs script server-stop after it stops the city’s sessions: server-stop is a backstop as well as a teardown: a session gc’s own stops could not see ends with the server. Stderr on exit 0 is never shown, so do not exit 0 with a warning there. Exit 2 is a failure, because the script declared the op. gc reads the token from the handshake: if the handshake fails at teardown, gc runs it once more, and if that fails too it runs no server-stop and prints a teardown warning, since the server may survive. gc does not configure the server at startup: the script brings it up when an op first needs it. If other cities or users share the server, end only the sessions the script started for this city (GC_EXEC_CITY_PATH) and leave the server running while anything else uses it. gc runtime conformance checks the op as the server group (RPP-SERVER-001 to RPP-SERVER-004; RPP-SERVER-004, that server-stop in one city leaves another city’s sessions running, only for a script that also declares city-scoped). gc runtime check runs it twice, the second time to check that it is idempotent. Both commands run the op, and the sessions they check it against, in a private city: GC_EXEC_CITY_NAME and GC_EXEC_CITY_PATH name a fresh temporary directory, never the city you run them from. A script that does not scope its server by GC_EXEC_CITY_PATH ends every session the server holds, so check it only against a backend that no live city uses.

Start Config (JSON on stdin)

The start and provision operations receive a JSON object on stdin:
Every field is optional and omitted when empty. The complete set: On a fresh start the agent’s startup prompt is not in the start config: gc renders it as a command-line argument (prompt_mode = "arg", the default) or flag ("flag"), and the exec provider passes neither to the script, so the agent starts without it. gc puts the prompt at the front of nudge instead in three cases: with prompt_mode = "none", on a start that resumes an existing conversation (any prompt mode), and for a prompt too large for a command line on a runtime whose [runtimes.<name>] entry sets prompt_delivery = "nudge-fallback". A script should handle any non-empty nudge.

Session environment

env is what gc wants set in the session, to apply over the box’s own environment. For a configured agent’s session it holds:
  • PATH, HOME, USER, LOGNAME, TZ, the locale and XDG directory variables, and a few Claude Code and telemetry settings, from gc’s own environment.
  • Every non-empty GC_* variable in gc’s environment except GC_CONTROLLER_TOKEN, and any variable named in GC_SUPERVISOR_ENV.
  • Provider credentials from gc’s environment: every variable whose name starts with a provider prefix such as ANTHROPIC_, OPENAI_, GEMINI_, GOOGLE_, AZURE_ or XAI_, and a fixed list of AWS variables (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN, AWS_REGION, AWS_PROFILE and others), not every AWS_* variable.
  • The city’s [workspace] env, then the provider’s, then the agent’s, then the session’s own variables (GC_AGENT, GC_ALIAS, GC_CITY, GC_DIR, GC_SESSION_ID and more), and last the agent’s selected upstream’s variables and a few gc-owned settings, the empty GC_CONTROLLER_TOKEN among them.
An empty value means the variable must be unset. gc sends some keys empty on purpose, GC_CONTROLLER_TOKEN among them, so that a value inherited from its own environment does not reach the agent. The script itself runs with gc’s environment, so a script that starts the agent as its own child must apply those empty values too. Provider credentials in the supervisor’s environment therefore reach every session. GC_SUPERVISOR_OMIT_PROVIDER_CREDS=1 does not change that: it only keeps them out of the launchd plist or systemd unit that gc generates, and out of a gc supervisor run that gc forks. The bundled contrib/session-scripts/gc-session-k8s copies env into the pod spec as literal env values (it drops or rewrites a few GC_* keys), and Kubernetes gives a literal env entry precedence over the same key from envFrom, so a credential in the supervisor’s environment overrides one you supply through envFrom.

Startup Hints

The JSON config contains fields that the tmux provider uses for multi-step startup orchestration. The exec provider does not fire start and forget it. gc first runs is-running to learn whether a box already holds the name, then runs start and waits for it to exit. After a successful start it can run more operations before it counts the session started: it publishes the input fence and the ready prompt for a runtime that declares the capabilities they need, and when the start config lists process_names or the provider declares a bypass-permissions dialog (a provider’s accept_startup_dialogs setting overrides both) it dismisses known startup dialogs, such as workspace trust, through watch-startup, peek and send-keys. These use the selected carrier. Without carrier.ops, gc tries tmux over exec, with dedicated-op fallback only on ErrExecUnsupported. If start fails or times out, or a step after it fails, gc runs stop <name> to tear down whatever the attempt created, then reports the start as failed. It skips that stop when the box belongs to a live session: when is-running printed true before the attempt, or when start exited non-zero on its own with stderr saying the name is taken (it contains already exists or already running). The stderr check does not apply to a start that gc canceled at its deadline. A runtime that declares both proc.provision and proc.exec, without carrier.ops, gets provision in place of that start: no stop follows a failed provision, and one always follows a failed agent launch after it. It gets that is-running (observe on a v2-ready script) only when it also declares fs.host, because gc needs the answer before it does any host work. Scripts may handle these hints or ignore them:
  • process_names — the tmux adapter polls for these process names to appear in the session’s process tree (30s timeout) before considering the agent “started.” A script can implement this by polling its backend’s process tree after session creation, or ignore it for fire-and-forget behavior (like the subprocess provider does).
  • lifecycle — "one_shot" marks a short-lived command that is expected to exit after handling its prompt. Providers should not require a persistent post-start process for one-shot starts.
  • nudge — text that the tmux adapter types into the session after the agent is ready. gc does not send it through the nudge operation when start returns, so a script that wants the agent to receive it types it in itself, in start, once the agent is ready. Later nudges, such as gc session nudge, use the selected carrier. Under carrier.ops that is the nudge operation. Otherwise gc types them through tmux over exec, and uses the nudge operation when the runtime does not implement exec.
  • pre_start — array of shell commands to run on the target filesystem before the session is created. Used for directory preparation, worktree creation, or other setup that must exist before the agent starts. Scripts should execute each command in the target environment before creating the tmux session. Fatal: if a command fails, fail start (exit 1) without creating the session. An agent must never launch into an unprepared work dir, and gc delivers skills and MCP for worktree agents as a pre_start command.
  • session_setup — array of shell commands to run on the target filesystem after the session is created and ready, before returning. Scripts should execute each command inside the session environment (e.g. kubectl exec -- sh -c '<cmd>' for K8s, docker exec -- sh -c '<cmd>' for Docker, or plain sh -c '<cmd>' for local providers). Non-fatal: warn on stderr if a command fails, but don’t abort start.
  • session_setup_script — path to a script on the orchestrator filesystem, run after session_setup commands. For remote providers (K8s, Docker), read the file locally and pipe its contents into the session (e.g. kubectl exec -i -- sh < script). For local providers, run directly via sh -c. Non-fatal like session_setup.
Fields that are not included in the JSON (gc-internal, not part of the exec protocol):
  • emits_permission_warning — bypass-permissions dialog handling
  • fingerprint_extra — config change detection metadata
ready_prompt_prefix and ready_delay_ms are sent, but gc does not wait for the agent to show the prompt, or wait out the delay, before it counts the start done. A script that must reach a ready agent before it returns (to type nudge, say) waits itself; otherwise it may ignore them. Session setup commands are the script’s responsibility — they run on the target filesystem, not the orchestrator — unless the script declares fs.host, in which case gc runs them on the host and leaves them out of the start config of a start into a vacant name (see Host filesystem (fs.host)).

Host filesystem (fs.host)

A script whose handshake declares fs.host together with "locality": "local" promises that its boxes run on gc’s host, as gc’s user, with gc’s view of the filesystem. locality alone does not promise that: a container on gc’s host is local but sees its own filesystem and may run as another user, and it must not declare fs.host. gc reads the two together; fs.host without "locality": "local" is ignored. For such a script gc does the session’s host work itself, around start (or provision):
  1. It stages the work dir: pack_overlay_dirs (including the per-provider/<provider>/ subdirectories that match the session’s provider), overlay_dir and copy_files.
  2. It runs pre_start on the host, each command under the [session] setup_timeout (and setup_max_timeout, when set). A failing command fails the start before start runs; the error carries the command’s output tail with secrets redacted.
  3. It runs start (or provision) with a config that leaves out what it did: pack_overlay_dirs, overlay_dir, copy_files, pre_start, session_setup and session_setup_script are absent.
  4. Once the agent is up, it runs session_setup and then session_setup_script on the host with GC_SESSION set. A failure is a warning; the session keeps running.
gc does this host work only into a name that holds no live box: is-running prints false or, on a v2-ready script, observe reads the name absent or its box dead (a start recycles a dead box, so the work is done again, as after a death under tmux). Into a name a running box holds, or one whose read fails, it does none of it and sends the full config. When gc relaunches the agent in a warm box (a script declaring proc.provision and proc.exec, without carrier.ops), it runs session_setup and session_setup_script on the host again after the launch, as the tmux runtime does. It does not stage the work dir or run pre_start again: the box is warm. Any other script is relaunched by a stop and a start, which do all of the host work again. gc runs no session_live for an exec runtime; the field stays in the start config. Commands there are typically tmux theming and keybindings, written as tmux ${GC_TMUX_SOCKET:+-L "$GC_TMUX_SOCKET"} ... so that they reach the city’s tmux server. Only gc’s tmux runtime sets GC_TMUX_SOCKET; on gc’s host without it, those commands reach the user’s own default tmux server. So a script declaring fs.host runs session_live only against a tmux server of its own (for example, with GC_TMUX_SOCKET set to that server’s socket name), and otherwise must not run it. The same applies to the session_setup commands gc runs on the host for such a script: gc runs them without GC_TMUX_SOCKET, so keep commands that drive tmux out of an agent’s session_setup when its runtime declares fs.host. There is no flag in the start config that says gc did the work. A script does exactly what its start config carries: a gc that did the host work left those fields out, and an older gc (or one whose cached handshake predates the script declaring fs.host) sends them, and the script does them, as before. The reverse also holds. gc keeps a successful handshake for the provider’s life, so a script edited in place to drop fs.host still gets start configs without those fields until gc restarts, and nothing does that work. Restart gc after removing fs.host from a script it is running. With fs.host, gc also reads the agent’s transcript on its own host for turn tracking, and the runtime passes the skill and MCP materialization gates, so an agent with MCP configured resolves at its scope root and in a worktree. The skill and MCP gates read the handshake through gc’s admission probe, which gc remembers for each version of the script file. The first gate check for a version (or the first after a failed probe’s 30-second retry window) runs protocol, bounded at 10 seconds, and concurrent checks wait for that one probe. A script that is slow to start or hangs in protocol delays that check by up to 10 seconds. A failed or timed-out probe reads as no fs.host until a later probe succeeds. On a v2-ready script with fs.host, gc also scans its host’s process table for a session’s leftover processes, as it does for tmux and subprocess sessions: a process that left the agent’s process group and outlived its terminal, carrying the session’s GC_SESSION_ID and GC_CITY_PATH. The orphan sweep ends such a process once its session is closed, or stopped with no live box under its name, and a session’s start ends its own stopped incarnation’s leftovers first. A leftover counts as live while a box the script’s inventory lists carries its GC_SESSION_ID; for a listed box whose GC_SESSION_ID reads empty, the leftover’s GC_SESSION_NAME decides. gc does not scan for the sessions of a script that is not v2-ready: its list-running cannot prove a box gone (an exit 2, or an empty answer from a backend it could not read, lists nothing), so a live box’s process would read as a leftover. Without fs.host gc does not scan either. The inventory runs only when the scan found such a process. For the orphan sweep it is bounded at 5 seconds, because the sweep scans on every orchestrator tick; for a session’s start it may take as long as a listing call. An inventory that fails, is partial or runs past its bound leaves tracking unknown: the sweep then reaps only the leftovers of closed sessions, and a session’s start refuses rather than end a leftover the inventory could have shown. gc signals a process only while it still carries the session’s GC_SESSION_ID and the start time the scan read. How gc reads a tmux server in a box’s picture depends on where the box’s agent runs: A script whose agent runs under a tmux server in its box declares proc.exec. Without it, gc reads the agent as running outside tmux, and the scan skips the agent. When the agent runs in session main, a session’s start ends a stale incarnation’s agent that its box’s tmux server kept running, and the drain-ack escalation can end a wedged session’s agent, as for the tmux runtime. A tmux session an agent starts on that server is the session’s too, and is ended with its leftovers. When the agent runs outside tmux, a tmux server carrying a GC_SESSION_ID is one an agent or a user started inside a box (tmux new -d, or the user’s default tmux server when none was running): tmux copies the environment of the process that starts its server, so the server and every process in its panes carry the session’s GC_SESSION_ID. The scan skips the server, its clients and every process in its panes, and when the city also runs ACP agents, gc reports only what that scan reports for them too. A session’s start and the drain-ack escalation therefore never end a tmux session running inside such a box, nor any process in its panes. A tmux server that carries no GC_SESSION_ID, such as a multiplexer a script starts for its boxes from the operation’s own environment, changes nothing. gc cannot read the environment of another user’s tmux server, so it skips a process under one and reports a scan error. gc recognizes tmux by its process name: tmux, or a title tmux takes from the name it runs under, so a renamed tmux binary is recognized too, except on macOS, where only tmux is. On Linux that title is <name>: server or <name>: client for a name of up to six characters, and <name>: for a name of 7 to 14 characters, because the kernel keeps 15 bytes of a process name and tmux cuts the rest at its last space; a longer name is not recognized. Any other process whose name takes one of these forms is treated as tmux too. Skipping these processes has costs:
  • A process that leaves such a pane and is adopted by init (or the user’s subreaper) is no longer under tmux, and counts as a leftover like any other. Once a box has founded the user’s default tmux server, anything the user later starts there carries the session’s identity, and can be ended as the session’s leftover once it leaves its pane and is adopted.
  • A tmux session an agent starts with tmux new -d inside a box is never cleaned up by gc. It runs until it exits or someone ends it.
  • In a city that also runs ACP agents, the same rule covers the ACP agents’ processes, since gc cannot tell a tmux server an ACP agent started from one inside a box. A tmux session an ACP agent starts (tmux new -d) is no longer ended when that session restarts, as it is in a city without such a script, and any ACP agent process under it is skipped.
  • The drain-ack escalation ends a wedged session’s processes only when their parent is a tmux server, so it finds nothing to end for such a box’s session: the slot stays occupied until the box exits.
Start a process that serves several boxes, such as a multiplexer or a daemon the boxes run under, from the operation’s own environment, never after applying a start config’s env. A process that carries a session’s GC_SESSION_ID and outlives that session’s box is that session’s leftover: gc ends it with its process group, and every box it serves goes down with it. gc runtime conformance checks the promise in its fshost group: a box’s command copies a file the runner wrote and records its id -u, which the runner reads back on its own host; a start config’s overlay_dir and pre_start are carried out, a failing pre_start fails start with no box, and a config that carries neither stages and runs nothing; with observe.v1, observe’s agent_pid is a live host process of the caller’s user; and a box’s command reads a file the runner wrote under its HOME, so a box that shares only the work dir (a container bind-mounting /tmp, say) fails. gc runtime check warns when a handshake declares fs.host without "locality": "local".

Work-dir export exclusions

  • work_dir_exclude — array of patterns, relative to work_dir, naming orchestrator-local state that must not leave the orchestrator host. gc sends it with every start config that has a work_dir, whatever the directory holds: a work dir with no top-level .gc/ or .beads/ can still hold rig scopes below it. A script that copies, archives, or syncs work_dir into another filesystem (a remote sandbox, a container image) must skip every matching path. A script that runs the agent in place on the orchestrator’s filesystem ignores it.
The list is a floor, not the complete set. A script must skip every matching path and may skip more. A script that carries its own built-in denylist applies the union of that list and work_dir_exclude; it never replaces its list with gc’s, so a gap on either side cannot widen what leaves the host. Rather than implement the grammar below, a script can ask gc for the entries that survive it:
  • Call the gc named by the start config’s env.GC_BIN, the binary that produced the list. An older gc on PATH may lack the subcommand.
  • Check its exit status (set -o pipefail in a pipeline). On failure it prints nothing to stdout, and an unchecked pipeline archives an empty work dir.
  • Use --null. The default newline-terminated output is for humans only: no byte filter makes it safe for a consumer that splits on blanks or quotes, such as xargs. As a backstop it refuses, printing nothing, any entry that contains a newline, a carriage return, or a backslash (GNU tar -T reads \057 as /), or that starts with -.
  • GNU tar reads a --null list verbatim only from 1.30; bsdtar always does. Older GNU tar unquotes backslash escapes even with --null, so a crafted file name can make it archive .gc/controller.token or a file above the work dir. Where GNU tar may predate 1.30, use the form below: 1.29 reads the list verbatim with it, and older releases reject its options, which fails the pipeline. bsdtar rejects those options, so keep the form above there.
  • The output lists every surviving file and symlink, plus every surviving directory that is empty on disk. A non-empty directory is never listed, so a consumer that recurses into listed entries still copies nothing excluded; a consumer that does not recurse recreates parent directories from the paths below them. A directory whose every entry is excluded is absent.
  • Entries come in depth-first walk order, each directory’s entries sorted by name. This is not sort order: a/b comes before a-c.
A script that applies work_dir_exclude itself copies symlinks as links and never dereferences them: an in-tree link such as x -> .gc/controller.token would otherwise ship its target. Pattern grammar:
  • Patterns and paths are /-separated and relative to work_dir.
  • A segment of exactly ** matches zero or more whole path segments.
  • Every other segment is a single-segment glob (Go path.Match syntax): * matches any run of characters except /, leading dots included.
  • A path is excluded when it, or any directory above it, matches. A trailing /** spells out that a whole subtree stays behind.
  • This is not gitignore, rsync, or tar --exclude syntax. A pattern with no / matches only at the work-dir root, and .gc/**/*.sock matches .gc/controller.sock because ** may match zero segments. Translating patterns into another tool’s syntax is error-prone; prefer gc runtime workdir-export.
The list covers secrets and credentials (.gc/services/**, .gc/secrets/**, .gc/controller.token, .gc/credentials.toml, .gc/credentials.json, .gc/mcp-adopted/**, .beads/.env, .beads/.beads-credential-key, .beads/proxy.secret), the event and usage logs, the nudge queue, per-session diagnostics under .gc/sessions/ and ACP transcripts under .gc/transcripts/, sockets, locks and pid files, the stores under .gc/store/ (the default SQLite binding root), .gc/storage/, .gc/infra/ and .gc/dolt-data/, bd’s stores and their backups in any scope (.beads/dolt/, .beads/doltlite/, .beads/embeddeddolt/, its SQLite files, bd backups and corrupt-store backups), the file provider’s .gc/beads.json and its .bak in any scope, the legacy JSONL archive, every file named beads.sqlite* wherever it sits, bd server, proxy and sync state, the provider-lifecycle journal .gc/scope-ownership.json, orchestrator runtime state, and other agents’ work dirs under .gc/worktrees/ and .gc/agents/. Copying any of it gives the session a stale, private fork of state the orchestrator owns, or hands it secrets it must not hold. Files the session needs are never listed: .gc/settings.json, .gc/site.toml, .gc/cache/ and .gc/system/ (pid and socket files aside), .gc/scripts/, the prompt and skill snapshots under .gc/tmp/, the staged prompts under .gc/synth/, the MCP projections under .gc/mcp-managed/, the step and iteration artifacts agents read and write under .gc/molecules/ and .gc/artifacts/, the .gc/file-beads-layout marker, .beads/metadata.json, .beads/config.yaml, .beads/http_target.json, and .beads/redirect. The list is fixed and matches paths by name. It does not read the city’s configuration: when a SQLite storage binding’s path moves its root to a path inside the work dir that the list does not name, only that root’s beads.sqlite* files match, and a script for such a city adds the root to its own denylist. Matching names also cannot stop a process on the orchestrator host from copying or hard-linking excluded content to a path the list keeps. .gc/site.toml ships because session-side gc commands load it with city.toml: it carries the workspace name and bead prefix as well as rig path bindings. Its rig paths are orchestrator-host paths, so a script that relocates the work dir remaps them as it remaps the GC_* path variables. The field is additive. A script that predates it ignores the unknown key and keeps copying the whole work dir.

Conventions

  • stdin for values: set-meta, nudge, and start pass data on stdin to avoid shell quoting and argument length limits.
  • stdout for results: is-running, process-alive return true/false. get-meta returns the value or empty for unset. list-running returns one name per line.
  • Idempotent stop: stop must succeed (exit 0) even if the session doesn’t exist.
  • Best-effort interrupt/nudge: Return 0 even if the session doesn’t exist.
  • Empty = unsupported: get-last-activity returning empty stdout means the backend doesn’t support activity tracking (zero time in Go).

Session identity

The env object in the start config carries the session’s identity: GC_SESSION_ID, GC_INSTANCE_TOKEN and GC_RUNTIME_EPOCH. When get-meta returns these keys from the moment is-running reports the session, the orchestrator can tell which session a running box belongs to. After an orchestrator restart it then adopts a session whose start was cut short, instead of failing it. A script whose get-meta answers them empty still works. If a session created with gc session new (or the API) fails to start, or its start is cut short, the orchestrator stops any box running under its name before it marks the session failed. A box that reports another session’s GC_SESSION_ID is left alone. That teardown reads the identity keys first, so get-meta must print nothing and exit 0 both for an unset key and for a session that does not exist. A non-zero exit reads as “cannot tell”: a failed gc session new or API session then stays open in creating until get-meta answers, or until an operator runs gc session close. A script that runs its backend’s CLI under set -e should catch the “no such session” case and print nothing.

observe.v1 (reconciler v2)

Reconciler v2 starts, stops and recycles sessions only on fresh, exact answers: “this box is absent”, “this is the box, and this is whose”, “kill exactly that box”. A script opts into giving them by declaring observe.v1 in its handshake. A script that declares observe.v1 and report-attachment is v2-ready: gc reads it through observe.v1 on the handshake alone. gc runtime conformance reports v2-ready: yes only for a script that also passes every requirement; otherwise it names the capabilities the script lacks and the requirements it failed. A script that declares neither keeps today’s behavior exactly. Reconciler v2 runs on a v2-ready script, and refuses any other exec runtime, naming what its handshake lacks. Admission asks the script’s protocol once per version of the file (its path, size, modification time and inode), within 10 seconds, and remembers the answer; at boot the controller checks that the provider it built reads the same. With session_reconciler unset, a v2-ready script switches the city to v2 unless the city falls back to legacy for another reason, and the boot log and gc doctor say which. input-fence is not required, but without it (with proc.exec) input gc fences to one incarnation is refused on the box, and gc doctor warns. The handshake’s locality decides whether gc’s storage verbs treat the runtime as remote (absent: remote). Declaring observe.v1 obliges the script to:
  1. Implement observe, inventory and kill-object (below).
  2. Honor fresh_only on start (and provision, if declared).
  3. Treat exit 2 from every op it implements as a failure: stop exit 2 is a stop that stopped nothing, a metadata op’s exit 2 is a missing store, and the observe.v1 ops’ exit 2 is an unknown answer.
  4. Keep one identity: get-meta <name> GC_SESSION_ID | GC_RUNTIME_EPOCH | GC_INSTANCE_TOKEN | GT_PROCESS_NAMES answers what the session started with, or what set-meta set since, and observe and inventory report the same values. For boxes started before the script declared observe.v1, derive them from the box’s own configuration.
  5. Seed identity before the box is visible: persist it before creating the box (or create the box with it, atomically). Until it is readable, answer "identity": null.
  6. Read the backend on every observe; never answer from a cache older than the call.
  7. Answer absent (or omit a name from a complete inventory) only when the backend proves nothing holds the name, live, dead, starting or stopping. If the backend’s view is partial or stale, answer unknown (or set complete: false).
  8. Answer is-attached true when any interactive client is attached by any means, not only through gc (screen’s multiuser Multi, attached included); exit non-zero when it cannot tell, including when the backend cannot be read. Only true or false is an answer.
  9. Serialize ops per name (for example with flock): start, stop, observe and kill-object for one name may race. A fresh_only start checks and creates under the lock.
  10. Never print GC_INSTANCE_TOKEN on stderr. gc never echoes observe or inventory stdout into an error or a log.
  11. Answer observe and is-attached within 4 seconds: gc stops the call there (SIGTERM, then SIGKILL 2 seconds later) and reads it unknown.
  12. With more than one city on one backend, scope boxes by GC_EXEC_CITY_PATH / GC_EXEC_CITY_NAME, which gc sets on every op.
  13. Implement peek for every box the name holds, live or dead (below).

peek <name> <lines> under observe.v1

Before v2 recycles a box that died, it reads the box’s screen to tell why: a provider’s terminal error parks the session, and a rate-limit screen quarantines it, instead of relaunching it into the same failure. For a v2-ready script, gc runs peek whatever is-running says. A running box is read as before (over exec when the runtime implements it); for a dead box gc runs peek itself. The script must:
  • print the box’s last <lines> lines of screen and exit 0, dead box included, when it can read them (a blank screen prints its empty lines; a capture that wrote nothing is a failure, not a blank screen);
  • exit 66 (no screen) when nothing holds a screen for the name: no box, or a dead box whose screen is gone. gc reads it as a known-empty screen wherever it reads one: v2 recycles the box, and a start whose agent exited while its startup dialogs were read goes on as over a blank screen;
  • exit non-zero otherwise (the backend cannot be read, the screen cannot be captured). gc never reads a failed peek as an empty screen: v2 refuses the recycle (peek-error) and retries it on the row’s backoff (10s, doubling, at most every 5 minutes) until peek answers, the box goes away, or the session is stopped, which removes a dead box by its object without reading its screen. The hold has no deadline of its own; once its refusals reach the backoff’s cap with the latest a peek failure, gc raises a peek-held alert naming the session, the error and that remedy, and repeats it about every 30 minutes while it lasts.
Its exit 2 is a failure, not the unknown-op no-op.

observe <name>

Stdin carries zero or more agent process names, one per line. Stdout is exactly one JSON object:

Agent liveness

agent: dead is a verdict gc acts on: a running box whose agent is dead is a zombie, and v2 recycles it with kill-object. Answer dead only when sure:
  • Look at every descendant of the box’s root process, not only its direct children: the agent often runs under a shell wrapper.
  • Match a process the way gc’s own process table does: its command name’s base name, or argv[0]‘s base name, is one of the names; or argv[0] is an interpreter (node, bun, npx, deno) and the first argument that is not a flag or a runner subcommand (run, exec, x) has one of the names as its base name, with or without its extension. The command name alone is not enough: the kernel truncates it to 15 characters, and Node 25 names its main thread node-MainThread.
  • Apply gc’s name aliases: kimi also matches kimi-code (the kimi entry point’s command and argv[0]), and gc also matches the base name of the gc binary the session runs (its GC_BIN, which differs when gc is renamed or wrapped, for example .gc-wrapped).
  • Read one process snapshot (for example ps -ww -eo pid=,ppid=,args= and ps -eo pid=,comm=) for every box, not one probe per box. Without -ww, procps cuts each line to COLUMNS even into a pipe, and an agent with a long command line reads dead.
  • When the snapshot cannot be read, or the box has no process names, omit agent (unknown): gc then does not recycle the box, and kill-object’s zombie mode re-checks the agent before it kills.
A non-zero exit, a timeout, malformed or oversized output (over 1 MiB), unknown, or a present state without its object all read as unknown, never as absent.

inventory

No name and no stdin. Stdout is one JSON object of at most 8 MiB, listing every name the backend holds for this city, live or dead:
  • complete: false lists names that are present and proves nothing else absent. Any failure is a non-zero exit.
  • attached, last_activity, restart_requested and identity may be null (not read). attached is not null for a script declaring report-attachment unless it genuinely could not tell, and last_activity is not null for a running session of a script declaring report-activity.
  • An entry whose name cannot be read fails the whole answer; an entry with a readable name and malformed attributes is listed with them unknown.
  • A name listed twice fails the whole answer: gc cannot tell which box is the name’s, so it cannot prove the listing complete.
  • Keep inventory cheap. On a v2-ready script every listing call runs inventory: gc’s inventory pass (every patrol interval, 15-30 seconds on a typical city, and on every wake), gc stop, status and the API; gc does not call list-running there. The inventory pass gives it at most 10 seconds, a listing call 30. Answer from one backend query and one process snapshot for the whole city, with no per-box round trip. list-running stays for older gc.

kill-object <name>

Stdin: {"object":{"id":"…","created":"…"},"mode":"corpse"|"zombie","agent_pid":"…"}. Re-check, then kill the exact object, as one backend operation where the backend allows it (docker rm -f <id>, a Kubernetes delete with a UID precondition, screen -S <pid>.<name> -X quit). Never kill by name. Stdout is exactly one of killed, gone, renamed, live or changed.

fresh_only starts

gc sends "fresh_only": true in the start config to a v2-ready script. If any box, live or dead, holds the name, exit 73 (or exit 1 with already exists / already running on stderr) and touch nothing; otherwise create a new box, never recycling, killing, reusing or respawning one. gc sets GT_PROCESS_NAMES and GC_INSTANCE_TOKEN in env, and after a failed start stops a box only when a fresh observe shows it carrying that start’s token.

Conformance

gc runtime conformance <script> gates every promise above as the observe group (RPP-OBSERVE-001 to RPP-OBSERVE-016), except peek of a dead box: the kit has no way to leave one, so RPP-OBSERVE-016 reads only a running box (exit 0) and a name no box holds (exit 66). gc runtime check runs a smoke check of the three ops. contrib/session-scripts/gc-session-screen is the reference implementation. The same command checks the bookkeeping ops every script may implement, each skipped when its op answers exit 2 and failed when it answers wrongly:

Switching an existing exec city to v2

Upgrading gc alone changes nothing for a script that does not declare the profile: the city stays legacy. Declaring observe.v1 and report-attachment makes an unset session_reconciler resolve to v2 at the next controller start, unless the city falls back to legacy for another reason (pin session_reconciler = "legacy" to stay). It also changes what the script’s legacy city sees: a failed observe reads unknown rather than not running, listings are attested (so gc stop skips its per-name sweep), and a declared op’s exit 2 is a failure. Before switching a city with running sessions:
  1. Run gc runtime conformance <script>.
  2. Run gc doctor: exec-runtime-identity judges each running box under an open session row as v2 does, on its batched identity or, when that is null, its observed one, and names the boxes v2 would hold instead of adopting them: Ownerless (no GC_SESSION_ID and no GC_INSTANCE_TOKEN) or Unknown (no token that matches the row, and no proof the box is the row’s own). Make the script report the identity of boxes it started before the upgrade (observe.v1 item 4).
  3. Otherwise stop those sessions first.

Writing Your Own Script

  1. Start with contrib/session-scripts/gc-session-screen as a template.
  2. Implement the operations your backend supports.
  3. Return exit 2 for operations you don’t support.
  4. Validate with gc runtime check ./your-script — it runs the protocol handshake, the required lifecycle round-trip (start, is-running, stop, idempotent stop), exercises every capability the handshake declares, and probes optional operations (absent ones are reported, not failed). It exits non-zero if any check fails, so CI can gate on it.
  5. Test with GC_SESSION=exec:./your-script gc start <city>.

Minimal script (start/stop/is-running only)

Environment Variables

Scripts can use GC_EXEC_STATE_DIR (if set) as a directory for sidecar state files (metadata, wrappers). gc does not set it. A script’s default must not depend on the caller’s session environment: the supervisor, a cron job and a sudo shell differ in XDG_RUNTIME_DIR, TMPDIR and even HOME, and a box one of them cannot find reads absent, so a v2 start creates a twin. Derive the default from something fixed per user (the home directory in the password database, for example). An operator who sets GC_EXEC_STATE_DIR must set the same value for every gc process of the city. A home can be shared between hosts (NFS), so a script whose boxes live on one host keys that state by host as well, or one host reads the other’s boxes as dead and removes them. gc sets GC_EXEC_CITY_NAME and GC_EXEC_CITY_PATH on every operation to the city the provider serves, the admission probe’s protocol (see observe.v1) included. A script shared by several cities on one backend scopes its boxes and listings by them. A handshake should still read no state and answer the same for every city: gc start, the orchestrator and gc doctor each probe it in their own process and remember the answer per version of the file. gc sets GC_EXEC_DEADLINE_MS on every operation it runs under a deadline — all of them but attach, and watch-startup when its start has none — whether or not the provider serves a city. It is the whole milliseconds left, rounded down and never negative, until the operation is killed: the earlier of the operation’s own timeout and any deadline gc’s caller already set. A script can budget its own inner calls by it. gc counts it from just before the spawn, so it is an upper bound; an operation whose deadline has passed before it is spawned is not run at all. It is informational: no handshake capability declares or gates it. A session a script starts may live in a cgroup of its own that the script kills whole when it stops the session. The city’s store is not caught in it when a gc command in the session starts it: gc starts its managed Dolt server in a transient user scope under GC_INFRA_SLICE (default gascity-infra.slice) when the session runs under the user’s systemd manager, or in the user’s login session and the user lingers. From any other cgroup, such as a system-level scope or a container, gc moves the server only when GC_INFRA_SLICE names a slice, and GC_INFRA_SLICE=off turns the move off. A supervisor a session forks is not moved. See City infrastructure. A script runs with gc’s own environment, without the session identity a gc command run from an agent’s shell carries (GC_SESSION_ID, GC_SESSION_NAME, GC_RUNTIME_EPOCH, GC_INSTANCE_TOKEN, GC_AGENT, GC_ALIAS, BEADS_ACTOR and the rest of the list gc’s managed Dolt server is started without): an operation belongs to no session. A server an operation starts therefore never reads as that session’s leftover process, and never carries its instance token. The session’s environment arrives in the start config’s env (see Session environment).

Shipped Scripts

See contrib/session-scripts/ for maintained implementations:
  • gc-session-screen — GNU screen backend, v2-ready (observe.v1, report-attachment, city-scoped, locality local). Each city gets a private screen socket directory under the script’s state directory. Dependencies: bash, screen, jq, flock, procps ps and kill, awk, cksum, uname.
Last modified on November 13, 2026