Skip to content

Automate The CLI

paneflow is the command-line interface to Paneflow. It is the same binary that opens the window: run it with no arguments and the app starts, run it with a verb and it talks to the running instance, then exits.

The CLI is both an administrative tool and the base for automation. As an administrative tool, it lists panes and agents, creates workspaces, splits panes, moves the keyboard focus and types into a pane. As an automation tool, it runs Lua 5.4 scripts with paneflow do and calls every Paneflow method with paneflow api.

Paneflow sets environment variables in every terminal it opens, so the CLI already knows which instance to reach and which pane is calling it.

Open a terminal in Paneflow and try it:

paneflow ls --human     # list the panes of the workspace
paneflow ps             # list the running agents, with their state
paneflow status backend # read the agent state of the pane named "backend"

Run paneflow help for every verb, or paneflow <verb> --help for the options of one.

Taxonomy

Paneflow organizes work into five kinds of things. Most commands act on a surface.

  • A space is a group of workspaces.
  • A workspace is a group of related work, such as one project. It appears in the sidebar and holds tabs.
  • A tab holds a layout of panes, split horizontally or vertically.
  • A pane is one place in that layout. It holds one or more surfaces and shows one at a time.
  • A surface is one terminal, or one Markdown view, inside a pane. A terminal surface runs one terminal session.

Three processes serve these objects. Every one belongs to a Paneflow home, the state directory set by PANEFLOW_HOME (~/.paneflow by default):

ProcessOwns
The windowThe app you see: workspaces, tabs, panes, focus, built-in actions
The hostThe terminal sessions. paneflow host start runs it without a window
The workerAgent activity, sessions and the actions of init.lua. paneflow serve manages it

Each method belongs to one of these processes, and the CLI sends each call to its owner. When no window runs, calls meant for the window go to the host. When the worker is not running, a call meant for it starts it first.

Identifiers

A surface has a numeric surface_id, such as 30064771116. Paneflow allocates these from a counter that only moves forward. A surface can also have a name, which you choose and can change.

A workspace has a numeric workspace_id and an index, its position counting from zero. paneflow select 2 shows the third workspace. Durable identifiers for sessions, workspaces and spaces are UUIDs, as in PANEFLOW_SESSION_ID.

Command context

Inside a Paneflow terminal, the CLI finds the instance and its caller through the variables Paneflow sets:

VariableHolds
PANEFLOW_SURFACE_IDThe surface_id of the terminal's own surface
PANEFLOW_WORKSPACE_IDThe workspace_id of the workspace that holds it
PANEFLOW_WORKSPACE_UUIDThe durable id of that workspace
PANEFLOW_SESSION_IDThe id of the terminal session
PANEFLOW_SOCKET_PATHThe address of the window's IPC socket
PANEFLOW_HOST_ENDPOINTThe address of the host
PANEFLOW_HOMEThe Paneflow home
PANEFLOW_BIN_DIRThe directory of Paneflow's helper programs, see PATH

Settings in paneflow.json cannot override these variables. Outside a Paneflow terminal, the CLI uses the socket of the current home; set PANEFLOW_SOCKET_PATH to reach another instance.

Paneflow also identifies the calling process itself, from its process ancestry, and keeps a command that comes from a pane inside that pane's workspace. Reads, writes and keystrokes stay there by default. To act on another workspace, pass --scope all, which requires ipc.orchestration set to true in paneflow.json.

paneflow ls --scope all        # every workspace
paneflow read --scope all 42   # a pane of another workspace

Without a target, ls lists the panes of the caller's workspace, or of the workspace shown in the window when the call is not scoped to one. split splits the first pane of the active tab of the shown workspace; pass --target to split another one:

paneflow split v                  # side by side, from the first pane
paneflow split h --target backend # stacked, from the pane named "backend"

new creates a workspace in the active space, or in the one --space names.

Targets

Commands that act on one pane take a target: as an argument for read, search, status, send, focus and key, through --target for split, and through --match for wait. Paneflow reads a target in this order and stops at the first form that applies:

  1. cmdline:<substr> matches the panes whose foreground command contains the text, in any case.
  2. cwd:<path> matches the panes whose working directory is the path or lies under it.
  3. A whole number matches the pane with that surface_id.
  4. Anything else is a name. An exact name in any case wins; otherwise the names that start with the text match.

cmdline: matches the full command line on Linux, but only the executable name on macOS and Windows. Prefer a name or cwd: in a portable script.

paneflow read cmdline:vite --lines 50
paneflow status cwd:/home/me/api
paneflow focus 42
paneflow send backend 'cargo test'

If a target matches more than one pane, the command changes nothing, lists what matched, and exits with status 3:

paneflow: ambiguous target 'agent'; matches: 12(agent-api), 14(agent-web)

A few options accept several panes on purpose: send --broadcast writes to every match, and wait --any and wait --all watch several panes for a pattern.

Names are convenient at a prompt, but two panes can share a prefix and a name can change. In a script that has to keep working, read the surface_id from paneflow ls and use that.

Machine-Readable Output

paneflow ls prints JSON by default; pass --human for a table. Most other listing commands print a table or a line meant for reading and take --json for JSON instead: ps, status, read, search, actions, sessions and events.

$ paneflow ls
{
  "pane_count": 1,
  "workspace": 0,
  "scope_workspace_id": 3,
  "surfaces": [
    {
      "surface_id": 30064771116,
      "name": "api",
      "title": "cargo watch",
      "cwd": "/home/me/dev/api",
      "cmd": "cargo watch -x test",
      "workspace_id": 3,
      "workspace": 0,
      "scope": "workspace",
      "tab_id": 3,
      "tab_title": "api",
      "space": null
    }
  ]
}

watch streams events as JSON Lines, one object per line. paneflow do prints the value a script returns as one line of JSON, and paneflow api call prints the JSON result of a method.

When standard output is not a terminal, ls, read and search wrap what they print in an <untrusted_terminal_output> fence, because a pane's text can contain instructions meant to fool an agent. Pass --raw to print it plain.

The exit status says how a command ended:

StatusMeaning
0The command succeeded
1The command failed, including when no Paneflow instance can be reached
2The command line was invalid
3A target was not found or was ambiguous, or send refused a pane whose agent waits for a decision
4A wait timed out: wait, ask, do --wait, a flow whose panes did not get ready, or a host stop that did not finish
130wait or do was interrupted with Ctrl-C

ask exits 4 after printing pending <id>, and do --wait after printing running <run_id>; --resume with that id keeps waiting. A Lua script ends with the status it passes to paneflow.stop(n). events exits 0 on Ctrl-C.

PATH

How paneflow reaches your PATH depends on how you installed it:

PackageLocation of paneflow
.deb and .rpm/usr/bin/paneflow, already on PATH
Windows installerThe install directory, which the installer adds to the system PATH
macOS app/Applications/PaneFlow.app/Contents/MacOS/paneflow
Linux tarballpaneflow.app/bin/paneflow, in the extracted directory

On macOS, put the app's directory on PATH in your shell's startup file:

# ~/.zshrc
export PATH="/Applications/PaneFlow.app/Contents/MacOS:$PATH"

Separately, when Paneflow opens a terminal, it puts PANEFLOW_BIN_DIR at the front of PATH. That directory holds Paneflow's helper programs: the launchers that start supported agents so Paneflow can track them, paneflow-resume and paneflow-ai-hook. Paneflow's shell integration moves the directory back to the front before each prompt, so a startup file that rewrites PATH does not hide the helpers.