Skip to content

References Scripting reference

This is the compact reference for Scripting and automation. It names the public surface a human script or LLM can quote exactly.

CLI verbs

The paneflow binary intercepts these verbs and exits before GUI startup. Unknown verbs exit with usage code 2 instead of silently launching the app.

VerbPrimary method or engineWrites to panes?Use
ls [--human] [--raw]surface.listNoList panes in the active workspace, fenced when printed to a program
read <target> [--raw]surface.readNoRead pane scrollback, fenced unless --raw
search <target> <pattern> [--raw]surface.searchNoSearch pane scrollback, fenced unless --raw
ps [--json]fleet.listNoList detected agents across workspaces
status <target> [--json]surface.statusNoRead one pane's agent state
new [--name] [--cwd] [--space]workspace.createNoCreate a workspace, in the active space unless --space names another
select <index>workspace.selectNoSelect a workspace, switching to its space
split <h|v>surface.splitNoSplit a pane
focus <target>surface.focusNoFocus a pane and its workspace
send <target> <text>surface.send_textGatedStage or submit text
key <target> <keystroke>surface.send_keystrokeGatedSend one non-submitting keystroke
wait --match <sel>surface.read, events.subscribeNoBlock until a pattern or idle, whichever comes first
watch [--surface <sel>] [--type <event>]events.subscribeNoStream lifecycle and surface events
up <file>Workspace spec enginePrefill onlyCreate a declarative workspace
flow run <file>Flow engineGated for submitting stepsRun a local multi-agent DAG
sessions [--json] [--follow]Worker session streamNoRead agent session state, with or without a window
write <target> <text> [--submit]pane.writeAfter a human allows the pairMessage another agent's pane
ask <question> [--option <text>]...prompt.request, prompt.waitNoAsk the user in the window and print the answer
do <script|action> [key=value]...Lua runtime, action.invokeWhen the script writesRun Lua or an init.lua action
actions [--json]action.listNoList the init.lua actions
api list|describe|callMethod registryWhen the method writesList, describe, or call any JSON-RPC method

From a pane, ls, read, search, and write stay in that pane's workspace; --scope all reaches every workspace once ipc.orchestration is true in paneflow.json.

Aliases accepted by the CLI: list_panes maps to ls, read_pane maps to read, and search_pane maps to search.

Selectors

SelectorExampleNotes
Numeric idpaneflow read 42Matches surface_id exactly
Namepaneflow status backendBest selector for durable scripts
cmdline:<substr>paneflow read cmdline:viteFull foreground argv on Linux, executable basename on macOS and Windows
cwd:<path>paneflow read cwd:/home/me/apiMatches the pane working directory

A selector that matches nothing or several panes exits with code 3, except commands that explicitly accept multiple matches such as send --broadcast, wait --any, and wait --all.

Exit codes

CodeMeaning
0Success
1Runtime failure: instance unreachable, pane closed, gate refused, or handler error
2CLI usage error
3Target not found or ambiguous, or send refused a target agent that waits for a decision or left the foreground
4wait timeout, flow ready timeout, ask still pending <id>, or do --wait still running <run_id>

Write gates

Reading is allowed by default. Writes are split by capability:

OperationGate
send without --submitipc.scripting or ai_unrestricted
send --submitipc.scripting or ai_unrestricted
keyipc.scripting or ai_unrestricted
send --scope all, key --scope all, flow run --scope all from inside a paneipc.orchestration
Host session.input from a control clientipc.scripting
Host session.create from a control client with a command, prompt, or envipc.orchestration
Host session.create from a control client, otherwiseipc.scripting
Flow step with submit = trueScripting capability reported by system.capabilities

These keys live in paneflow.json: ipc.scripting implies ipc.orchestration, and ai_unrestricted opens both. The deprecated PANEFLOW_IPC_SCRIPTING=1 and PANEFLOW_IPC_ORCHESTRATION=1 still apply as the scripting guide describes, and a refused request still answers with its former message, which names them.

send does not append a carriage return unless --submit is present. key rejects submitting keystrokes such as enter, ctrl-m, and ctrl-j. A single surface.send_text payload is capped at 64 KiB.

Relevant config keys:

