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.
| Command | What it does | More |
|---|---|---|
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 dashboard | Opens a Dashboard tab. | Dashboard |
cs search QUERY | Searches, browses and traverses the workspace. | Search |
cs export PATH | Renders a workspace file to PDF. | Export |
cs terminal | Opens, writes to, reads, restarts and closes terminals; reports program status; asks a question; starts a team. | Below |
cs pane | Lists and changes the window's panes. | Below |
cs window | list 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 session | Lists and detaches the clients viewing this server; hands over session leadership. | Collaboration |
cs copy, cs paste | Pipe into and out of the clipboard of the machine viewing the window. | Copy and paste |
cs upload DIR, cs download PATH | Upload into a directory through a picker; download a file, or a directory as a tar. | Transfers |
cs tunnel SPEC | Forwards ports on the desktop's machine to ports on this one. | Tunnels |
cs dump-skill | Prints 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.
| Needs | Commands |
|---|---|
| Any chan terminal | terminal (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 files | open of a path, terminal new PATH |
| A workspace | graph, 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 --title | window new, open and hide |
| A devserver viewed in Chan Desktop | tunnel |
| Nothing: any terminal, over ssh too | terminal status, dump-skill |
| Variable | Holds |
|---|---|
CHAN | 1 in every chan terminal. |
CHAN_CONTROL_SOCKET | The server cs talks to. |
CHAN_WINDOW_ID | The window cs acts on. --window overrides it for the commands that open a tab and for cs pane. |
CHAN_TAB_NAME, CHAN_TAB_GROUP | This terminal's name, when it has one, and its group, default unless set. |
CHAN_SESSION_ID | This terminal, kept across a restart. |
CHAN_WORKSPACE_PATH, CHAN_WORKSPACE_NAME | The 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,
cssays the chan window or server that spawned this terminal is no longer running. - When a devserver comes back on another socket,
cslooks 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 statusandcs dump-skillwork, wherecsis installed. - A workspace command in a standalone terminal refuses with this is a standalone terminal.
cs window rmdeletes 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.hidekeeps a window to reopen.- For a standalone terminal,
cs window newrequests focus for the new window once the desktop has built it. The operating system decides whether to grant focus. cs window listis empty under a standalonechan serve, which keeps no windows.sematches both search and session, andtboth terminal and tunnel, so neither is accepted as a prefix.-v,-vvand-vvvraise 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.
-
Open a named terminal
$cs terminal new --tab-name buildThe tab opens in the window's active pane, which is the one you typed in. To open it beside you, pass
--panea pane id, as in cs pane. -
Run a command in it
No newline is added, so end with
\nto run the command.$cs terminal write --tab-name build $'make test\n' -
Read what it printed
$cs terminal scrollback --tab-name build | tail -20
| Command | Example | What it does |
|---|---|---|
new | cs terminal new src --tab-name build --tab-group ci | Opens 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. |
write | cs 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. |
list | cs terminal list --json | jq -r '.groups.ci[].name' | Lists live terminals by group, with window, pane, agent, program status, queue and directory. |
scrollback | cs terminal scrollback --tab-name build > build.log | Prints one terminal's recent output, escape sequences included. |
restart | cs terminal restart --tab-name build | Starts the terminal again with the same name, group and window. --command and --env change what runs. |
close | cs terminal close --tab-group ci | Ends the terminals and frees their names. |
survey | cs 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. |
status | cs terminal status done --msg "Tests passed" | Reports program status. See Program status. |
team | cs terminal team load teams/review | Starts a team of agents. See Agent teams. |
Details and limits
write,restartandcloseneed--tab-nameor--tab-group, so a forgotten filter cannot reach every terminal.scrollbacktakes a name that matches exactly one terminal.- Matching nothing is an error: no live terminal session matched.
- Names need not be unique.
write,restartandclosereach every terminal with the name. writerefuses 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,museoropencodeterminal reach it together, oldest first, as one turn.geminitakes them one per turn, and each costs two queue entries. --submitsends the submit key of the agent you name:agy,claude,codex,gemini,kimi,museoropencode. One agent per command, so write to a group of mixed agents one terminal at a time.cs terminal listshows each terminal's agent.- Submit templates can be overridden on the server with
CHAN_SUBMIT_<AGENT>orsubmit.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. restartandcloseask no confirmation.closehangs 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
nohupjob, keeps running afterclose. scrollbackkeeps 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.newqueues the tab and returns; the tab appears a moment later.--paneand--sideplace it, and--env KEY=VALUEadds to its environment.surveytakes up to four--optionvalues 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"| Report | In the tab | In Details |
|---|---|---|
working | The 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. |
blocked | An 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. |
done | A green check while unseen. | Done, seen or not. |
error | A red exclamation mark while unseen. | Error, seen or not. |
idle | No mark. | Idle. |
clear | The cleared records' marks go. | The cleared records go. |
Details and limits
--kindapplies toblockedonly, and--progress, a whole number from 0 to 100, toworkingandblocked.- 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.
--idgives a subprocess a record of its own instead of replacing its parent's.clear --id buildremoves that record and its children;clearwith no--idremoves them all. doneanderrorstay until replaced or cleared.working,blockedandidleend with the program that held the terminal when the report arrived, or at the shell's next prompt.--sleep Nwrites 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,
cssends it through chan instead. - A title holds up to 192 bytes and a message up to 2048.
cs terminal list --jsoncarries every record and its text, marked or not.- chan marks a terminal the same way while a
cs terminal survey,cs exportorcs tunnelstarted 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.
| Command | What it does |
|---|---|
cs pane list | Lists 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 dashboardandcs terminal teamtake the same--window,--paneand--side.- Pane ids look like
pane-4and hold only while the window is open. Read them fromcs 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,
newopens 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-nameheld 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.
| Exit | Meaning |
|---|---|
0 | Done, or queued to a live window. A queued tab or message arrives a moment later. |
1 | Failed: refused, nothing matched, or a close blocked by unsaved work. |
124 | Nothing 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. |
69 | Only from an older devserver, which could refuse a --submit. The text was still queued. |