Skip to content

Latest commit

 

History

History
665 lines (577 loc) · 57.8 KB

agent-sessions.md

File metadata and controls

665 lines (577 loc) · 57.8 KB

Agent sessions

Board tasks: #69, #115 (starting sessions), #96 (Codex sessions and models), #185 (sessions on a machine), #251 (Antigravity sessions), #259 (Codex's live status). Verified against Claude Code 2.1.301 and Copilot CLI 1.0.85 on Windows (October 2026), codex-cli 0.166.0 and 0.172.0 on Linux (November 2026) and agy 1.5.19 on Linux (November 2026).

An agent in Claude Code, Codex, Copilot CLI or Antigravity links its own session to the task it works on, or the board starts a session itself from the hand-off menu: it links a Claude Code or Copilot CLI session, and a Codex or Antigravity session links itself (Starting a session). The board then shows whether that session is still running (Codex and Antigravity on Linux only: see Live status) and offers Open in terminal, which resumes it in a new terminal window in the session's folder, with Copy resume command as a fallback. T3 Code threads already link back to their conversation (agent hand-off); this does the same for sessions run in a terminal, and gives a session inside T3 Code a way out to one.

How it works

Linking a session

The agent calls link(task, agentSession: {harness, sessionId, cwd}, label). Each harness puts the id in an env var the agent reads with its shell:

Harness harness Id from Resume Fork
Claude Code claude-code $CLAUDE_CODE_SESSION_ID claude --resume <id> claude --resume <id> --fork-session
Codex codex $CODEX_THREAD_ID (checked on codex-cli 0.166.0: the same id as thread.started) codex resume <id> none
Copilot CLI copilot-cli $COPILOT_AGENT_SESSION_ID copilot --resume=<id> none
Antigravity antigravity $ANTIGRAVITY_CONVERSATION_ID (checked on agy 1.5.19: the conversation's id, as stream-json's conversation_id) agy --conversation <id> none

Antigravity's CLI is agy, never antigravity (the Antigravity app). Like Codex it picks its own id (presetSessionId false), so a session the board starts links itself. Autopilot's headless runs use it too (autopilot). Every per-harness branch is an exhaustive switch or Record (assertNever in packages/contracts/src/exhaustive.ts), so no harness falls back to another's behaviour.

Antigravity inside T3 Code links only its T3 thread, never an agentSession: every self-link text says so (SELF_LINK_ANTIGRAVITY_IN_T3 in selfLink.ts), and the agent tells by $T3CODE_THREAD_ID, which T3 Code sets in the CLIs it runs. T3 Code can run agy with a folder of its own, where the user's agy doesn't look, so agy --conversation couldn't reopen it. The board can't tell such a link from a native one (agy says antigravity-client in T3 Code too), so Open in terminal checks first that agy keeps the conversation here (~/.gemini/antigravity-cli/conversations/<id>.db) and otherwise refuses with a message to open it in the app it ran in. Claude Code and Codex inside T3 Code share their CLI's folder, so they link both.

Conversations in the Antigravity app. The desktop app (checked on 2.36.0) reads agy's ~/.gemini/config, MCP servers and skills included, so registering the board for agy gives the app's agents its tools too. The app sets $ANTIGRAVITY_CONVERSATION_ID for its commands, so its agents link antigravity sessions like agy's. The app keeps them in ~/.gemini/antigravity/conversations/<id>.db, where agy doesn't look. antigravityConversationOwner in agentSessions.ts says whose a conversation is: agy's when it has conversations/<id>.db (agy's wins if both do), else the app's, else neither. Status reads unknown for the app's: it holds no lock on an open, idle conversation, so its presence files say nothing. Open in terminal refuses it with a message to open it in the Antigravity app. Reading its real status, and opening it in the app, are left to #141.

Codex sessions are linked by agents running in Codex, like the other two, and by Autopilot's headless runs (autopilot), which read the id from codex exec's first event. Codex picks its own session id (AGENT_HARNESSES.codex.presetSessionId is false), so a Codex session the board starts from the hand-off menu can't be linked before it runs: its prompt tells it to link itself (Starting a session). The board resumes one with codex resume <id> and never forks it. On Linux it reads whether a Codex session is open from the thread's writer lock (Live status).

The link is an agent_session link stored under agent-session://<harness>/<id>, so linking the same session twice returns the first link; a different folder replaces the stored one (logged as link_updated), since Claude Code finds a conversation to resume by its folder. The label says what the session does ("Implementing #107", "Planning #107", "Orchestrating #107" for an epic; see Names); linking again with a different label renames the session (also logged as link_updated). The id must be a UUID and the folder an absolute path, with trailing separators dropped (AgentSessionRef). The board links sessions it starts itself, such as Autopilot's headless runs, through services.links.add with the same input; their folder can be a worktree outside the project.

Agents are told this in four places: the link tool's description and the server instructions, the hand-off and planning prompts, the results of set_plan and move_task to in_progress, and get_task's Missing links. The session hint in Missing links asks only when the MCP client is Claude Code, Codex, Copilot CLI or Antigravity (harnessOfClient in apps/server/src/mcp/format.ts). Codex names itself codex-mcp-client in initialize and in its User-Agent (checked on codex-cli 0.166.0), agy antigravity-client (agy 1.5.19); the server is stateless, so tool calls read it from the User-Agent. The shipped skill and AGENTS.md snippet say the same.

How an agent links itself

Every host's lookups and link call are in one registry, SELF_LINK_HOSTS in packages/contracts/src/selfLink.ts: T3 Code plus one entry per AGENT_HARNESSES harness. Prompts, hints and tool descriptions are built from it, and skills.test.ts fails if the skill files disagree with it. A new CLI goes in AGENT_HARNESSES and reaches every text. Another kind of host is one more entry in SELF_LINK_HOSTS, which the reminder picks up; the prompt lines and the Missing links hint name T3 Code and the CLIs, so they need it too.