KeyDefaultMeaning
ipc.scriptingfalseOpens text and keystroke writes; implies ipc.orchestration
ipc.orchestrationfalseLets a request launch a command, a prompt, or env, and lets --scope all reach every workspace
ai_unrestrictedfalseOpens both gates for every caller
ai_injection_fencetrueWraps surface.read text in an untrusted terminal envelope
submit_paste_delay_ms70Base delay between bracketed paste and the submit carriage return
terminal.envnoneEnvironment variables injected into new terminals

Read fields

paneflow read <target> --json and raw surface.read return:

FieldMeaning
textScrollback text, fenced by default
linesReturned line count
total_linesTotal retained lines
eofWhether the read reached the oldest retained line
output_generationMonotonic counter advanced by pane output

Defaults and limits: lines defaults to 200 and clamps to 1-4000. offset starts from the end of the buffer. Passing an out-of-range offset is an invalid-params error.

The fenced JSON-RPC param defaults to ai_injection_fence. The CLI flag --raw passes fenced: false.

Agent state fields

paneflow ps --json returns {"agents":[...]}. paneflow status <target> --json returns one status object.

FieldMeaning
pidAgent process id, when known
toolAgent family such as claude, codex, opencode, or gemini
statethinking, waiting_for_input, finished, errored, idle, or unknown_running
hookedWhether the current launch reports through lifecycle hooks Paneflow installs; a hook from a previous launch never counts
state_seqPer-session counter that increases on every state transition, on status
reasonDetection reason, including no_hook
surface_idPane id
surface_namePane name
workspaceWorkspace index
active_tool_nameTool currently running inside the agent
messageWaiting prompt or permission text
last_resultLast turn summary, when available
waiting_msTime spent waiting for input
idle_msTime since observed activity
output_generationPane output counter, on status; absent when unknown

An empty fleet is {"agents":[]} with exit code 0. A pane with no tracked agent returns idle state, not an error.

Workspace spec

paneflow up <file> reads a TOML workspace spec.

Top-level fieldTypeDefaultNotes
namestring"Workspace"Workspace title
spacestringactive spaceSpace name (any case) or id; Default names the default space
layoutstring"even_h"even_h, even_v, main_vertical, or tiled
port_baseinteger3000Base for ${port_offset} allocation
[[panes]]arrayrequiredOne entry per pane
Pane fieldTypeDefaultNotes
cwdstringnoneMust exist after expansion and canonicalization
agentstringnoneAgent launcher name, mutually exclusive with command
commandstringnoneRaw command, mutually exclusive with agent
promptstringnonePrefilled into an agent input, never submitted by up
focusboolfalseGives initial focus to this pane
envtablenoneMerged over terminal.env; supports ${port_offset}
namestringnoneStable selector name
worktreestringnoneBranch name for a managed worktree under the worktrees.dir root (see the configuration schema)
fromstringHEADBranch or commit the worktree branch starts from when up creates it
copy_envbooltrueCopies the repository's .worktreeinclude entries into the worktree, or the top-level .env* files and AGENTS.override.md without that file
setupstringnoneCommand run before launch
setup_timeout_secsinteger300Setup timeout
worktree_teardownstring"auto"auto removes clean worktrees on close; keep leaves them

${port_offset} substitutes only inside env values. Unknown keys are errors. Workspace creation validates paths before creating panes.

Flow spec

paneflow flow run <file> reads a TOML flow spec and runs it against the current Paneflow instance.

FieldTypeNotes
idstringRequired, unique step id
needsarrayDependencies; on foreach, waits for all instances
foreacharrayFan-out, one instance per item
paneinline tableSpawn a pane using workspace pane fields
sendinline table{ target, text, submit? }; requires a dependency
readytable{ pattern, timeout_secs? }; regex barrier
capturetable{ var, lines }; captures 1-500 lines after ready
submitboolSubmits a spawned pane prompt; requires scripting access

Variables:

VariableScope
${item}foreach steps: cwd, name, worktree, env, send.target, ready.pattern, prompts, and texts
${var}Captured values inside send.text and submitting pane.prompt
${var.<item>}Captures from a foreach group

