Skip to content

ManualTerminal

Script it with cs

Drive the window and its terminals from a shell: open files, write to and read terminals, report status, and arrange panes.

What you can do

  • Open files, terminals and panes from a script.
  • Type into other terminals by name or group, and read their output.
  • Show a program's progress, or that it needs you, on its tab.
  • Read terminals and panes as Markdown or JSON.

Commands

cs, also chan shell, drives the chan window and terminals it runs in. A prefix that names one command is enough: cs te l is cs terminal list. Add --help to any command for its flags and examples.

CommandWhat it doesMore
cs open [PATH]Opens a text file in the editor, a directory in the file browser (the current one by default), any other file selected in the file browser, or a chan://graph link.Editor
cs graph [PATH]Opens the workspace graph, focused on a path.Graph
cs dashboardOpens a Dashboard tab.Dashboard
cs search QUERYSearches, browses and traverses the workspace.Search
cs export PATHRenders a workspace file to PDF.Export
cs terminalOpens, writes to, reads, restarts and closes terminals; reports program status; asks a question; starts a team.Below
cs paneLists and changes the window's panes.Below
cs windowlist shows every window of the local machine or devserver; new opens one and prints its id once it can take commands; open ID, hide ID and rm ID show, hide or delete one.
cs sessionLists and detaches the clients viewing this server; hands over session leadership.Collaboration
cs copy, cs pastePipe into and out of the clipboard of the machine viewing the window.Copy and paste
cs upload DIR, cs download PATHUpload into a directory through a picker; download a file, or a directory as a tar.Transfers
cs tunnel SPECForwards ports on the desktop's machine to ports on this one.Tunnels
cs dump-skillPrints chan's manual for agents, offline: --list for its topics, --topic SLUG for one.

Where cs works

cs works in every chan terminal, workspace or standalone, on the desktop, in a browser or on a devserver. It acts on the window it runs in, found from variables chan sets, and reads paths from the shell's directory on the terminal's machine.

NeedsCommands
Any chan terminalterminal (but team), pane, dashboard, copy, paste, upload, download, window list and rm, session list, info, self and detach
A workspace, or a standalone terminal whose machine serves filesopen of a path, terminal new PATH
A workspacegraph, search, export, terminal team, session handover and takeover, open of a chan://graph link
The desktop's local terminal or workspace, except a chan-term window started with a command, --hold, --app-id or --titlewindow new, open and hide
A devserver viewed in Chan Desktoptunnel
Nothing: any terminal, over ssh tooterminal status, dump-skill
VariableHolds
CHAN1 in every chan terminal.
CHAN_CONTROL_SOCKETThe server cs talks to.
CHAN_WINDOW_IDThe window cs acts on. --window overrides it for the commands that open a tab and for cs pane.
CHAN_TAB_NAME, CHAN_TAB_GROUPThis terminal's name, when it has one, and its group, default unless set.
CHAN_SESSION_IDThis terminal, kept across a restart.
CHAN_WORKSPACE_PATH, CHAN_WORKSPACE_NAMEThe workspace root and its name, or $HOME with no workspace.

No variable tells a workspace from a standalone terminal; a workspace command refusing is the test:

cs search --limit 1 x >/dev/null 2>&1 && echo workspace || echo standalone

In a desktop workspace terminal, open a second window and use its id immediately:

w=$(cs window new) && cs open README.md --window "$w"

new waits up to ten seconds after the desktop creates the window record for the new window to connect. If it does not, the command prints no id on stdout and exits 124 with an error naming the window; the record remains and may connect later. A successful reply confirms the connection, not operating-system focus. A terminal served by a devserver refuses window new, open and hide even when the desktop views it.

Details and limits
  • Outside a chan terminal, a window command refuses: not running inside a chan session; this needs $CHAN_WINDOW_ID.
  • When the server that started the terminal has gone, cs says the chan window or server that spawned this terminal is no longer running.
  • When a devserver comes back on another socket, cs looks for the one devserver serving this workspace and uses it.
  • chan sets these variables; read them, do not set them.
  • In an ssh session opened from a chan terminal, only cs terminal status and cs dump-skill work, where cs is installed.
  • A workspace command in a standalone terminal refuses with this is a standalone terminal.
  • cs window rm deletes a window and its saved layout, and refuses one with running terminals unless you add --force; a devserver's window removed from a desktop terminal gets no such check. hide keeps a window to reopen.
  • For a standalone terminal, cs window new requests focus for the new window once the desktop has built it. The operating system decides whether to grant focus.
  • cs window list is empty under a standalone chan serve, which keeps no windows.
  • se matches both search and session, and t both terminal and tunnel, so neither is accepted as a prefix.
  • -v, -vv and -vvv raise logging.