Host Tried in order Call
T3 Code the t3_thread_configure tool with no arguments, then a T3 reference on the conversation's messages that identifies this thread link(value: "<thread id>"); if the board refuses it, t3_environment_read and link(t3Thread: {environmentId, threadId})
Claude Code, Codex, Copilot CLI, Antigravity the harness's one variable, in the table above (Antigravity inside T3 Code links as T3 Code instead) link(agentSession: {…}, label)
Anything else a URL for the session or thread, if the host has one link(value: "<url>", label)
  • When. An agent links when it creates a task it will work on or starts planning or implementing one, not when it only reads, notes, triages or moves one. set_plan and move_task to in_progress carry the reminder even when another thread or session is linked, as whoever filed the task may have linked theirs. Missing links asks only on a task in progress. The board never links a session just because it called the board.
  • Environment. Agents read only the named variable and are told never to list their environment. T3 Code has $T3CODE_THREAD_ID, deliberately not used: T3's own tool and message references need no shell.
  • A bare thread id is enough. The board adds the environment and checks the thread exists, on link and on the links of add_to_backlog, create_task and create_epic. A thread it can't place doesn't fail a create: the result says it wasn't linked. Where the board can't place a thread (T3 isn't detected, or the thread is in another environment), the refusal points the agent at t3Thread: {environmentId, threadId}, which the board doesn't check.
  • When nothing works, the agent says so in its reply, with what it tried, records the same with add_note, and carries on. It doesn't use request_attention for this.
  • Refused values are repeated in errors only when id-shaped (rejectedValueText), so text pasted by mistake stays out of logs and transcripts.

Not done: the host passing its identity when the agent connects to MCP, which would spare agents the lookup and could be added later. Until then the board can't force a link or detect a missing one.

Live status

Every 20 seconds, while a browser is connected and at least one session is linked, the server reads the harnesses' own files and stores what it finds as the link's snapshot. A changed snapshot reaches browsers as task.upserted, as PR and T3 thread state do. A session's status is also read when it is linked (by an agent, or by Autopilot as its run starts) and again just before it is opened.

A poll that fails, finds no links or takes longer than 30 seconds (a hung PowerShell, a stalled disk) never stops the next one. Don't reset the in-flight guard from inside the async function that is being guarded: with nothing to await, it runs before the guard is assigned and leaves it set for good, which once stopped polling until the server restarted.

Status Shown as Claude Code Copilot CLI Antigravity Codex
busy Working a live sessions/<pid>.json says busy
idle Idle it says idle
running Running it says something else a live process holds session-state/<id>/inuse.<pid>.lock a lock is held on presence/<id>.lock a lock is held on thread-writer-locks/<id>.lock
not_running Not running no live file for the session no live lock, or no session folder no lock held on it, or no such file no lock held on it, or no such file
unknown Status unknown no sessions folder, or a live process's file can't be read no session-state folder no presence folder, not Linux, or a conversation the Antigravity app keeps no thread-writer-locks folder, or not Linux
finished Finished 5m ago an Autopilot run's session whose run ended well
failed Failed 5m ago an Autopilot run's session whose run failed
  • Claude Code's folder is $CLAUDE_CONFIG_DIR, else ~/.claude; Copilot's is $COPILOT_HOME, else ~/.copilot; Antigravity's CLI's is ~/.gemini/antigravity-cli (agy ignores GEMINI_HOME; ~/.gemini/antigravity is the app's); Codex's is $CODEX_HOME, else ~/.codex (SessionDirs.codexHome). No format is documented, so anything unexpected reads as unknown rather than a guess.
  • agy makes presence/<id>.lock when a conversation opens and leaves the empty file behind when it exits, so the file says nothing; agy holds a lock on it (a FLOCK under its own pid) while the conversation is open (agy 1.5.19). The board reads Linux's /proc/locks once a poll (ProcessProbe.lockHolders("agy")), keeps the locks whose holder's /proc/<pid>/comm starts with agy, and matches the file by inode but not device: /proc/locks names the filesystem's device, which on btrfs isn't the one stat gives, so the holder's name is what keeps another program's lock on a same-numbered file elsewhere out. macOS and Windows have no such list, so an Antigravity session is unknown there.
  • Codex keeps thread-writer-locks/<thread id>.lock, and whichever Codex process has the thread loaded holds a lock on it; another writer is refused with "thread … already has an active writer". The interactive CLI holds it (a FLOCK under its own pid) for as long as it is open, through turns and idle alike, and deletes the file when it exits (codex-cli 0.172.0); codex exec, the shared app-server service (codex app-server daemon, which keeps a thread locked while it has it loaded, even after thread/unsubscribe) and the ChatGPT app's bundled Codex hold it too, and have left the file behind. So Codex's running means a Codex process has the thread open, never whether a turn is going: Codex has no busy or idle. Every holder seen is named codex, so the board reads the locks the same way as agy's (lockHolders("codex"), once a poll, by inode), with the same unknown outside Linux.
  • T3 Code runs its Codex threads through a codex app-server of its own, which holds a thread's lock while it has the thread loaded. When a holder's parent, or its parent's, and so on, is named t3code (ProcessProbe.descendsFrom walks /proc/<pid>/stat), the session is running with inApp, so the card says Running in T3 and Open in terminal offers the thread. That is right even when the conversation is long over: Codex refuses a second writer, so codex resume in a terminal couldn't take the thread while T3 Code has it. A thread open in the ChatGPT app reads as plain running, since inApp means inside T3 Code.
  • A pid counts only while process.kill(pid, 0) finds it. Claude Code removes its file on a clean exit; after a crash the file stays and the pid can be reused. On Windows procStart is the process's creation time as a FILETIME, compared with Get-Process's start time in one PowerShell call for all pids, cached for five minutes per pid. Elsewhere the reuse check is skipped.
  • Autopilot's headless sessions take their state from the run that made them (autopilot_runs.session_id), not from the files: busy while the run is queued or running, then finished or failed with endedAt, the time the run ended. Once it ended, a live process for the session (someone resumed it in a terminal) shows its own status instead, so Open in terminal still warns. The runner refreshes the link as it adds it, and the engine as the run ends, rather than waiting for the poll. Open in terminal and Fork work on a finished or failed session as on a stopped one.
  • inApp is set when Claude Code's entrypoint starts with sdk (T3 Code runs it through the Agent SDK), and for a Codex thread whose lock a process under T3 Code holds.
  • A session that ran on a connected machine has that machine in its link (ref.machine: instance id and name), set by the runner's run or by link on a runner. Its files are there, so the board never reads it: the runner polls it (every 20 seconds, with no browser needed) and the snapshot arrives with the task's changes (remote machines). Open in terminal opens it there, over ssh (On a machine).
  • The task panel names the machine on the rows of a session or T3 thread that has one, with the same "on Engine" label as an Autopilot run (MachineLabel). A session row adds the folder it runs in there ("on Engine · shop", the full path in the tooltip) in place of its own folder label; a T3 thread's link carries no folder, so its row names only the machine. A machine's thread offers only Open in T3 Code: the browser link is built from the board's own T3 origin, which isn't the machine's, so t3LinkTargets leaves it out.

Opening a session

Open in terminal posts to /api/links/:id/resume with a mode (resume or fork) and force. The server re-reads the link, checks the folder still exists, reads the status afresh, and:

  • for a running session the board started in a named Windows Terminal window (the link's window), while the terminal setting is still Windows Terminal, runs wt -w <window> focus-tab -t 0 and answers {launched: true, focused: true}: the window comes back to the front on its first tab. If that can't start, or the terminal is another one, it is treated like any running session:
  • answers 409 with the snapshot when the session is running and the mode is resume without force. The web app then asks: Fork (Claude Code, recommended), Open anyway, Cancel, and Open T3 thread when the session runs inside T3 Code and the task has a thread;
  • otherwise starts the terminal and answers {launched, command, error}. When the terminal won't start, launched is false and command is what to paste instead; the web app shows it in a toast with Copy command.

Copy resume command (GET /api/links/:id/resume-command) gives cd <folder> and the resume command, quoted for the shell the terminal setting opens.

The terminal

Settings → Integrations → Terminal picks where sessions open (terminal setting, machine-only, not in backups):

Setting Runs
Automatic, Windows Windows Terminal's default profile, else a Command Prompt window
Automatic, macOS Terminal, through osascript
Automatic, Linux the first of x-terminal-emulator, gnome-terminal, konsole, xfce4-terminal, xterm, running bash -c 'cd <folder> && <command>; exec bash'
A Windows Terminal profile wt -w 0 new-tab -p <guid> -d <folder> <shell> … (-w new with Open in: New window)
Command Prompt, Windows PowerShell a console window through cmd /c start
Custom command the template, with {cwd} (quoted) and {command}, run by cmd on Windows and sh elsewhere. On Windows a folder containing % is refused, as cmd would expand it

Open in (terminalOpenIn, machine-only; shown on Windows for Automatic and Windows Terminal profiles) is a new tab in the last window (default) or a new window. -w 0 is Windows Terminal's most recently used window, and it starts a window itself when none is open. It doesn't apply to Command Prompt, PowerShell, macOS, Linux or custom commands.

Windows Terminal's settings are read from the Store, Preview and unpackaged locations, with comments and trailing commas allowed. A profile's shell comes from its commandline (or its source for PowerShell 7 and Git Bash), and the command runs inside that shell so the window stays open after the session exits: bash -l -i -c '<cmd>; exec bash', cmd /k, PowerShell -NoExit -Command. Windows Terminal splits its own command line on ;, quotes or not, so every ; is passed as \;. A profile we can't drive (WSL, Azure Cloud Shell) keeps its look and runs cmd. The settings page shows what the current setting runs for an example session.

The rules for starting processes are in ADR 0009 and, for new sessions, ADR 0010.

Providers and detection

A provider (T3 Code, Claude Code, Codex, GitHub Copilot, Antigravity: PROVIDERS in packages/contracts/src/providers.ts) is opt-in. The user adds it in Settings → Agents → Providers, and the providers setting keeps { id, enabled, cliPath } for each one added. A provider that isn't added, or is switched off, shows nowhere else: not in the hand-off menus (handoffClis, canStartProjectT3Thread), the launch and plan dialogs opened from them, the Models page's columns, or the model pickers' provider tabs. Agents can't start T3 threads without T3 Code added (t3LaunchBlocker). Sessions and threads already linked to tasks still open whatever the list says. harnessCliSetting reads a CLI provider's path from the list (none looks the CLI's name up on PATH); the board reviewer, issue import, the settings Ask, new sessions, resumes and headless runs all use it. See ADR 0011.

GET /api/providers (createProviders in integrations/providers.ts) is the one place the board detects them, for every provider whether added or not (the Add provider dialog shows what this machine has). Per provider it returns:

  • cli: the configured path (else the name on PATH) resolved, its version, or why it isn't usable. Null for T3 Code.
  • mcp: whether an entry with the board's MCP URL exists, its name and scope, and whether the harness says it connects (connected is null when it can't tell). Null for T3 Code.
  • t3: T3 Code's live status (detected, origin, label, liveStatus) and whether a token is saved.
  • models: what the models scan (agentModels.ts) found, only for the CLI providers while added and on, since scanning starts the CLI.

?parts=cli answers with the CLI checks and T3 Code only. The board's menus and session rows read that (useAgentClis), so they never wait on claude mcp list or a model scan; only Settings → Agents → Providers asks for the rest. The CLI checks are kept for a minute by their paths and shared by both answers; the MCP and model checks are kept for a minute, keyed by the enabled providers and the board's URL, so a new CLI path or a provider switched on asks again; ?refresh=1 (Re-check) skips the cache and a refresh while a check is running joins it. T3 Code's part is never cached: a plain read returns the integration's last status (the timer looks every minute), while a re-check also runs a full T3 check first (t3.test(): discovery, then a live poll), alongside the CLI checks, so a T3 started after the board shows up at once. An open page also follows T3 between re-checks: on integrations.changed the web patches T3's part of the cached detection (withT3Status, keeping tokenSet, which the event lacks) instead of refetching, which would re-run the CLI and MCP checks. A change to the list publishes providers.changed, which updates the settings cache in every window and refetches the detection.

The MCP entry is found by URL, not name: sameMcpUrl treats localhost, 127.0.0.1 and [::1] as one host, compares the port and path, and ignores a trailing slash and the query (which may carry a token). Claude Code is asked with claude mcp list (and mcp get for the scope), run from the home folder, which doesn't list servers added to one project (local scope), so ~/.claude.json is also read for those (reported as local scope, with a hint to use --scope user); if the CLI fails or times out, that file is all there is. Copilot CLI has no such command, so ~/.copilot/mcp-config.json (or $COPILOT_HOME/mcp-config.json) is read, and for Codex ~/.codex/config.toml (or $CODEX_HOME/config.toml): codexMcpEntries reads only its [mcp_servers.<name>] headers and their url lines. Antigravity's is ~/.gemini/config/mcp_config.json (agy writes mcpServers.<name>.serverUrl). GEMINI_HOME is not followed: agy 1.5.19 wrote its mcp add entry to ~/.gemini with it set elsewhere, and T3 Code points it at a private copy of its own. An empty or missing file is nothing set up yet. The board never writes it: the row shows the agy mcp add command. Config files are only read for server names and url strings, never headers or env, and no URL or token is put in the result.

Antigravity in T3 Code

T3 Code runs Antigravity with a private GEMINI_HOME per profile (<T3 home>/userdata/providers/antigravity/<hash>/) and, on each launch, links the user's ~/.gemini/config/skills and ~/.gemini/antigravity-cli/skills into it. A regular file at either link path makes that fail on every launch with only a logged warning (t3code #45309), so the board skills never reach Antigravity threads in T3. t3AntigravityLinks.ts finds such files for the Antigravity provider's t3Links (a full check on a board, not a runner, outside the minute's cache: it is a few lstats), and POST /api/providers/antigravity/t3-links/repair deletes one after the user confirms in the editor.

It is the one place the board touches T3's private folder, which holds Antigravity's sign-in, so it is kept narrow:

  • Only the two folder links are looked at, with lstat; a regular file's first 8 bytes are read for the IntxLNK magic, only to say what it is. No other file in the profile is opened.
  • A path is flagged only while its target under ~/.gemini exists: without it T3 skips the link anyway.
  • The repair takes a profile hash and a path from the fixed list (zod, never a free path), checks again that a regular file is there and its target exists, and unlinks it. It never deletes folders or links, and never makes the link: T3 does on its next Antigravity launch.
  • The file links T3 also makes (AGENTS.md, GEMINI.md, config/skills.json) aren't checked: T3's fix keeps a regular file there as the profile's own copy, and removes any regular file at the folder links, which is the rule this follows.

A provider's dot (providerDot in settings/providers.logic.ts) is grey while switched off, green when the CLI runs and the MCP entry exists (a project-only entry that the CLI can't confirm is amber: it is missing in other folders), and for T3 Code green once a saved token connects; connected: false only adds a note, because a harness can report a server as down while it would connect when a session starts.

The page saves the list with useUpdateProviders: each change is a function applied to the cached list when it is made, which already holds the edits not yet saved (settings writes are optimistic, live-sync), and the saves reach the server in order, so two quick switches can't undo each other.

Upgrading. Migration 040_providers_settings seeds the list from what an install already uses: a CLI path set, the T3 token, the board reviewer on, a tier or custom model with a model (or headless runs) for a provider, and sessions or T3 threads linked to tasks. It moves headlessReviewCli, codexCli and copilotCli into cliPath. What only the machine can tell is left to seedFromDetection, which runs once after start-up on an install that had data (the migration leaves a providersDetectSeed marker): it adds providers whose MCP entry is registered, and those whose hand-off entry the menus showed (the entry on and the CLI found).

Starting a session

The hand-off menu on a card and in the panel offers New Claude Code session…, New Codex session…, New Copilot CLI session… and New Antigravity session… on any open task, and on an epic (finished ones too), for each CLI provider that is added, on, and found by GET /api/providers: the path set for it in Settings → Agents → Providers, else the name on PATH. The dialog (SessionLaunchDialog) reads GET /api/tasks/:id/session-launch-options (CLIs, the project folder, its branches and default branch, each CLI's model for the task's model, which model that is and what picked it (a label's custom model, else the tier: resolveTaskModel), and whether sessions get a named window) and offers:

  • the hand-off prompt, editable, with Plan with me swapping the work and planning prompts. It is the prompt with linkedSession and sessionHarness: the agent is told the board linked the session (startedSessionLine), or, for Codex and Antigravity, to link it itself (selfLinkLine: link(agentSession: {harness: "codex", sessionId: $CODEX_THREAD_ID, cwd}, label), or "antigravity" and $ANTIGRAVITY_CONVERSATION_ID, with the label the board would have given it), and has no suggested-model line. An epic's is the orchestrating prompt (mode orchestrate, session label "Orchestrating #N") with no Plan with me, and the server refuses a mode that doesn't fit the task (handoffModeError);
  • a model, filled in from Settings → Agents → Models (the custom model's or the tier's cli[harness]) for a work prompt; Default model, and planning, use the CLI's default. It is the shared model picker locked to the CLI (CliModelPicker in components/models/, with defaultLabel), listing the models the CLI's scan found (GET /api/agent-models) with the effort beside them; a name it doesn't list can be typed. Model names are CliModel: letters, digits and . : @ / [ ] -;
  • an effort next to it (--effort for Claude Code and Antigravity, -c model_reasoning_effort=<level> for Codex, --reasoning-effort for Copilot CLI; CliEffortMenu), filled in from the same model's cliEffort[harness] (options.efforts) and followed by the plan toggle like the model. It offers the levels the scan lists for the model, else the CLI's own (CLI_EFFORTS), or "Default effort", which passes no flag; a model that takes no effort hides it, and picking a model that doesn't take the chosen level resets it to the default. The planning dialog has the same two pickers, starting on the CLI's default;
  • images, pasted or dropped into the prompt or picked with the image button (up to 10). A CLI can't take an image on its command line, so the server gives them to the task and adds [Attached image "<name>" is saved at: <path>] lines (T3 Code's wording) to the prompt and to the short prompt; Claude Code opens the file with Read. A planning session's images stay unclaimed, in the pending folder (see attachments.md);
  • New worktree from a branch, Task worktree, or This checkout. (A fix from a PR's Fix in → has none of these: it runs in a new worktree on the PR's own branch, below.) The branch starts on the task's integration branch when its epic delivers through one (origin's copy first, as the T3 dialog does), else origin's copy of the default branch (the local one when origin has none), as Autopilot's worktrees start from it. The branch picker is the T3 dialog's, with the task's own branches pinned above the full list (agent-handoff.md). Task worktree shows when one of the task's branches is checked out in a worktree of the project, and runs the session in that worktree with no new branch (existing_worktree); picking a pinned branch with a worktree selects it too, and a pinned branch without one is a base for a new worktree.

It loads like the T3 dialog (see agent-handoff.md): the prompt can be edited at once while the model, effort and workspace controls show skeletons; the choices follow a refresh of the options until the user picks one; opening the hand-off menu or Fix in → prefetches the options and the model scan, and the options stay cached for 30 seconds. A fix waits for its prompt (the PR's problems) before the composer shows. The server runs the options' three git calls (rev-parse, for-each-ref, the default branch) side by side.

POST /api/tasks/:id/sessions then:

  1. for a new worktree, runs createWorktree under <worktreesDir>/sessions on a new <brand>/<task#>-<id8> branch. Autopilot's cleanup never removes these: they are the user's. For a task worktree it makes nothing, after checking with git worktree list that the folder is a live worktree of the project (not its own checkout) with that branch checked out (findWorktree), since the path comes from the browser;

  2. builds claude [--model m] [--effort e] --session-id <uuid> --name "Implementing #N" -- <prompt> (-- so a prompt starting with - isn't read as an option), or Copilot's copilot [--model m] [--reasoning-effort e] --session-id <uuid> --name … -i <prompt>, with a session id the board picks, or Codex's codex [--model m] [-c model_reasoning_effort=e] -- <prompt>, which takes neither an id nor a name, or Antigravity's agy [--model m] [--effort e] -i=<prompt>, which takes neither either. agy's parser reads -i --continue (or -i "- item") as a flag, so the prompt is fused to -i= (agy 1.5.19's own advice);

  3. opens it in the terminal setting's terminal. With Windows Terminal it goes to the window named for the task (taskWindowName, <brand>-<task#>): wt -w <brand>-115 new-tab … opens the window, or a tab of it when it is already open, whatever Open in says;

  4. links the session (label "Implementing #N", "Planning #N" or, for an epic, "Orchestrating #N", plus the window once the terminal has started), then reads its status. When the terminal won't start the result carries the command to run by hand; the session is linked all the same, since that command has its id and its prompt says the board linked it.

    A Codex or Antigravity session isn't linked here (linkId is null): the board has no id for it. Its prompt, short prompt and the fix prompt (GET /api/links/:id/fix?harness=codex) tell it to link itself with $CODEX_THREAD_ID (or $ANTIGRAVITY_CONVERSATION_ID), under the same label, and the dialog and the toast say so. The launcher doesn't try to find the id afterwards: Codex's rollout files would have to be matched by folder and time, which two sessions in one folder would get wrong, and the agent's own link is the one the other harnesses rely on too. So a Codex session shows on the card once its agent has linked it, and has no named window to bring back (only the board records one).

A lane's Plan tasks… starts a session that plans several tasks (POST /api/projects/:id/plan-session, agent-handoff.md). It always runs in the project's checkout, starts on the CLI's default model unless one is typed, opens in the window named for the first task, and links the one session to every task, labelled "Planning #3, #4, #7". Its short prompt asks the agent for get_handoff_prompt(tasks: […], mode: "plan").

The prompt is one argument (textArgument in terminal.ts). POSIX shells get it as written, single-quoted. On Windows it crosses Windows Terminal, which quotes an argument with spaces but not the quotes inside it, and often cmd.exe, which has no escape inside quotes and expands %NAME% even there; so line breaks become spaces, " becomes ', a trailing backslash gets a space after it, the text always has a space, and a % is refused. A refused prompt, or a command line over 8,000 characters on Windows, starts the session with a short prompt built from the task alone ("Let's work on #N…: call get_task(…) first"); the result says why (shortReason) and the web app copies the full prompt to the clipboard. These argvs were run for real through cmd, Windows PowerShell 5.1 and a custom cmd template, and the CLI received the prompt unchanged. A Windows Terminal launch couldn't be run from the agent's session that built this; it relies on the same quoting the resume command's bash -c script does.

The window name is stored beside the session's ref in ref_json and returned as the link's window. Only the board sets it (AddLinkOptions, links.setWindow); an agent linking the same session again, from another folder, keeps it. Open in terminal resumes such a session into its window again, so the window keeps holding it; resumed in a terminal with no named windows (the setting changed), the link forgets the window. A fork is a new session and opens where the setting says. Bringing the window back shows its first tab: Windows Terminal can't focus a tab by what runs in it, so with several sessions in the window the one asked for may be on another tab.

Fixing a PR. workspace: {mode: "pr_branch", branch} with mode: "fix" is Fix in → on a PR link (GitHub PRs). The server refuses a branch that isn't the head of an open or draft PR of the task (not from a fork, and, when origin's URL names a repository, in that repository: remoteRepo); then createWorktree is given branch instead of baseRef, which makes a new local <brand>/<task#>-<id8> branch at origin's copy of the PR's branch that tracks nothing, and refuses the default branch (the prompt tells the agent to push with git push origin HEAD:<branch>). The session is labelled "Fixing the PR of #N" (sessionLabel), and the short prompt (shortPrompt) names the branch and repeats the safety rules.

A custom hand-off starts a session the same way, from its dialog or without it. Its session is labelled " on #N" (StartSessionInput.label, which replaces the mode's label). When its prompt can't go on the command line the CLI gets a short pointer of its own (handoffShortPrompt), not the mode's "Let's work on #N": it names the hand-off, has the agent read the task and wait, and says to start nothing until the prompt is pasted, since a hand-off may ask for anything but working the task. The full prompt is copied for pasting, as for any session. A session that links itself (Codex) does so under the hand-off's name there too.

The terminal setting is resolved first, so one that can't run here is refused (400) before any worktree is made. A worktree made for a session whose terminal then didn't start stays, since the returned command runs in it, and the dialog closes so starting again doesn't quietly make a second one.

On a machine

A session whose link names a connected machine, and every new session of a task a machine holds, runs on that machine. The terminal here runs ssh -t to it, and tmux there holds the session, so it keeps going when the terminal closes or this machine sleeps; opening it again attaches to it (integrations/remoteTerminal.ts).

  • The way in is the machine's SSH route (ssh <target>, with its port), else, for a machine reached over Tailscale only, ssh to its tailnet address or *.ts.net name with the user's ssh config choosing the user. A machine with neither is refused: "There's no SSH route to engine…".
  • Known before. The hand-off menu and the launch options don't offer a session of a CLI the machine's checks say can't open there (no SSH route, an ssh login that asks for a password, no tmux, the CLI missing), with the reason and a link to the machine's card; what isn't known for sure offers it as before (ready for).
  • Asked first. A BatchMode ssh (no prompts, 20 seconds) runs the machine check script (integrations/machines/checkScript.ts, the same the runner runs for the card) there: is tmux there, the folder, the CLI on a login shell's PATH (with ~/.local/bin, ~/bin, ~/.npm-global/bin, /opt/homebrew/bin and /usr/local/bin added), and is the session's tmux session open. A missing tmux names the install command for the machine's package manager. Each missing piece is a sentence with what to do, offering a T3 Code thread on the machine instead (details: {t3: "offer", machineId}, MachineT3Offer, which "no SSH route" carries too); ssh's own failure goes through sshFailure. Nothing is made on the machine before this passes.
  • The offer. The web's error toasts for starting a session ("Couldn't start the session", SessionLaunchDialog) and opening one ("Couldn't open the session", useSessionActions) read it through useT3OfferToast (t3OfferAction in components/sessions/t3Offer.logic.ts): when that machine's T3 Code is connected, Start a T3 Code thread there opens the T3 launch dialog, which sends a held task's thread to the machine; in any other state, read-only included, Connect T3 Code on opens Settings → Machines at that machine's T3 part (remote machines). There is no action once that machine no longer holds the task: a session's link outlives the hold, and a thread for a task the board holds would start in the board's own T3 Code.
  • The command is ssh -t [-p <port>] -- <target> sh -lc '<script>'. The script puts those folders on PATH, checks tmux, falls back to TERM=xterm-256color when the machine has no terminfo for the terminal here (kitty, Ghostty), cds to the folder, ends the tmux session if its CLI has exited, and runs exec tmux new-session -A -s <name> -c <folder> sh -c '<cli …>; tmux set-option -q @ended 1; exec $SHELL -l': -A attaches when the tmux session exists, and a shell takes over when the CLI exits, so its last words stay readable; @ended marks that, so opening it again runs the CLI rather than showing that shell. The script is quoted so that the login shell there reads it the same whether it is a POSIX shell or fish (loginShellQuote), and has no double quote, which cmd.exe on a Windows board couldn't carry. Checked through sh, bash, fish and zsh.
  • The tmux session's name is <brand>-<12 hex of an id>: the session's id, or for one that picks its own id (Codex) the launch's. The machine records it on the link (ref.tmux, which only a runner sets): on the link it makes for a board-started session, and, for one that links itself, on that link (terminalFor in runnerInteractive.ts). Resume uses it, else the name from the session's id.
  • A session that links itself is found by a launch token: the board makes one per terminal (LaunchToken), sends it with POST /machine/sessions (launch), and puts it in the prompt's link call (selfLinkLine, or withLaunchToken in a prompt the user rewrote). The link tool takes it as agentSession.launch, and the machine gives the link that terminal: once, and only for the same task and CLI. A machine without the launchTokens capability is sent none. A link with no token is matched only as a marked fallback: exactly one terminal waiting for that CLI and folder, opened in the last 10 minutes, for a session id the machine has no link for yet (so a session linking itself again can't take a new one's terminal). Otherwise the link names no terminal, and opening it resumes the session by its id.
  • The prompt goes through tmux, whose client refuses a command over 16 KB, so a script over 14,000 characters (REMOTE_SCRIPT_MAX) starts the session with the short prompt, as an over-long command line here does ("The prompt is too long for tmux on the machine.").
  • Resume attaches when the CLI still runs in the tmux session, without the 409; a session running outside tmux (a headless run, or one started on the machine) gets the 409 as here. Fork gets a tmux session of its own: where the CLI can fork into an id it is given (forkIntoArgs in AGENT_HARNESSES: Claude Code's --resume <id> --fork-session --session-id <new>), the board picks the id and names the tmux session from it, which is the name opening the fork's own link falls back to, so nothing is recorded; another CLI's fork gets a random name. Copy resume command gives the ssh command. Headless runs' sessions work the same: their folder is the run's worktree on the machine.
  • A new session (startOnMachine in sessionLaunch.ts): after the check, POST /machine/sessions has the machine make a worktree under its data dir from origin's copy of the chosen base, or use its checkout, and link the session to its copy of the task with the machine named; the link reaches the board through the change log, and the answer carries its id. The dialog says where it runs (options.machine), lists every CLI (the machine's is the one checked) and no task worktrees, and has no image button: the CLI there can't open a path of this machine. A pasted image, a task worktree or a PR's branch is refused.
  • MCP. A machine set up only as a runner may have no registration for its own MCP server, so the CLI is given it on the command line, as headless runs there are: Claude Code's --mcp-config and Codex's -c mcp_servers.<id>.url, at http://127.0.0.1:<runner port>/mcp (the port from the SSH route's remotePort, else the direct route's). The value is decoded from base64 on the machine, so no double quote crosses the shells. Copilot CLI relies on the user's config there.
  • The CLI that runs is the machine's own; the path set in Settings is this machine's.

Not done: bringing back a named Windows Terminal window for a session on a machine (attaching does the same), images, and finding again the fork of a CLI that can't be given its id. tmux itself was not run in the tests: the scripts run against a stand-in tmux that answers as one would.

Names

A session's name is, in order:

  1. the link's label: what the agent said it does, or what Autopilot called the run (runners);
  2. the title Claude Code keeps for the session, read by the status reader and stored on the snapshot as title: the live session file's name (<claudeDir>/sessions/<pid>.json) unless its nameSource is derived (Claude's own guess from the folder and branch), else the transcript's newest custom-title (a name the session was given: --name, /rename), else its newest ai-title (what Claude wrote after the first exchange). The transcript is <claudeDir>/projects/<folder>/<id>.jsonl, found by the session's folder (claudeProjectSlug) or else by looking in every project folder, and only its start and end are read (integrations/claudeSessionTitle.ts). A transcript is read again only when its size or time changed. Never an LLM call; Copilot CLI has no title;
  3. nothing: the web shows "Claude Code session in ".

claudeDir is $CLAUDE_CONFIG_DIR, else ~/.claude. Neither file format is documented, so a title that can't be read is left out rather than guessed.

Transcripts

get_session_transcript(task, session?, offset?) lets an agent audit how a task's Claude Code session went: what it was asked, what it concluded, what it ran and where it went wrong. Only a session linked to the task can be read, found by the link's id and folder as the title is (transcriptPath), never by a path the agent gives. Without session the newest linked session is read and the header names the others; session picks another. T3 Code threads and Copilot CLI sessions aren't covered.

The transcript is condensed to one line per event (condenseTranscriptFile): each user message, the assistant's final text of each turn, each tool call with its name and target (file, command, pattern), tool errors, permission denials, retries and interruptions. A slash command is logged as [command] and a compaction summary as [compacted], neither counted as a turn, and a command's output is left out. Stopping Claude while a tool waits rejects the tool too: that is logged as the interruption, not also as a denial. A header gives the turn, tool call, error and retry counts, the duration and the start and end times (renderTranscript in format.ts). Long text is cut, and entries are paged at 20,000 characters (PAGE_CHARS); a page names the offset of the next entry, and an offset past the end says so with the number of entries. Each page reads and condenses the file again, with no cache: a transcript is read a few times while it is audited, and a live session's grows between pages.

Every line is redacted (redact): API keys, bearer tokens, PEM and PGP key blocks, values whose name holds a secret word anywhere in it (PGPASSWORD=…, AWS_SECRET_ACCESS_KEY=…, an Authorization header with any scheme), quoted values with spaces in full, flags named for a secret and their value (--password …), the password after curl's -u, passwords in URLs, pairing codes and long runs of random mixed-case letters and digits, standard base64 included, become [redacted]. Code beside a secret name is kept: a type, a call, another name, a number or a path (password: string, PWD=/home/dev), and so are long runs made of words (an identifier with a digit, a Claude project folder). A camelCase or dotted word is kept only beside a name written as code: after a flag, a name in capitals (API_TOKEN=…) or a shell assignment with no spaces (token=…) it is redacted, since a short passphrase looks the same. Text is first cut to four times its limit, so a huge tool output isn't scanned whole, then redacted, then cut to the limit; a secret the first cut splits is the last run of non-space characters, which is dropped, or only its last 200 characters when that run is longer (a minified line). The session's label is redacted in the header and in error messages too. A transcript holds whatever the agent read, and the LLM gateway some users sit behind kills a session whose messages contain a credential-shaped string.

A session that ran on a connected machine is read on that machine: the board picks the session as above and asks the machine for the page (POST /machine/transcript, by session id and folder), also after the task was taken back. A machine the board is no longer connected to, or can't reach, is an error saying so.

On the card and in the panel

A card shows each session as a chip with the harness's mark and a status dot; its menu opens, forks or copies the command. Open and fork are left out (and the panel row's click is disabled) when GET /api/providers doesn't find that harness's CLI; the copy commands stay. Resuming or forking runs the CLI path set in Settings, as a new session does, and the copied command carries it too. A task with a T3 thread shows no session chips, since the thread runs a Claude session underneath and would show twice. The task panel lists every session by name, with its folder (secondary) and status, in the panel's Sessions section (board-layout); a chip's tooltip shows the name.