The runner validates unknown keys, missing dependencies, dependency cycles, invalid regexes, undefined captures, pane budget, and missing timeouts before execution. Ctrl-C stops the orchestration loop; panes that were created remain in Paneflow.

JSON-RPC connection

PropertyValue
Linux endpoint$XDG_RUNTIME_DIR/paneflow/paneflow.sock; when XDG_RUNTIME_DIR is unset or not a writable directory, $TMPDIR, else ~/.cache/run
macOS endpoint$TMPDIR/paneflow/paneflow.sock, else ~/Library/Caches/run; XDG_RUNTIME_DIR is ignored
Windows endpoint\\.\pipe\paneflow
Isolated home endpointWhen PANEFLOW_HOME names a directory other than the default home, the window of that home listens on its own endpoint: paneflow-ipc-<fingerprint>.sock in $XDG_RUNTIME_DIR (Linux only), else $TMPDIR, else /tmp, and \\.\pipe\paneflow-ipc-<fingerprint> on Windows. <fingerprint> is 16 hexadecimal digits derived from the home path. A PANEFLOW_SOCKET_PATH that names another endpoint is ignored unless PANEFLOW_ALLOW_SOCKET_OVERRIDE=1
FramingNewline-delimited JSON-RPC 2.0
Request modelOn Linux and macOS, one connection carries several requests, answered in order with one reply per request that has an id; the connection closes after 30 s without a request. On Windows, each pipe connection answers one request. events.subscribe turns its connection into the event stream, which takes no further request
Local trustSame user only; no network listener, no token, no TLS
BackpressureConnection cap and bounded event queues return structured errors or dropped frames

Probe capabilities at runtime:

printf '%s\n' '{"jsonrpc":"2.0","method":"system.capabilities","params":{},"id":1}' \
| nc -U "$PANEFLOW_SOCKET_PATH"

JSON-RPC methods

MethodParamsReturns or notes
system.ping-Liveness check
system.capabilities-{scripting, methods[]}
system.identify-{name, version, protocol}
workspace.list-Workspaces with global indexes, titles, and space: {id, name} or null for the default space
workspace.current-Shown workspace, with its space
workspace.createname?, cwd?, layout?, space?Create a workspace; space is a name (any case) or id, the active space when absent; an unknown one is refused with unknown space: <value>
workspace.selectindexSwitch workspace, and to its space when it is hidden
workspace.closeindexClose a workspace
workspace.upname, layout, panes[], space?Declarative spawn used by up and flow roots; space as for workspace.create
workspace.restore_layoutlayoutApply a layout tree
surface.list-{surfaces:[{surface_id,name,title,cwd,cmd,workspace,space}]}
surface.readsurface_id, lines?, offset?, fenced?Scrollback and output_generation
surface.searchsurface_id, pattern, max_matches?Case-insensitive substring matches
surface.renamesurface_id, nameRename or clear a pane name
surface.focussurface_idFocus pane and workspace
surface.statussurface_idAgent state for one pane
surface.send_textsurface_id, text, submit?, paste?Gated PTY text write
surface.send_keystrokesurface_id, keystrokeEnv-gated non-submitting keystroke
surface.splitdirection, surface_id?, cwd?, command?, prompt?, env?, profile?, name?, managed_worktree?, worktree?Split a pane; {split, new_tab, tab_id, direction, panes, surface_id, notices?}
tmux.compatteam, surface_id, argv, scope_session?tmux command from a Claude Code team pane; team is the token Paneflow gave that team's panes, and the reply is {stdout, stderr, exit}
fleet.list-Read-only fleet snapshot
events.subscribesurfaces?, types?Persistent newline-delimited event stream

A surface.split with worktree creates or reuses a Paneflow worktree for the new pane, which then starts in it: {branch, from?, copy_env?, setup?, setup_timeout_secs?, teardown?}, exclusive with managed_worktree. branch is created when it does not exist, from from when given, and setup needs the orchestration gate. Without cwd, the request plans from the anchor tab's bound worktree, else from the workspace folder, as a plain split does. A pane bound to another worktree than the anchor's tab opens a tab of its own: the answer then has split: false and new_tab: true, and tab_id names the tab that holds the new pane. notices lists what the worktree setup reported, such as the files copied from .worktreeinclude or a failed setup.