cs terminal

Commands select terminals by name and group across the whole server, whichever window holds them. --tab-name matches every terminal with that name, --tab-group every terminal of the group, and both together match terminals with both.

  1. Open a named terminal

    $cs terminal new --tab-name build

    The tab opens in the window's active pane, which is the one you typed in. To open it beside you, pass --pane a pane id, as in cs pane.

  2. Run a command in it

    No newline is added, so end with \n to run the command.

    $cs terminal write --tab-name build $'make test\n'
  3. Read what it printed

    $cs terminal scrollback --tab-name build | tail -20
CommandExampleWhat it does
newcs terminal new src --tab-name build --tab-group ciOpens a terminal tab in this window's active pane, in a directory, with a name and group. --command runs a program instead of the shell.
writecs terminal write --tab-group ci $'git pull\n'Queues text for every match, delivered when each goes quiet. --submit AGENT also submits it to an agent; --stdin reads the text.
listcs terminal list --json | jq -r '.groups.ci[].name'Lists live terminals by group, with window, pane, agent, program status, queue and directory.
scrollbackcs terminal scrollback --tab-name build > build.logPrints one terminal's recent output, escape sequences included.
restartcs terminal restart --tab-name buildStarts the terminal again with the same name, group and window. --command and --env change what runs.
closecs terminal close --tab-group ciEnds the terminals and frees their names.
surveycs terminal survey --tab-name lead --option Merge --option Wait "Tests pass. Merge?"Shows the question over that terminal's window and prints the answer chosen.
statuscs terminal status done --msg "Tests passed"Reports program status. See Program status.
teamcs terminal team load teams/reviewStarts a team of agents. See Agent teams.
Details and limits
  • write, restart and close need --tab-name or --tab-group, so a forgotten filter cannot reach every terminal. scrollback takes a name that matches exactly one terminal.
  • Matching nothing is an error: no live terminal session matched.
  • Names need not be unique. write, restart and close reach every terminal with the name.
  • write refuses more than 4096 bytes rather than cutting it. Put long text in a file and send its path.
  • Each terminal queues up to 100 entries. A restart drops what is still queued.
  • Messages submitted to a busy agy, claude, codex, kimi, muse or opencode terminal reach it together, oldest first, as one turn. gemini takes them one per turn, and each costs two queue entries.
  • --submit sends the submit key of the agent you name: agy, claude, codex, gemini, kimi, muse or opencode. One agent per command, so write to a group of mixed agents one terminal at a time. cs terminal list shows each terminal's agent.
  • Submit templates can be overridden on the server with CHAN_SUBMIT_<AGENT> or submit.toml. A template that brackets the prompt replaces the control characters a terminal paste filters with spaces, while preserving tabs and line feeds. Gemini receives that framed body before a separate submit key when the template has one; every other agent receives the body and its submit key together.
  • restart and close ask no confirmation. close hangs up the terminal's program, kills it if it still runs shortly after, and fails if it outlives a 5-second wait.
  • A process that ignores the hangup or left the terminal, such as a nohup job, keeps running after close.
  • scrollback keeps a bounded tail of the output. Send it to a file or a pager, not to a live terminal, which would replay its escape sequences.
  • new queues the tab and returns; the tab appears a moment later. --pane and --side place it, and --env KEY=VALUE adds to its environment.
  • survey takes up to four --option values and waits until someone answers, picks [F] to follow up later, or dismisses it. After 600 seconds, or --timeout, it gives up and exits 124.

Program status

Programs report that they are working, blocked, done or failed with OSC 7501, the Program Status Protocol Superlogical specifies for Rex and other terminals. chan marks the tab, and Details in the tab's right-click menu lists each report. It is on by default, in Settings → Terminal → Program status (OSC 7501). From a script:

$cs terminal status working --id build --app cargo --progress 40
$cs terminal status done --id build --msg "Tests passed"
ReportIn the tabIn Details
workingThe terminal icon's prompt with a cursor being typed; with --progress, a pie in a ring that fills to the percentage.Working, with its progress.
blockedAn amber mark after the name: a shield for --kind permission, a question mark for question, a key for auth, a pause sign with no kind. It shows even while its tab is in front.Blocked, with its kind.
doneA green check while unseen.Done, seen or not.
errorA red exclamation mark while unseen.Error, seen or not.
idleNo mark.Idle.
clearThe cleared records' marks go.The cleared records go.
Details and limits
  • --kind applies to blocked only, and --progress, a whole number from 0 to 100, to working and blocked.
  • Hover a mark to read the report's state, kind, progress, app, title and message.
  • With several reports standing, the tab shows one mark: blocked over error, error over done, then the latest.
  • A done or error report is seen when it arrives while its tab is in front, or when its tab comes to the front. A seen report keeps no mark and stays in Details.
  • So a report typed at the prompt of the tab in front shows no mark. To watch one, run (sleep 5; cs terminal status done --msg Passed) & and switch to another tab within five seconds.
  • Details is also in the command launcher.
  • Each report replaces its record, optional fields included. --id gives a subprocess a record of its own instead of replacing its parent's. clear --id build removes that record and its children; clear with no --id removes them all.
  • done and error stay until replaced or cleared. working, blocked and idle end with the program that held the terminal when the report arrived, or at the shell's next prompt.
  • --sleep N writes once and waits N seconds, up to 86400, so you can look at a passing state from an interactive shell. Ctrl+C ends the wait and writes nothing more.
  • The report goes to the terminal itself, so it works over ssh in any terminal that supports OSC 7501. With output redirected and no terminal, cs sends it through chan instead.
  • A title holds up to 192 bytes and a message up to 2048.
  • cs terminal list --json carries every record and its text, marked or not.
  • chan marks a terminal the same way while a cs terminal survey, cs export or cs tunnel started there waits.

cs pane

Each pane has two sides, A and B, each a strip of tabs. cs pane changes the window it runs in, or the one given by --window or holding the --tab-name terminal. Changes show at once and survive a reload.

CommandWhat it does
cs pane listLists every pane and both its sides. Plain cs pane does the same.
cs pane new right|bottom [--pane P]Splits the active pane, or P, and prints the new pane's id.
cs pane focus P [--side a|b]Selects a pane, and one of its sides.
cs pane resize DELTA [--pane P]Grows the pane in its split by DELTA, from -1.0 to 1.0. A negative DELTA shrinks it.
cs pane equalize [--pane P]Sets the pane's nearest split to 50/50.
cs pane swap OTHER [--pane P]Swaps everything in two panes, both sides.
cs pane close [P] [--force]Closes the active pane, or P.
cs pane close-tab [--pane P] [--tab T] [--force]Closes one tab, the pane's active one by default.
cs pane close-all [--force]Closes every tab in every pane.

To put a named terminal in a new pane, keep the id new prints:

right=$(cs pane new right)
cs terminal new --pane "$right" --side a --tab-name runner
Details and limits
  • cs open, cs graph, cs dashboard and cs terminal team take the same --window, --pane and --side.
  • Pane ids look like pane-4 and hold only while the window is open. Read them from cs pane list.
  • Without --force, a close stops at unsaved files and running terminals, prints them, and exits non-zero. No dialog asks.
  • Closing the last pane clears its tabs: a window always keeps one pane.
  • In a standalone terminal window, new opens a terminal in the new pane.
  • Each call waits up to 5 seconds for the window, and fails with no reply from the window (is it open in a browser?) when it does not answer.
  • A --tab-name held in two windows is refused, not guessed.

Output and exit codes

Lists print Markdown. terminal list, pane, window list, session and search take --json, and --pretty to indent it. Results go to stdout, such as a new pane's id or a survey's answer; confirmations such as queued at position 1 go to stderr.

ExitMeaning
0Done, or queued to a live window. A queued tab or message arrives a moment later.
1Failed: refused, nothing matched, or a close blocked by unsaved work.
124Nothing answered in time: a survey, a copy or paste, a tunnel, or window new waited too long. An export or session wait that runs out exits 1.
69Only from an older devserver, which could refuse a --submit. The text was still queued.

Next