Copilot CLI support is unit-tested only.

The tokens a linked session used are read from its transcript into the panel's Usage section and the stats page: see token-usage.md.

Decisions

  • Status from the harness's files, not from the agent. The agent can't report that it has exited; the files and the pid can.
  • One poll for everything, only while someone is watching. As for T3 threads, the timer does nothing without a connected browser.
  • 409 rather than a client-side check. The server reads the status itself just before launching, so a stale card can't reopen a running session silently.
  • Launch from the server. The browser can't start processes, and the desktop app uses the same route, so there is one path to test.

Alternatives considered

Option Why not chosen
A claude:// style URL handler Neither CLI registers one, and it would need installing per machine
Reading the transcript files for status (it is read for the title and for get_session_transcript only) Larger and slower than the running-session files, with no pid to check
Focusing a window that already shows any session No reliable way across terminals; only a Windows Terminal window the board named can be found again
Writing the prompt to a file for the session to read Neither CLI takes a first prompt from a file, and a pointer prompt reads worse than the prompt itself

Choosing a CLI's model

Settings → Agents → Models picks each tier's (and each custom model's) CLI model from a list the CLI itself gives, so a model isn't typed from memory. Each cell is the shared model picker (board-layout.md) locked to the CLI: a button with the CLI's mark, the model's name and its effort opens a searchable list of the models, each with its name, its value and what the CLI says about it, and the effort column beside it. Search text the list doesn't have can be used as typed (claude-opus-5-5, sonnet[1m]; checked as a CliModel). A saved model the scan doesn't list still shows. Beside the cell is a button that clears the model, which means the CLI's default. A model is saved as soon as it is picked.