The ai.* lifecycle methods are no longer accepted on the app socket; lifecycle events come from the paneflow-ai-hook reporter, and events.subscribe still delivers ai.* events.

Structured failures use JSON-RPC error envelopes: -32602 invalid params, -32601 gated method, -32001 permission, and -32000 backpressure. Some legacy validation errors still arrive as {"error":"..."} inside result; clients should treat both shapes as failures.

Events

paneflow watch and raw events.subscribe emit newline-delimited JSON. The first frame acknowledges the subscription.

Event typeMeaning
subscribedSubscription acknowledged
ai.session_startAgent session starts
ai.prompt_submitPrompt is submitted
ai.tool_useAgent reports tool use
ai.notificationAgent asks for input or permission
ai.stopAgent turn stops
ai.exitAgent process exits
ai.session_endAgent session closes
surface_changedPane output_generation advanced
heartbeatIdle keepalive
droppedSubscriber lagged and events were shed

After a dropped frame, resync with paneflow ps --json or paneflow status <target> --json.

Agent verbs

Agents drive Paneflow through the CLI from their shell tool; there is no MCP server.

VerbPrintsExit
write <target> <text>written, approval_pending <request> until a human allows the pair, or no_window; --json prints the whole reply0, 0, 1
ask <question>The answer, one picked option per line, or pending <id> after --timeout (20 s by default)0, 0, 4
ask --resume <id>The answer to a question still pending0 or 4
do <action> --wait <duration>The action's result, or running <run_id> once the wait passes0 or 4
do --resume <run_id> [--wait <duration>]The result of a run still going0 or 4

write is the only agent verb that writes into a pane, and only after a human allows that pair of agent sessions in Paneflow; the automation guide describes its controls. Terminal text from read, search, and ls is fenced as <untrusted_terminal_output> when printed to a program, and an agent never passes --raw.

Lifecycle hooks

paneflow-ai-hook reads event JSON on stdin, sends one lifecycle event (ai.stop, ai.notification, and so on) to the local host, and exits 0 so a stopped Paneflow instance does not break the agent. Hooks carry the agent's identity and session metadata to ps, status, watch, and paneflow sessions; turn status comes from OSC 7501.

CommandEffect
paneflow integrations listList the runtimes that have an installer and their state
paneflow integrations install <runtime>Install the hooks, the status line, and the paneflow-conductor skill for claude-code (or claude) or codex
paneflow integrations remove <runtime>Remove Paneflow's own handlers; a handler of yours in the same hook group is kept
paneflow hooks setupInstall every detected runtime that has an installer
paneflow hooks uninstallRemove the integrations
paneflow mcp uninstallRemove the paneflow MCP entries an older Paneflow wrote, printing each one
paneflow hooks statusPrint one <runtime>: <state> line per runtime; always exits 0

Hooks are installed once per machine, from the CLI or Settings > Agents. Claude Code hooks go to $CLAUDE_CONFIG_DIR/settings.json (default ~/.claude/settings.json), Codex hooks to $CODEX_HOME/hooks.json (default ~/.codex/hooks.json), and they exit immediately outside a Paneflow pane. Other agents have no installer: they still run, are detected from their process, and get a turn status only when they report it through OSC 7501.

Worker and sessions

Agent state lives in a per-home worker, started as paneflow serve run. It runs detached, one per PANEFLOW_HOME, reduces each session's declared OSC 7501 status to one state, rebuilds that state from disk when it restarts, and never touches a running shell. status, send --submit, and wait --idle read the reduced state from the worker whether or not a window is open; paneflow sessions reads the worker directly.

CommandEffect
paneflow serve startStart the worker for this PANEFLOW_HOME, or adopt the one already serving it
paneflow serve statusPrint the pid, protocol, home, session count, and capabilities
paneflow serve stop [--drain-ms 5000]Stop the worker; terminals are untouched
paneflow sessions [--json] [--follow]Print the session list the sidebar shows; --follow prints one line per transition and reconnects when the worker restarts
paneflow sessions ack <session-id>...Lower the unread flag a finished turn raises