tmux
v0.2.8tmux as an iii worker — list, create, rename and kill sessions and windows and move windows between sessions, see which pane runs Claude Code or Codex (working, waiting for you, idle), which runs `iii compose` and every listening port by process and pane, plus a Console page whose terminal is a live tmux client.
Install
iii call compose::add worker=tmux@0.2.8Run in your project with the iii engine running. Exact versions are immutable and digest-pinned.
skill doc
tmux
The tmux worker drives the tmux binary on the host and reads the same tmux
server the person uses in their terminal. It reports every session, window
and pane with the foreground command, working directory and title, and adds
what tmux itself does not know: the agent CLI running in a pane (matched in
the pane's process tree) with a working / waiting / idle state read from the
pane's last lines, the iii compose daemon running in a pane with its
engine's WebSocket port and its workers' ports, and every TCP port this
user's processes listen on, each traced back to the pane that started it.
It also reads how much of their weekly and 5-hour allowance Claude Code and
Codex have used, and keeps several Claude Code accounts, each a config folder
of its own (CLAUDE_CONFIG_DIR); default is ~/.claude. The global
account is the one plain claude gets in a new tmux window (tmux's global
environment). A Claude Code pane follows the global account, is pinned to
one, or was started by hand (manual); sessions::list says which, per pane,
under claude.
Changes are tmux's own semantics. Selecting a window switches every client
attached to that session, the person's terminal included. Creating a window
makes it current unless select: false is passed. Killing a session or
window kills the programs in it. The Console page's terminal is a real tmux
client that only the Console drives.
When to Use
- A person asks which Claude Code or Codex sessions are running, which of them is busy, or which one is waiting for an answer or an approval.
- A person asks whether
iii composeis up, on which port the engine listens, or which ports the http, ade or other workers use. - A person asks what is listening on a port, or which tmux window started a server.
- A person wants a new tmux session or window, optionally running a command in a given directory, or wants one renamed, moved to another session or closed.
- A person asks how much Claude Code or Codex usage is left this week, when it resets, or which account has the most room.
- A person wants Claude Code started on a given account, a running Claude Code moved to another account, or another account made global.
Boundaries
- Read functions (
status,sessions::list,ports::list,install::status,usage::read,accounts::list) are allowed by default. Creating, renaming, selecting, moving, splitting, respawning and killing change the person's tmux and are approval-gated. Killing a session, window or pane, andpanes::respawnwithkill: true, end whatever runs there, so name what will stop before asking. Moving a session's last window closes that session, and the person's terminals attached to it end, so say so too.panes::selectis approval-gated too: a zoom shows on every client looking at that window. panes::capturereturns whatever is on a pane's screen, which can include anything the person typed or a program printed; it needs approval and its text should not be repeated beyond what the question needs.subagents::transcriptreturns a sub-agent's conversation, tool calls and their output; it needs approval for the same reason.usage::readandaccounts::listcarry each account's email and organization but never a token. Everything else underaccounts::andpanes::accountis approval-gated: a move ends Claude Code in that pane (SIGTERM) and starts it again on the other account, resuming its conversation, so name the panes that will restart;globalmoves every idle pane that follows the global account unlessmove: new_only.ruleswithmode: switchlets the worker change the global account by itself later.removewithdelete_filesdeletes that account's folder, its sign-in included.login_startgives the person a sign-in link andlogin_codetypes the code they copied from it; never sign in for them, never ask for or repeat a code, and leavebrowseratnoneunless the person sits at the worker's computer.- Starting Claude Code with
claude.skip_permissions: truelets it run commands and change or delete files without asking. Only do it when the person asks for it, and say so before asking for approval. - The worker reads Claude Code's sign-in only to ask its usage; it never refreshes, prints or returns a token.
- The worker never types into panes, except to move Claude Code started by
hand in a shell: once that shell has the terminal back, it types the
command that starts it on the other account into it (nothing otherwise).
A move only goes to a signed-in account.
tmux::terminal::*is the Console page's own terminal: it is denied to agents and cannot be observed (NOT_OBSERVABLE), since its calls carry the terminal's access key and what the person types. Itsuploadonly writes a file the person pastes to a folder of its own under their cache folder (~/.cache/iii/tmux/uploadsor~/Library/Caches/iii/tmux/uploads, kept 7 days) and answers the path; the page pastes that path, the worker types nothing. - Agent state is a reading of the screen:
waitingmeans a prompt that needs the person is visible, not that the agent's process is blocked. Patterns live in the worker configuration and can be tuned per agent. - Ports are TCP listeners of this user's processes only, and tmux locations only exist for processes started inside tmux.
- tmux is Unix-only; on a host without tmux,
statusreportsavailable: falseand the lists come back empty.installable: truethere meansinstallcan try. installputs the tmux program on the computer and can run the system's package manager as root, so it needs approval; say so before asking. It never waits for a password: without root or passwordless sudo it uses tmux's official build in~/.local/bin. It runs in the background, and it never talks to the person's tmux server. Only install tmux when the person asks.
Functions
tmux::status— whether tmux is installed, its version and path, and whether a server is running.tmux::sessions::list— every session → window → pane with command, cwd, title, size, agent state and session title, compose daemon and ports.tmux::sessions::create— start a detached session with an optional name, directory, first window name and command;remain_on_exit: truekeeps its pane, dead, once the command ends.tmux::sessions::rename/tmux::sessions::kill— rename or kill a session by id ($5) or exact name.tmux::windows::create— add a window to a session with an optional name, directory, command andselect;remain_on_exit: truekeeps its pane once the command ends.tmux::windows::select— make a window current in its session (every attached client follows).tmux::windows::rename/tmux::windows::kill— rename or kill a window by id (@3) or index.tmux::windows::move— move a window to another session (after its last window) or next to one of its windows (before/after, tmux 3.2 or later, which also reorder it inside its own session); it keeps its id and programs, and moving a session's last window closes that session (source_session_closed).tmux::panes::select— make a pane (%5) active;zoom: truezooms the window on it,zoom: falseunzooms, nozoomkeeps the window's zoom; it never toggles, and a one-pane window can't zoom (every client of that window follows).tmux::panes::split— split a panerightorbelow, in its current directory unlesscwd, with the default shell unlesscommand, active unlessselect: false;remain_on_exit: truekeeps it once its program ends.tmux::panes::kill— kill a pane and its program;window_closed/session_closedsay when that closed its window and session.tmux::panes::respawn— start a pane's program again (its own command unlesscommand); a running one needskill: true, a dead one (remain_on_exit) doesn't.tmux::panes::capture— a pane's visible screen with colour escapes, its size, cursor and alternate-screen flag.tmux::subagents::transcript— what one sub-agent of a pane's Claude Code or Codex has done (pane,subagentfromagent.subagents[].id): its task, messages, reasoning, tool calls and results, oldest first.tmux::ports::list— listening TCP ports with process, iii role, worker, compose namespace and pane, plus eachiii composestack.tmux::install— install the tmux program on this computer in the background (package manager, else tmux's official build); answers at once, and starting during a run joins it.tmux::usage::read— Claude Code's accounts with each one's 5-hour window, week and per-model weeks (used %, reset time), Codex's plan, windows and credits, the global account, the rules and any suggestion;refresh: truereads again now (at most once a minute per account).tmux::accounts::list— the Claude Code accounts (name, colour, folder, email, plan, signed in, panes running on it, usage), the global one, the rules, the suggestion and the latest switch.tmux::accounts::add/update/remove— add an account (name,color,sharedgroups linked from~/.claude), rename, recolour or change what it shares, take it off the list (delete_filesdeletes its folder; neverdefaultor the global one).tmux::accounts::login_start/login_code/login_cancel— sign an account in:login_startrunsclaude auth loginfor it in a hidden terminal and answers the link (url) the person opens;login_codetypes the code the page showed them ({state: "done", account}, orinvalid_code,rejected,expired,gone,failed);browser: hostopens the worker computer's own browser, which signs in with no code. Sign-ins under way are inaccounts::listaslogins; while one runs (until its Claude Code is gone),globalrefuses to switch the accounts it involves (signing_in) andremovekeeps the account's folder.tmux::accounts::global— make an account global;move:idle_now_working_after(default) ornew_only. Answers the panesmoved,after_turnandstayed.tmux::panes::account—globalmakes a pane follow the global account, an account id pins it; Claude Code moves there now when idle, after its turn otherwise (after_turn); the account it runs on cancels a waiting move.tmux::accounts::move_idle— move the idle Claude Code panes of accountfromtoto, pinned there.tmux::accounts::rules/tmux::accounts::dismiss— what to do when the global account runs low (off,suggest,switch; threshold, order, switch back after the reset); "Not now" on a suggestion.tmux::windows::create/tmux::sessions::createwithclaude: { account, skip_permissions }instead ofcommand— start Claude Code onglobalor an account; the answer'srunsis the exact command.tmux::install::status— where that install is:idle,runningwith its step and words,succeededwith path and version, orfailedwith one sentence and the log.
Reacting to tmux
Observe tmux::on-changed instead of polling sessions::list when something
must react to tmux: an agent that finishes a turn (working → idle), one
that starts waiting for the person, a compose stack that comes up, a session
that appears or goes away. Each observer receives the full overview
(sessions and ports, the same shapes the two list functions return) once
when it is added and then only when something changed; the worker polls tmux
only while the function is observed. It takes no args. Overviews can arrive
out of order, so keep the one with the highest sessions.generated_at_ms.
Register a handler, then observe the function with it:
iii.registerFunction('my-worker::on-tmux', async ({ output: { sessions, ports } }) => {
// compare agent states with the previous overview
})
iii.observe({ function_id: 'tmux::on-changed', capture: ['output'] }, 'my-worker::on-tmux')