GET /api/agent-models (integrations/agentModels.ts) asks each CLI, and only where a picker needs it, once a CLI's cell or tab is shown (useAgentModels); GET /api/providers reuses the same cache for its model counts (for the providers added and on, PROVIDERS[id].scansModels):

  • Claude Code: claude -p --input-format stream-json --output-format stream-json --verbose is given one initialize control request on stdin, then stdin closes. The CLI answers with models[] (value, displayName, description, supportedEffortLevels) and exits. No prompt is sent, so it costs no tokens; its SessionStart hooks do run, which is most of the few seconds a scan takes. The default entry is left out, as an empty field already means it.
  • Copilot CLI: the model list in copilot help config. It names no models and no per-model efforts, so every model offers the CLI's --reasoning-effort levels.
  • Antigravity: agy models, one id<TAB>label line per model (parseAntigravityModels); no per-model efforts, so every model offers agy --effort's levels. agy is a PyInstaller bundle that unpacks a whole runtime each time it starts, so its list and its --version are kept until the binary changes (path and modified time) or a Re-check or Rescan asks again, rather than for the usual ten minutes and one minute.
  • Codex: codex app-server, the JSON-RPC server Codex's own clients and T3 Code list models with (integrations/codexAppServer.ts). One JSON message per line: initialize (as the board), the initialized notification, then model/list, following nextCursor (at most 20 pages). Each entry's model is the --model value, with displayName, description, supportedReasoningEfforts (levels the board doesn't know are dropped), defaultReasoningEffort (stored as defaultEffort) and isDefault, the model Codex runs when given none; hidden models are left out, as Codex's picker leaves them out. The server doesn't exit once it has answered, and on codex-cli 0.166.0 it exits at the end of stdin before answering a request still queued, so stdin stays open until the last page is in and the process tree is then ended, as it is after 20 seconds without an answer. It takes about 0.4 seconds and sends no prompt. The pickers name the default model on their Default model row ("unless Codex is set to another": Codex's config.toml can pick another) and the default level on the effort column's Default. Tested on a recorded reply (fixtures/codex/model-list.json) and against a stand-in server, so the tests don't need Codex.

Each harness's answer is kept for ten minutes, by the CLI path it came from (a changed path rescans); a scan that failed isn't kept. ?refresh=1, the Rescan models button, rescans, and joins a scan already running. A CLI that is missing, fails, times out or prints something unexpected gives an empty list and an error, shown under the tiers; the fields still take typed models.

An effort (cliEffort[harness], optional and additive on a tier and on a custom model, so older settings parse as they were) goes with the model: its select shows only once a model is set, and offers that model's scanned levels, else the CLI's own. Clearing the model clears its effort, and so does choosing a model that doesn't take it; the server also drops an effort for a harness with no model. The effort goes everywhere the model does:

  • a new session (newSessionArgv; the dialog prefills it);
  • headless runs that resolve to a tier or custom model (resolveOperationModel returns it with the model): Autopilot's headless agent, the board reviewer, the issue import and Ask. A T3 model standing in for a CLI model carries none; a typed model carries its own.

Code map

File What it does
packages/contracts/src/agentSessions.ts AgentSessionRef, snapshot, AGENT_HARNESSES and resume commands, startedSessionLine / selfLinkLine, TerminalSetting, REST shapes
apps/server/src/integrations/agentSessions.ts The status reader, process probe, poller (and the run-based state of Autopilot sessions), resume and terminal info
apps/server/src/integrations/remoteTerminal.ts A session on a machine: the ssh route, the tmux script and its quoting, the preflight, the runner's MCP on the command line (tested)
apps/server/src/integrations/terminal.ts Quoting (and textArgument for free text), Windows Terminal detection, the launch for each terminal and shell, named windows, spawning
packages/contracts/src/sessionLaunch.ts CliModel, launch options and input, newSessionArgv, taskWindowName, sessionLabel
packages/contracts/src/agentModels.ts, modelTiers.ts The scan's shape (AgentModels); CliEffort, CLI_EFFORTS and cliEffort on a tier
apps/server/src/integrations/agentModels.ts The model scans, their parsers and the cache (tested on recorded output)
apps/server/src/integrations/codexAppServer.ts Codex's model/list over codex app-server (tested against a stand-in server)
apps/server/src/integrations/sessionLaunch.ts The launch options, starting and linking a session (start, and startPlanning for several tasks)
packages/contracts/src/providers.ts ProviderId, PROVIDERS, the providers setting, ProvidersStatus, harnessCliSetting, providerActive
apps/server/src/integrations/providers.ts GET /api/providers: CLI, MCP, T3 and models checks, their cache, and the seed from detection (tested)
apps/server/src/integrations/t3AntigravityLinks.ts Stray files at T3 Code's Antigravity skill links, and their repair (tested)
apps/server/src/db/codeMigrations.ts 040_providers_settings: seeds the list and moves the CLI paths (tested in database.test.ts)
apps/web/src/components/settings/agents/ProvidersSection.tsx, ProviderEditors.tsx Settings → Agents → Providers: the list, the Add provider dialog and each provider's editor (providers.logic.ts is tested)
apps/web/src/components/models/ The shared model picker of the Models page, the new-session and planning dialogs and every other model control (*.logic.ts tested)
apps/server/src/db/migrations/015_agent_session_links.sql Adds the agent_session link kind
apps/server/src/http/routes/system.ts /api/links/:id/resume, /api/links/:id/resume-command, /api/terminal, /api/providers, /api/agent-models
apps/server/src/http/routes/tasks.ts /api/tasks/:id/session-launch-options, /api/tasks/:id/sessions
apps/server/src/http/routes/projects.ts /api/projects/:id/plan-session and /api/projects/:id/plan-thread
apps/server/src/mcp/tools/links.ts link with agentSession
apps/server/src/integrations/claudeTranscript.ts Condensing a Claude Code transcript, redaction, paging (tested)
apps/server/src/integrations/sessionTranscript.ts Choosing the linked session and finding its transcript (tested)
apps/server/src/mcp/tools/transcripts.ts get_session_transcript
apps/web/src/components/sessions/ Status and warning copy, the warning dialog, shared menu items, useSessionActions
apps/web/src/components/handoff/SessionLaunchDialog.tsx The new-session dialog (sessionLaunch.logic.ts)
apps/web/src/components/settings/TerminalSection.tsx Settings → Integrations → Terminal