This page lists every method of Paneflow's API, as `paneflow api docs` prints them
in Paneflow 0.20.0. Call one with `paneflow api call <method> key=value`, from Lua
as `paneflow.<namespace>.<method>{...}`, or as JSON-RPC 2.0 on Paneflow's local
socket, one JSON message per line. See [CLI automation](/docs/scripting) for how
to use them.

Each method shows the process that serves it: `window` (the app), `worker`
(`paneflow serve`) or `host` (`paneflow host`, which owns the terminal sessions).
A method tagged `scripting` or `orchestration` needs that gate open under `ipc`
in paneflow.json, or a grant for the calling pane. A note with a rule on its left
marks where the code answers differently from what the method declares.

## action

### `action.invoke`

Run an action of init.lua with arguments and return what it returned. Arguments are checked against its schema first; a run is stopped after 30 seconds. With wait_ms, a run still going past it answers {status: running, run_id} for action.wait. With ctx.origin agent, only an action declared with agents = true runs.

Owner: worker. Gate: none. Reply: ready.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `args` | `table` | no | The action's arguments, checked against its declared schema |
| `ctx` | `table` | no |  |
| `name` | `string` | yes |  |
| `wait_ms` | `integer` | no | Milliseconds to wait for the run to end, at most 25000; past it the reply is {status: running, run_id} and action.wait keeps waiting. Absent waits for the end |

| Result | Type |
| --- | --- |
| `result` | `any?` |
| `run_id` | `string?` |
| `status` | `"done"\|"running"\|"rate_limited"?` |

```lua
local result = paneflow.action.invoke{ name = "dev_layout", args = { file = "app.log" }, ctx = { origin = "cli" } }
```

```json
{
  "result": {
    "surface_id": 12
  }
}
```

### `action.list`

List the actions init.lua declared, with their titles, argument schemas and sources.

Owner: worker. Gate: none. Reply: ready.

No parameters.

| Result | Type |
| --- | --- |
| `actions` | `table[]` |

```lua
local result = paneflow.action.list()
```

```json
{
  "actions": [
    {
      "name": "dev_layout",
      "title": "Dev layout",
      "category": "Actions",
      "keywords": [
        "split"
      ],
      "args": {
        "type": "object",
        "properties": {
          "file": {
            "type": "string"
          }
        },
        "required": [
          "file"
        ],
        "additionalProperties": false
      },
      "agents": false,
      "source": "init.lua:3"
    }
  ]
}
```

### `action.wait`

Keep waiting on an action run that action.invoke returned as {status: running, run_id}: the run's result with status done, the same running status, or the action's error.

Owner: worker. Gate: none. Reply: ready.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `run_id` | `string` | yes |  |
| `wait_ms` | `integer` | no | Milliseconds to wait, 0 by default, at most 25000 |

| Result | Type |
| --- | --- |
| `result` | `any?` |
| `run_id` | `string?` |
| `status` | `"done"\|"running"\|"rate_limited"?` |

```lua
local result = paneflow.action.wait{ run_id = "6f1c0e9a2b7d4c3e8f5a1b2c3d4e5f60", wait_ms = 20000 }
```

```json
{
  "result": {
    "surface_id": 12
  },
  "status": "done"
}
```

## agent

### `agent.acknowledge`

Clear the unread mark of sessions and publish the lowered rows.

Owner: worker. Gate: none. Reply: ready.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `session` | `string` | no | One session, when sessions is absent |
| `sessions` | `string[]` | no |  |

| Result | Type |
| --- | --- |
| `acknowledged` | `string[]` |

```lua
local result = paneflow.agent.acknowledge{ sessions = { "123e4567-e89b-42d3-a456-426614174000" } }
```

```json
{
  "acknowledged": [
    "123e4567-e89b-42d3-a456-426614174000"
  ]
}
```

### `agent.activity_log`

Read the most recent agent activity entries.

Owner: worker. Gate: none. Reply: ready.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `limit` | `integer` | no | Entries to return, 50 by default |

| Result | Type |
| --- | --- |
| `entries` | `any[]` |

```lua
local result = paneflow.agent.activity_log{ limit = 2 }
```

```json
{
  "entries": []
}
```

### `agent.follow`

Stream the session projection: a snapshot header, then one frame per reduced transition.

Owner: worker. Gate: none. Reply: stream.

A stream: Lua cannot call it. React to events with `paneflow.on` or `paneflow.wait`.

No parameters.

| Result | Type |
| --- | --- |
| `capabilities` | `string[]` |
| `core_connected` | `boolean` |
| `following` | `boolean?` |
| `sessions` | `any[]` |
| `usage` | `any` |
| `worker` | `table` |

```lua
local result = paneflow.agent.follow()
```

```json
{
  "worker": {
    "name": "paneflow-serve",
    "version": "0.20.0",
    "build_id": "9f2c",
    "protocol": 1,
    "required_core_protocol": 1,
    "pid": 4242,
    "home": "/home/me/.paneflow",
    "endpoint": "/home/me/.paneflow/serve/worker.sock",
    "started_at_ms": 1763600000000,
    "capabilities": [
      "agent.follow"
    ]
  },
  "capabilities": [
    "agent.follow"
  ],
  "core_connected": true,
  "sessions": [],
  "usage": {},
  "following": true
}
```

### `agent.snapshot`

Read every session's reduced agent row and the usage frame.

Owner: worker. Gate: none. Reply: ready.

No parameters.

| Result | Type |
| --- | --- |
| `capabilities` | `string[]` |
| `core_connected` | `boolean` |
| `following` | `boolean?` |
| `sessions` | `any[]` |
| `usage` | `any` |
| `worker` | `table` |

```lua
local result = paneflow.agent.snapshot()
```

```json
{
  "worker": {
    "name": "paneflow-serve",
    "version": "0.20.0",
    "build_id": "9f2c",
    "protocol": 1,
    "required_core_protocol": 1,
    "pid": 4242,
    "home": "/home/me/.paneflow",
    "endpoint": "/home/me/.paneflow/serve/worker.sock",
    "started_at_ms": 1763600000000,
    "capabilities": [
      "agent.follow"
    ]
  },
  "capabilities": [
    "agent.follow"
  ],
  "core_connected": true,
  "sessions": [],
  "usage": {}
}
```

## agent_prompt

### `agent_prompt.resolve`

Ask the user, in the window, the question or the permission request a coding agent's hook received, when agent_prompts is paneflow in paneflow.json. Holds one 300 second deadline for the whole call and replies answered with the JSON the hook prints, or declined, after which the agent asks in its own terminal.

Owner: worker. Gate: none. Reply: ready.

`reason` can also be `busy`.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `agent` | `string` | no | The agent's runtime name, such as claude or codex |
| `event` | `"ask_user_question"\|"permission_request"` | yes |  |
| `payload` | `any` | yes | The hook's input JSON, as the agent wrote it |
| `session` | `string` | no | The Paneflow session of the agent; the worker replaces it with the caller's own session when the caller runs in a pane |

| Result | Type |
| --- | --- |
| `output` | `any?` |
| `reason` | `string?` |
| `status` | `"answered"\|"declined"` |

```lua
local result = paneflow.agent_prompt.resolve{ event = "permission_request", agent = "claude", payload = { tool_name = "Bash", tool_input = { command = "rm -rf build" } } }
```

```json
{
  "status": "answered",
  "output": {
    "hookSpecificOutput": {
      "hookEventName": "PermissionRequest",
      "decision": {
        "behavior": "allow"
      }
    }
  }
}
```

## client

### `client.dispatch_action`

Dispatch a built-in action in the window as the command palette does, and reply once it is dispatched.

Owner: window. Gate: none. Reply: async.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `name` | `string` | yes | A name from client.list_actions, such as toggle_zoom |

| Result | Type |
| --- | --- |
| `dispatched` | `boolean` |
| `name` | `string` |

```lua
local result = paneflow.client.dispatch_action{ name = "toggle_zoom" }
```

```json
{
  "dispatched": true,
  "name": "toggle_zoom"
}
```

### `client.list_actions`

List the window's built-in actions: the names key bindings and client.dispatch_action accept.

Owner: window. Gate: none. Reply: inline.

No parameters.

| Result | Type |
| --- | --- |
| `actions` | `table[]` |

```lua
local result = paneflow.client.list_actions()
```

```json
{
  "actions": [
    {
      "name": "toggle_zoom",
      "description": "Zoom the focused pane",
      "group": "Panes & splits"
    }
  ]
}
```

## config

### `config.reload`

Load init.lua again now and return the status; a failed load keeps the previous configuration active.

Owner: worker. Gate: none. Reply: ready.

No parameters.

| Result | Type |
| --- | --- |
| `actions` | `integer` |
| `bindings` | `integer` |
| `found` | `boolean` |
| `handler_errors` | `integer` |
| `handlers` | `integer` |
| `loaded_at_ms` | `integer?` |
| `ok` | `boolean` |
| `path` | `string` |
| `problems` | `table[]` |
| `timer_errors` | `integer` |
| `timers` | `integer` |

```lua
local result = paneflow.config.reload()
```

```json
{
  "path": "/home/me/.paneflow/init.lua",
  "found": false,
  "ok": true,
  "actions": 0,
  "bindings": 0,
  "handlers": 0,
  "timers": 0,
  "handler_errors": 0,
  "timer_errors": 0,
  "problems": []
}
```

### `config.status`

Read the state of init.lua: its path, whether it was found, when it loaded, what it declared and its load problems.

Owner: worker. Gate: none. Reply: ready.

No parameters.

| Result | Type |
| --- | --- |
| `actions` | `integer` |
| `bindings` | `integer` |
| `found` | `boolean` |
| `handler_errors` | `integer` |
| `handlers` | `integer` |
| `loaded_at_ms` | `integer?` |
| `ok` | `boolean` |
| `path` | `string` |
| `problems` | `table[]` |
| `timer_errors` | `integer` |
| `timers` | `integer` |

```lua
local result = paneflow.config.status()
```

```json
{
  "path": "/home/me/.paneflow/init.lua",
  "found": true,
  "loaded_at_ms": 1763600000000,
  "ok": false,
  "actions": 2,
  "bindings": 1,
  "handlers": 1,
  "timers": 0,
  "handler_errors": 0,
  "timer_errors": 0,
  "problems": [
    {
      "file": "init.lua",
      "line": 7,
      "severity": "error",
      "message": "unexpected symbol near 'end'"
    }
  ]
}
```

## events

### `events.follow`

Stream the worker's numbered event log: a following header, then every event with consecutive seq values, keepalive frames when quiet, and an end frame when the worker closes the stream. A since that left the ring, or an epoch from another worker start, is refused with -32040 and data {reason: evicted, seq, epoch}.

Owner: worker. Gate: none. Reply: stream.

A stream: Lua cannot call it. React to events with `paneflow.on` or `paneflow.wait`.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `epoch` | `string` | no | The epoch since belongs to; a different epoch is refused with an evicted error |
| `since` | `integer` | no | Replay the events after this seq first; refused with an evicted error when they left the ring |
| `types` | `string[]` | no | Only send these types: exact names or a family such as terminal.* |
| `workspace_id` | `integer` | no | Only send events about this layout workspace id |

| Result | Type |
| --- | --- |
| `epoch` | `string` |
| `seq` | `integer` |
| `type` | `"following"` |

```lua
local result = paneflow.events.follow{ types = { "terminal.*", "pane.closed" } }
```

```json
{
  "type": "following",
  "seq": 41,
  "epoch": "1a2b-19a7c3f0e00-0"
}
```

### `events.subscribe`

Stream surface and agent events as JSON lines: a subscribed frame, then events, heartbeat and dropped frames.

Owner: window. Gate: none. Reply: stream.

A stream: Lua cannot call it. React to events with `paneflow.on` or `paneflow.wait`.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `surfaces` | `integer[]` | no | Only stream events about these surfaces |
| `types` | `string[]` | no | Only stream these event types: surface_changed and the ai.* lifecycle types |

| Result | Type |
| --- | --- |
| `id` | `integer` |
| `type` | `"subscribed"` |

```lua
local result = paneflow.events.subscribe{ types = { "surface_changed" } }
```

```json
{
  "type": "subscribed",
  "id": 1
}
```

## fleet

### `fleet.list`

List the agents running in every workspace.

Owner: window. Gate: none. Reply: ready.

When no window is open, the host answers, and each row also carries `session` and `generation`.

No parameters.

| Result | Type |
| --- | --- |
| `agents` | `table[]` |

```lua
local result = paneflow.fleet.list()
```

```json
{
  "agents": [
    {
      "pid": 4242,
      "tool": "claude",
      "state": "waiting_for_input",
      "hooked": true,
      "reason": null,
      "surface_id": 7,
      "surface_name": "claude",
      "workspace": 0,
      "active_tool_name": null,
      "message": "needs a decision",
      "last_result": null,
      "waiting_ms": 3000,
      "idle_ms": 3000
    }
  ]
}
```

## grant

### `grant.delegate`

Give a pane the caller spawned a grant no wider than one the caller holds.

Owner: worker. Gate: none. Reply: ready.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `duration_secs` | `integer` | no | Seconds the delegated grant lasts, until the delegator's grant ends by default |
| `rights` | `("write"\|"spawn"\|"layout")[]` | yes |  |
| `scope` | `"workspace"\|"instance"` | no |  |
| `session` | `string` | yes | The session of a pane the caller spawned with surface.split |

| Result | Type |
| --- | --- |
| `expires_at_ms` | `integer?` |
| `granted` | `boolean` |
| `id` | `string?` |
| `reason` | `string?` |

```lua
local result = paneflow.grant.delegate{ session = "223e4567-e89b-42d3-a456-426614174000", rights = { "write" } }
```

```json
{
  "granted": true,
  "id": "g-2",
  "expires_at_ms": 1800000000000
}
```

### `grant.list`

List the grants panes hold, with the revision of the set; a pane sees the grants it holds or delegated.

Owner: worker. Gate: none. Reply: ready.

No parameters.

| Result | Type |
| --- | --- |
| `grants` | `table[]` |
| `revision` | `integer` |

```lua
local result = paneflow.grant.list()
```

```json
{
  "revision": 4,
  "grants": []
}
```

### `grant.request`

Ask the human for rights the calling pane does not hold, for a scope and a time.

Owner: worker. Gate: none. Reply: ready.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `duration_secs` | `integer` | no | Seconds the grant lasts once allowed, 3600 by default; 0 asks for a grant with no expiry |
| `reason` | `string` | no | Why the agent needs it, shown to the human |
| `rights` | `("write"\|"spawn"\|"layout")[]` | yes | Rights asked for, among write, spawn and layout |
| `scope` | `"workspace"\|"instance"` | no | workspace reaches the calling pane's own workspace, instance every workspace |

| Result | Type |
| --- | --- |
| `expires_at_ms` | `integer?` |
| `granted` | `boolean` |
| `id` | `string?` |
| `reason` | `string?` |

```lua
local result = paneflow.grant.request{ rights = { "write" }, scope = "workspace", duration_secs = 600 }
```

```json
{
  "granted": true,
  "id": "g-1",
  "expires_at_ms": 1800000000000
}
```

### `grant.revoke`

Revoke a grant and every grant delegated from it.

Owner: worker. Gate: none. Reply: ready.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | `string` | yes | The grant to revoke; every grant delegated from it is revoked too |

| Result | Type |
| --- | --- |
| `revision` | `integer` |
| `revoked` | `string[]` |

```lua
local result = paneflow.grant.revoke{ id = "g-1" }
```

```json
{
  "revoked": [
    "g-1",
    "g-2"
  ],
  "revision": 5
}
```

## keymap

### `keymap.list`

List the key bindings init.lua declared and the keys it unbound, for the window to apply.

Owner: worker. Gate: none. Reply: ready.

No parameters.

| Result | Type |
| --- | --- |
| `bindings` | `table[]` |
| `unbound` | `table[]` |

```lua
local result = paneflow.keymap.list()
```

```json
{
  "bindings": [
    {
      "key": "ctrl-alt-d",
      "action": "dev_layout",
      "args": {
        "file": "app.log"
      },
      "source": "init.lua:9",
      "target": "lua"
    }
  ],
  "unbound": [
    {
      "key": "ctrl-shift-w",
      "source": "init.lua:10"
    }
  ]
}
```

## layout

### `layout.adopt`

Hand the worker a client's model after an outage. The worker takes it when its own revision is not greater than the revision it last acknowledged to the client, and otherwise returns its own view.

Owner: worker. Gate: none. Reply: ready.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `acknowledged` | `integer` | yes | The last revision the worker acknowledged to this client |
| `view` | `table` | yes | The layout model as plain data: {revision, state: {version, workspaces, active_workspace, active_space}, undo}, every workspace, tab, pane, split and surface carrying its stable id |

| Result | Type |
| --- | --- |
| `accepted` | `boolean` |
| `revision` | `integer` |
| `view` | `table?` |

```lua
local result = paneflow.layout.adopt{ view = { revision = 14, state = { version = 3, workspaces = {  }, active_workspace = 0, active_space = nil } }, acknowledged = 12 }
```

```json
{
  "accepted": true,
  "revision": 14,
  "view": null
}
```

### `layout.apply`

Apply one layout op to the worker's model and return the new revision and its events. A refused op fails with -32070 and data {reason}: not_found, zoomed, pane_limit, tab_limit, surface_limit, ids_exhausted, invalid, or window_owns_layout while a window of an earlier build owns the layout.

A request that sets a command, a prompt or an env is refused with -32601 unless ipc.orchestration, ipc.scripting or ai_unrestricted is true in paneflow.json, or a spawn or layout grant covers the calling pane.

Owner: worker. Gate: orchestration. Reply: ready.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `ids_from` | `integer` | no | The client's next id when it applied the op; ids the op allocates are taken from the client's leases from here |
| `op` | `table` | yes | One layout operation, named by its op field: split, close_pane, focus_pane, rename_surface, set_ratios, bind_session and the others of paneflow-layout, with the ids it acts on |
| `spawned_by` | `string` | no | The session of the pane that asked the window for this op; the worker records it as the spawner of the terminals the op creates. Only the attached window may send it |

| Result | Type |
| --- | --- |
| `events` | `table[]` |
| `revision` | `integer` |

```lua
local result = paneflow.layout.apply{ op = { op = "focus_pane", pane = 5 } }
```

```json
{
  "revision": 13,
  "events": [
    {
      "type": "pane.focused",
      "workspace_id": 1,
      "tab_id": 2,
      "pane_id": 5,
      "data": {}
    },
    {
      "type": "layout.changed",
      "workspace_id": 1,
      "tab_id": 2,
      "data": {
        "revision": 13
      }
    }
  ]
}
```

### `layout.attach`

Attach this connection as a layout client until it closes, and return the view, its revision and the worker's epoch.

Owner: worker. Gate: none. Reply: ready.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `client` | `string` | no | A name for the client in worker.status |

| Result | Type |
| --- | --- |
| `epoch` | `string` |
| `revision` | `integer` |
| `view` | `table` |

```lua
local result = paneflow.layout.attach{ client = "window" }
```

```json
{
  "epoch": "1a2b-19a7c3f0e00-0",
  "revision": 12,
  "view": {
    "revision": 12,
    "state": {
      "version": 3,
      "workspaces": [],
      "active_workspace": 0,
      "active_space": null
    }
  }
}
```

### `layout.launch`

Start the terminal of a surface for the attached layout client that created it: the worker builds the launch from its configuration and the layout and creates the session under the id the client chose, which the client binds with bind_session. The surface must have no session or this one. Fails with -32070 and data {reason}: not_attached, not_found, invalid, host_unreachable or launch_failed with the host's message.

A request that sets a command, a prompt or an env is refused with -32601 unless ipc.orchestration, ipc.scripting or ai_unrestricted is true in paneflow.json, or a spawn or layout grant covers the calling pane.

Owner: worker. Gate: orchestration. Reply: ready.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `appearance` | `any` | no | The colors the terminal answers color queries with: {foreground, background, cursor, palette of 256 [r, g, b], dark} |
| `cell` | `any` | no | The cell size in pixels: {width, height} |
| `cols` | `integer` | no | Initial width in cells; 120 when absent |
| `confine_to` | `string` | no | A worktree the working directory must stay inside; a cwd outside it starts at the worktree |
| `cwd` | `string` | no | The working directory the client asks for |
| `env` | `table<string, string>` | no | Variables for this terminal, above the global and space ones |
| `fallback` | `string` | no | The directory used when cwd no longer exists |
| `rows` | `integer` | no | Initial height in cells; 40 when absent |
| `session` | `string` | yes | The session id the client chose for the new terminal |
| `surface_id` | `integer` | yes | The terminal surface to start |

| Result | Type |
| --- | --- |
| `events` | `table[]` |
| `notices` | `string[]` |
| `revision` | `integer` |

```lua
local result = paneflow.layout.launch{ surface_id = 7, session = "0190e4d2-7b2a-7c3d-8e4f-a1b2c3d4e5f6", cwd = "/home/me/project" }
```

```json
{
  "revision": 15,
  "events": [
    {
      "type": "layout.changed",
      "workspace_id": 1,
      "tab_id": 2,
      "data": {
        "revision": 15
      }
    }
  ],
  "notices": []
}
```

### `layout.lease_ids`

Grant this connection a contiguous block of 1,024 ids for the elements it creates; the worker never grants an id twice, across restarts included.

Owner: worker. Gate: none. Reply: ready.

No parameters.

| Result | Type |
| --- | --- |
| `end` | `integer` |
| `start` | `integer` |

```lua
local result = paneflow.layout.lease_ids()
```

```json
{
  "start": 4097,
  "end": 5121
}
```

### `layout.sweep`

Remove the records of ended sessions that no surface of the layout, no undo hold and no pending launch names, and with live, also stop the live sessions this host started that nothing holds. The attached layout client calls it after it restores; the worker runs the host requests. Fails with -32070 and data {reason}: not_attached or host_unreachable.

Owner: worker. Gate: none. Reply: ready.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `keep` | `string[]` | no | Sessions the client holds outside the layout, such as dock terminals, which the sweep must keep |
| `live` | `boolean` | no | Also stop the live sessions this host started that nothing holds, as the first sweep after a restore does |

| Result | Type |
| --- | --- |
| `forgotten` | `string[]` |
| `stopped` | `string[]` |

```lua
local result = paneflow.layout.sweep{ live = true, keep = {  } }
```

```json
{
  "forgotten": [
    "0190e4d2-7b2a-7c3d-8e4f-a1b2c3d4e5f6"
  ],
  "stopped": []
}
```

### `layout.view`

Return the layout model the worker holds, with its revision and the worker's epoch.

Owner: worker. Gate: none. Reply: ready.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `unless_revision` | `integer` | no | The revision the client holds; when it is still the worker's, view is null |

| Result | Type |
| --- | --- |
| `attached` | `boolean` |
| `epoch` | `string` |
| `revision` | `integer` |
| `view` | `table?` |

```lua
local result = paneflow.layout.view()
```

```json
{
  "epoch": "1a2b-19a7c3f0e00-0",
  "revision": 12,
  "attached": true,
  "view": {
    "revision": 12,
    "state": {
      "version": 3,
      "workspaces": [],
      "active_workspace": 0,
      "active_space": null
    },
    "undo": {
      "records": [],
      "held": []
    }
  }
}
```

## pane

### `pane.write`

Relay a message from one agent's pane into another's, once a human allows the pair.

Owner: host. Gate: none. Reply: ready.

`request` arrives as a number. With `submit`, the reply also carries `delivered`, `started`, `reason` and, when known, `state`.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `scope` | `"workspace"\|"all"` | no |  |
| `session` | `string` | yes | The session to write into |
| `source_session` | `string` | yes | The calling pane's session (PANEFLOW_SESSION_ID) |
| `submit` | `boolean` | no |  |
| `text` | `string` | yes | Text to relay, prefixed with a provenance line |

| Result | Type |
| --- | --- |
| `bytes` | `integer?` |
| `message` | `string?` |
| `request` | `string?` |
| `status` | `string` |
| `submit_mode` | `string?` |
| `submitted` | `boolean?` |

```lua
local result = paneflow.pane.write{ source_session = "123e4567-e89b-42d3-a456-426614174000", session = "223e4567-e89b-42d3-a456-426614174000", text = "the tests pass on main" }
```

```json
{
  "status": "approval_pending",
  "request": "7",
  "message": "a human must allow it"
}
```

## peer

### `peer.classify`

Say whether a process runs inside one of the host's panes, and which one.

Owner: host. Gate: none. Reply: ready.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `pid` | `integer` | yes | PID of the process to classify |
| `started_at` | `integer` | yes | Start time the caller read for that PID, in the host's process clock |

| Result | Type |
| --- | --- |
| `in_pane` | `boolean` |
| `session` | `string?` |
| `stale` | `boolean?` |
| `unverified` | `string?` |
| `workspace` | `string?` |

```lua
local result = paneflow.peer.classify{ pid = 4242, started_at = 9876543 }
```

```json
{
  "in_pane": true,
  "session": "123e4567-e89b-42d3-a456-426614174000",
  "workspace": "223e4567-e89b-42d3-a456-426614174000"
}
```

## prompt

### `prompt.follow`

Stream the prompts this client can show: a following header, a requested frame for each pending prompt oldest first, then requested frames (id, spec, origin, remaining time, token) and ended frames (id, reason), keepalive frames when quiet. A pane never receives an agent's prompt.

Owner: worker. Gate: none. Reply: stream.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `kinds` | `("input"\|"pick")[]` | yes | The prompt kinds this client can show |

| Result | Type |
| --- | --- |
| `kinds` | `("input"\|"pick")[]` |
| `pending` | `integer` |
| `type` | `"following"` |

```lua
local result = paneflow.prompt.follow{ kinds = { "input", "pick" } }
```

```json
{
  "type": "following",
  "kinds": [
    "input",
    "pick"
  ],
  "pending": 1
}
```

### `prompt.reply`

Answer or cancel a pending prompt. The first reply wins and every follower receives ended; a later one is refused with -32060 and data {reason: not_pending}. An agent's prompt takes a reply only with its token, from outside every pane.

Owner: worker. Gate: none. Reply: ready.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `answer` | `string\|string[]\|table` | no | The text, the id, the list of ids or {text}, as the prompt's kind takes |
| `cancel` | `boolean` | no | Dismiss the prompt; the asker receives cancelled |
| `id` | `integer` | yes |  |
| `token` | `string` | no | The requested frame's token; required for an agent's prompt |

| Result | Type |
| --- | --- |
| `id` | `integer` |
| `reason` | `"answered"\|"cancelled"\|"timeout"\|"no_client"\|"failed"` |

```lua
local result = paneflow.prompt.reply{ id = 3, answer = "feature/login" }
```

```json
{
  "id": 3,
  "reason": "answered"
}
```

### `prompt.request`

Ask the user through every attached client that can show the prompt; the first answer wins. Returns {status: answered, answer} within wait_ms, {status: pending, id} when wait_ms passes first, or the reason it ended: cancelled, timeout, no_client, unsupported, busy, rate_limited (an agent asking more than 3 times in a burst or more than once a second after it) or failed with a detail.

Owner: worker. Gate: none. Reply: ready.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `allow_other` | `boolean` | no | Accept typed text that matches no item; the answer is {text} |
| `body` | `string` | no | Shown under the title, line breaks kept; at most 16384 bytes |
| `confirm` | `string` | no | Label of the confirming row |
| `items` | `(string\|table)[]` | no | The choices of a pick prompt, at most 2000: an id string or an item |
| `kind` | `"input"\|"pick"` | yes | input asks for a line of text, pick for a choice among items |
| `multiple` | `boolean` | no | Let the user tick several items; the answer is the list of ids |
| `origin` | `table` | no | Who asks, shown under the title |
| `placeholder` | `string` | no |  |
| `timeout` | `number` | no | Seconds before the prompt ends with timeout: 300 by default, at most 3600 |
| `title` | `string` | yes |  |
| `value` | `string` | no | Text the field starts with |
| `wait_ms` | `integer` | no | Milliseconds to wait for the answer before returning pending with the id, 0 by default, at most 25000 |

| Result | Type |
| --- | --- |
| `answer` | `string\|string[]\|table?` |
| `detail` | `string?` |
| `id` | `integer?` |
| `status` | `"answered"\|"pending"\|"cancelled"\|"timeout"\|"no_client"\|"unsupported"\|"busy"\|"rate_limited"\|"failed"` |

```lua
local result = paneflow.prompt.request{ kind = "input", title = "New branch", value = "feature/", wait_ms = 20000, origin = { kind = "action", name = "new_branch", title = "New branch" } }
```

```json
{
  "status": "answered",
  "id": 3,
  "answer": "feature/login"
}
```

### `prompt.wait`

Keep waiting on a pending prompt by id, with the same outcomes as prompt.request.

Owner: worker. Gate: none. Reply: ready.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | `integer` | yes |  |
| `wait_ms` | `integer` | no | Milliseconds to wait, 0 by default, at most 25000 |

| Result | Type |
| --- | --- |
| `answer` | `string\|string[]\|table?` |
| `detail` | `string?` |
| `id` | `integer?` |
| `status` | `"answered"\|"pending"\|"cancelled"\|"timeout"\|"no_client"\|"unsupported"\|"busy"\|"rate_limited"\|"failed"` |

```lua
local result = paneflow.prompt.wait{ id = 4, wait_ms = 20000 }
```

```json
{
  "status": "answered",
  "id": 4,
  "answer": "web"
}
```

## surface

### `surface.focus`

Reveal a surface and give it the keyboard focus.

Owner: worker. Gate: none. Reply: ready.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `surface_id` | `integer` | yes |  |

| Result | Type |
| --- | --- |
| `focused` | `boolean` |
| `scope` | `string` |
| `surface_id` | `integer` |
| `workspace` | `integer` |

```lua
local result = paneflow.surface.focus{ surface_id = 7 }
```

```json
{
  "focused": true,
  "surface_id": 7,
  "workspace": 0,
  "scope": "workspace"
}
```

### `surface.list`

List the surfaces of the shown workspace, or of one workspace, with their identity.

Owner: window. Gate: none. Reply: ready.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `scope` | `"workspace"\|"all"` | no | "all" reads beyond the calling pane's workspace when orchestration is open for it |
| `scope_session` | `string` | no | List the workspace that holds this session |
| `workspace_id` | `integer` | no | List this workspace instead of the shown one |

| Result | Type |
| --- | --- |
| `pane_count` | `integer` |
| `scope_workspace_id` | `integer?` |
| `surfaces` | `table[]` |
| `workspace` | `integer` |

```lua
local result = paneflow.surface.list()
```

```json
{
  "pane_count": 1,
  "workspace": 0,
  "scope_workspace_id": null,
  "surfaces": [
    {
      "surface_id": 7,
      "name": "shell",
      "title": "~/dev",
      "cwd": "/home/me/dev",
      "cmd": "zsh",
      "workspace_id": 1,
      "workspace": 0,
      "scope": "workspace",
      "tab_id": 1,
      "tab_title": "Terminal",
      "space": null,
      "sandboxed": false
    }
  ]
}
```

### `surface.read`

Read a surface's trailing scrollback lines.

Owner: window. Gate: none. Reply: deferred.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `fenced` | `boolean` | no | Wrap the text in an untrusted-output fence; the ai_injection_fence setting decides when absent |
| `lines` | `integer` | no | Trailing lines to return, clamped to 1..4000 |
| `name` | `string` | no | Pick the surface by its unique name instead of its id |
| `offset` | `integer` | no | Lines to skip back from the end of the buffer |
| `scope` | `"workspace"\|"all"` | no | "all" reads beyond the calling pane's workspace when orchestration is open for it |
| `scope_session` | `string` | no |  |
| `surface_id` | `integer` | no | The surface to read; the first surface of the shown tab when absent |
| `workspace_id` | `integer` | no |  |

| Result | Type |
| --- | --- |
| `eof` | `boolean` |
| `lines` | `integer` |
| `output_generation` | `integer` |
| `text` | `string` |
| `total_lines` | `integer` |
| `truncated` | `boolean` |

```lua
local result = paneflow.surface.read{ surface_id = 7, lines = 2, fenced = false }
```

```json
{
  "text": "cargo test\nok",
  "lines": 2,
  "total_lines": 40,
  "eof": false,
  "output_generation": 12,
  "truncated": false
}
```

### `surface.rename`

Give a surface a custom name, or clear it.

Owner: worker. Gate: none. Reply: ready.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `name` | `string` | no | The new name; an absent or empty name clears the custom name |
| `new_name` | `string` | no | Alias of name |
| `surface_id` | `integer` | no |  |

| Result | Type |
| --- | --- |
| `name` | `string?` |
| `renamed` | `boolean` |

```lua
local result = paneflow.surface.rename{ surface_id = 7, name = "tests" }
```

```json
{
  "renamed": true,
  "name": "tests"
}
```

### `surface.search`

Find the scrollback lines of a surface that contain a pattern.

Owner: window. Gate: none. Reply: deferred.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `fenced` | `boolean` | no | Add a text field holding every match in one untrusted-output fence; the ai_injection_fence setting decides when absent |
| `max_matches` | `integer` | no | Matches to return, clamped to 1..1000 |
| `name` | `string` | no |  |
| `pattern` | `string` | yes | Substring or pattern to find, at most 512 bytes |
| `scope` | `"workspace"\|"all"` | no | "all" reads beyond the calling pane's workspace when orchestration is open for it |
| `scope_session` | `string` | no |  |
| `surface_id` | `integer` | no |  |
| `workspace_id` | `integer` | no |  |

| Result | Type |
| --- | --- |
| `matches` | `table[]` |
| `text` | `string?` |
| `truncated` | `boolean` |

```lua
local result = paneflow.surface.search{ surface_id = 7, pattern = "error" }
```

```json
{
  "matches": [
    {
      "line": 31,
      "text": "error[E0308]: mismatched types"
    }
  ],
  "truncated": false
}
```

### `surface.send_keystroke`

Send a named key such as escape or ctrl-c to a surface.

Refused with -32601 unless ipc.scripting or ai_unrestricted is true in paneflow.json, or a write grant covers the calling pane.

Owner: window. Gate: scripting. Reply: ready.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `keystroke` | `string` | no | Dash-separated key such as escape, ctrl-c or alt-f; required, and never one that submits a line |
| `scope` | `"workspace"\|"all"` | no |  |
| `scope_session` | `string` | no |  |
| `surface_id` | `integer` | no |  |

| Result | Type |
| --- | --- |
| `sent` | `boolean` |

```lua
local result = paneflow.surface.send_keystroke{ surface_id = 7, keystroke = "ctrl-c" }
```

```json
{
  "sent": true
}
```

### `surface.send_text`

Write text into a surface, submitting it only when asked.

Refused with -32601 unless ipc.scripting or ai_unrestricted is true in paneflow.json, or a write grant covers the calling pane.

Owner: window. Gate: scripting. Reply: ready.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `force` | `boolean` | no | Write even when the agent waits for a decision; the write is logged |
| `paste` | `boolean` | no | Force or refuse bracketed paste; decided from the target when absent |
| `scope` | `"workspace"\|"all"` | no |  |
| `scope_session` | `string` | no | The calling pane's session; writes stay in its workspace |
| `submit` | `boolean` | no | Submit with a carriage return after the text |
| `surface_id` | `integer` | no |  |
| `text` | `string` | no | Text to write; required unless submit is true. At most 64 KiB |

| Result | Type |
| --- | --- |
| `agent_target` | `boolean` |
| `agent_tool` | `string?` |
| `length` | `integer` |
| `paste` | `boolean` |
| `sent` | `boolean` |
| `submit_mode` | `"deferred_paste_cr"\|"inline_cr"?` |
| `submitted` | `boolean` |
| `terminal_bracketed_paste` | `boolean` |

```lua
local result = paneflow.surface.send_text{ surface_id = 7, text = "cargo test" }
```

```json
{
  "sent": true,
  "length": 10,
  "submitted": false,
  "paste": false,
  "submit_mode": null,
  "agent_target": false,
  "agent_tool": null,
  "terminal_bracketed_paste": false
}
```

### `surface.split`

Split the pane holding a surface and start a terminal in the new pane.

A request that sets a command, a prompt or an env is refused with -32601 unless ipc.orchestration, ipc.scripting or ai_unrestricted is true in paneflow.json, or a spawn or layout grant covers the calling pane.

Owner: worker. Gate: orchestration. Reply: async.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `command` | `string` | no |  |
| `cwd` | `string` | no |  |
| `direction` | `"horizontal"\|"vertical"` | yes | horizontal stacks the panes, vertical puts them side by side |
| `env` | `table<string, string>` | no |  |
| `label` | `string` | no |  |
| `managed_worktree` | `table` | no |  |
| `name` | `string` | no | Alias of label |
| `profile` | `"normal"\|"agent"\|"cached"` | no |  |
| `prompt` | `string` | no |  |
| `surface_id` | `integer` | no | Split the pane holding this surface; the shown tab's first pane when absent |
| `worktree` | `table` | no | Create or reuse a Paneflow worktree for the new pane, which then starts in it; exclusive with managed_worktree |

| Result | Type |
| --- | --- |
| `direction` | `string` |
| `new_tab` | `boolean` |
| `notices` | `string[]?` |
| `panes` | `integer` |
| `split` | `boolean` |
| `surface_id` | `integer` |
| `tab_id` | `integer` |

```lua
local result = paneflow.surface.split{ surface_id = 7, direction = "vertical" }
```

```json
{
  "split": true,
  "new_tab": false,
  "tab_id": 3,
  "direction": "vertical",
  "panes": 2,
  "surface_id": 9
}
```

### `surface.status`

Read a surface's agent state, hook status and output generation.

Owner: window. Gate: none. Reply: ready.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `name` | `string` | no |  |
| `surface_id` | `integer` | no |  |

| Result | Type |
| --- | --- |
| `active_tool_name` | `string?` |
| `hooked` | `boolean` |
| `idle_ms` | `integer?` |
| `last_result` | `string?` |
| `message` | `string?` |
| `output_generation` | `integer` |
| `session` | `string` |
| `state` | `string?` |
| `state_seq` | `integer?` |
| `surface_id` | `integer` |
| `tool` | `string?` |
| `waiting_ms` | `integer?` |

```lua
local result = paneflow.surface.status{ surface_id = 7 }
```

```json
{
  "surface_id": 7,
  "state": "thinking",
  "state_seq": 4,
  "hooked": true,
  "tool": "claude",
  "active_tool_name": "Bash",
  "message": null,
  "last_result": null,
  "waiting_ms": null,
  "idle_ms": 1200,
  "output_generation": 12,
  "session": "123e4567-e89b-42d3-a456-426614174000"
}
```

## system

### `system.capabilities`

List the methods this endpoint serves and whether its gates are open.

Owner: window. Gate: none. Reply: ready.

When no window is open, the host answers: its reply carries `controller` and `host` in place of `methods`.

No parameters.

| Result | Type |
| --- | --- |
| `methods` | `string[]` |
| `orchestration` | `boolean` |
| `scripting` | `boolean` |

```lua
local result = paneflow.system.capabilities()
```

```json
{
  "scripting": false,
  "orchestration": false,
  "methods": [
    "system.ping",
    "surface.list"
  ]
}
```

### `system.counters`

Read the app's work counters: renders, git spawns, process spawns.

Owner: window. Gate: none. Reply: inline.

No parameters.

| Result | Type |
| --- | --- |
| `counters` | `table` |

```lua
local result = paneflow.system.counters()
```

```json
{
  "counters": {
    "root_renders": 120,
    "sidebar_renders": 40,
    "host_agent_snapshots_applied": 3,
    "session_list_calls": 2,
    "git_spawns": {
      "total": 5,
      "probe": 4,
      "user_action": 1,
      "by_subcommand": {
        "status": 4,
        "other": 1
      }
    },
    "process_spawns": 7,
    "process_identity": {
      "pid": 4242,
      "started_at": 1763600000000
    }
  }
}
```

### `system.describe`

Describe every method, or one: owner, gate, params and result schemas, examples.

Owner: window. Gate: none. Reply: inline.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `method` | `string` | no | Describe only this method |

| Result | Type |
| --- | --- |
| `callable` | `boolean` |
| `examples` | `table[]` |
| `fallback` | `string?` |
| `gate` | `string` |
| `gate_note` | `string?` |
| `in_capabilities` | `boolean` |
| `methods` | `table[]` |
| `name` | `string` |
| `owner` | `string` |
| `params` | `any` |
| `reply` | `string` |
| `result` | `any` |
| `stream` | `boolean` |
| `summary` | `string` |

```lua
local result = paneflow.system.describe{ method = "system.ping" }
```

```json
{
  "name": "system.ping",
  "summary": "Check that the endpoint answers.",
  "owner": "window",
  "fallback": null,
  "gate": "none",
  "gate_note": null,
  "reply": "inline",
  "stream": false,
  "in_capabilities": true,
  "callable": true,
  "params": {
    "type": "object"
  },
  "result": {
    "type": "object",
    "properties": {
      "pong": {
        "type": "boolean"
      }
    }
  },
  "examples": [
    {
      "params": {},
      "result": {
        "pong": true
      }
    }
  ]
}
```

### `system.identify`

Name the running app, its version and its wire protocol.

Owner: window. Gate: none. Reply: inline.

No parameters.

| Result | Type |
| --- | --- |
| `name` | `string` |
| `protocol` | `string` |
| `version` | `string` |

```lua
local result = paneflow.system.identify()
```

```json
{
  "name": "PaneFlow",
  "version": "0.20.0",
  "protocol": "jsonrpc-2.0"
}
```

### `system.ping`

Check that the endpoint answers.

Owner: window. Gate: none. Reply: inline.

No parameters.

| Result | Type |
| --- | --- |
| `pong` | `boolean` |

```lua
local result = paneflow.system.ping()
```

```json
{
  "pong": true
}
```

### `system.whoami`

Say how the answering process identifies the caller: window, worker, pane, external or unverified.

Owner: window. Gate: none. Reply: inline.

No parameters.

| Result | Type |
| --- | --- |
| `principal` | `string` |
| `reason` | `string?` |
| `session` | `string?` |
| `workspace` | `string?` |

```lua
local result = paneflow.system.whoami()
```

```json
{
  "principal": "pane",
  "session": "123e4567-e89b-42d3-a456-426614174000",
  "workspace": "223e4567-e89b-42d3-a456-426614174000"
}
```

## tmux

### `tmux.compat`

Run a tmux command for an agent team, as the paneflow tmux shim does.

Owner: window. Gate: none. Reply: async.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `argv` | `string[]` | yes | The tmux command line, at most 256 arguments and 256 KiB |
| `scope_session` | `string` | no |  |
| `surface_id` | `integer` | yes | The calling pane's surface |
| `team` | `string` | yes | Team name, 1 to 64 bytes |

| Result | Type |
| --- | --- |
| `exit` | `integer` |
| `stderr` | `string` |
| `stdout` | `string` |

```lua
local result = paneflow.tmux.compat{ team = "review", surface_id = 7, argv = { "display-message", "-p", "#{pane_id}" } }
```

```json
{
  "stdout": "%0\n",
  "stderr": "",
  "exit": 0
}
```

## usage

### `usage.import`

Start importing past activity from the agents' local logs.

Owner: worker. Gate: none. Reply: ready.

`accounts[].agent` takes `claude-code`, `codex` or `grok`.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `accounts` | `table[]` | no |  |
| `force` | `boolean` | no | usage.import only: start again even when an import already ran |

A value with no declared fields.

```lua
local result = paneflow.usage.import{ force = false }
```

```json
{}
```

### `usage.refresh`

Read fresh usage for the running agents and the listed accounts.

Owner: worker. Gate: none. Reply: ready.

`accounts[].agent` takes `claude-code`, `codex` or `grok`.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `accounts` | `table[]` | no |  |
| `force` | `boolean` | no | usage.import only: start again even when an import already ran |

A value with no declared fields.

```lua
local result = paneflow.usage.refresh{ accounts = { { agent = "codex", config_dir = "/home/me/.codex" } } }
```

```json
{}
```

### `usage.snapshot`

Read the usage ledger snapshot.

Owner: worker. Gate: none. Reply: ready.

No parameters.

A value with no declared fields.

```lua
local result = paneflow.usage.snapshot()
```

```json
{}
```

## worker

### `worker.hello`

Open a worker connection and read the worker's identity and capabilities.

Owner: worker. Gate: none. Reply: ready.

No parameters.

| Result | Type |
| --- | --- |
| `build_id` | `string` |
| `capabilities` | `string[]` |
| `endpoint` | `string` |
| `home` | `string` |
| `name` | `string` |
| `pid` | `integer` |
| `protocol` | `integer` |
| `required_core_protocol` | `integer` |
| `started_at_ms` | `integer` |
| `version` | `string` |

```lua
local result = paneflow.worker.hello()
```

```json
{
  "name": "paneflow-serve",
  "version": "0.20.0",
  "build_id": "9f2c",
  "protocol": 1,
  "required_core_protocol": 1,
  "pid": 4242,
  "home": "/home/me/.paneflow",
  "endpoint": "/home/me/.paneflow/serve/worker.sock",
  "started_at_ms": 1763600000000,
  "capabilities": [
    "agent.follow"
  ]
}
```

### `worker.shutdown`

Ask the worker to stop; terminals keep running in the host.

Owner: worker. Gate: none. Reply: ready.

No parameters.

| Result | Type |
| --- | --- |
| `pid` | `integer` |
| `stopping` | `boolean` |

```lua
local result = paneflow.worker.shutdown()
```

```json
{
  "stopping": true,
  "pid": 4242
}
```

### `worker.status`

Read the worker's pid, version, session count and counters.

Owner: worker. Gate: none. Reply: ready.

The reply also carries a `layout` object.

No parameters.

| Result | Type |
| --- | --- |
| `capabilities` | `string[]` |
| `core_connected` | `boolean` |
| `counters` | `any` |
| `endpoint` | `string` |
| `home` | `string` |
| `pid` | `integer` |
| `protocol` | `integer` |
| `session_count` | `integer` |
| `version` | `string` |

```lua
local result = paneflow.worker.status()
```

```json
{
  "pid": 4242,
  "protocol": 1,
  "home": "/home/me/.paneflow",
  "endpoint": "/home/me/.paneflow/serve/worker.sock",
  "version": "0.20.0",
  "session_count": 3,
  "core_connected": true,
  "capabilities": [
    "agent.follow"
  ],
  "counters": {
    "sweeps": 10
  }
}
```

## workspace

### `workspace.close`

Close the workspace at an index; the last workspace cannot be closed.

Owner: worker. Gate: none. Reply: ready.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `index` | `integer` | yes | Zero-based workspace index |

| Result | Type |
| --- | --- |
| `closed` | `integer` |

```lua
local result = paneflow.workspace.close{ index = 1 }
```

```json
{
  "closed": 1
}
```

### `workspace.create`

Open a workspace with one terminal, or with a layout document.

A request that sets a command, a prompt or an env is refused with -32601 unless ipc.orchestration, ipc.scripting or ai_unrestricted is true in paneflow.json, or a spawn or layout grant covers the calling pane.

Owner: worker. Gate: orchestration. Reply: async.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `cwd` | `string` | no | Directory of the first pane; it must exist |
| `layout` | `table` | no |  |
| `name` | `string` | no | Workspace title |
| `space` | `string` | no | Space by name or id; the active space when absent |

| Result | Type |
| --- | --- |
| `index` | `integer` |
| `panes` | `integer` |
| `title` | `string` |

```lua
local result = paneflow.workspace.create{ name = "review" }
```

```json
{
  "index": 1,
  "title": "review",
  "panes": 1
}
```

### `workspace.current`

Describe the shown workspace with its layout document, or null when none is shown.

Owner: window. Gate: none. Reply: ready.

No parameters.

| Result | Type |
| --- | --- |
| `cwd` | `string` |
| `index` | `integer` |
| `layout` | `table?` |
| `panes` | `integer` |
| `space` | `table?` |
| `title` | `string` |

```lua
local result = paneflow.workspace.current()
```

```json
{
  "index": 0,
  "title": "paneflow",
  "cwd": "/home/me/dev/paneflow",
  "panes": 1,
  "space": null,
  "layout": {
    "type": "pane",
    "surfaces": [
      {
        "surface_type": "terminal",
        "name": "shell"
      }
    ]
  }
}
```

### `workspace.list`

List every workspace with its title, directory, pane count and space.

Owner: window. Gate: none. Reply: ready.

No parameters.

| Result | Type |
| --- | --- |
| `workspaces` | `table[]` |

```lua
local result = paneflow.workspace.list()
```

```json
{
  "workspaces": [
    {
      "index": 0,
      "title": "paneflow",
      "cwd": "/home/me/dev/paneflow",
      "panes": 2,
      "active": true,
      "space": null
    }
  ]
}
```

### `workspace.restore_layout`

Conform the shown tab to a layout document, reusing its panes.

A request that sets a command, a prompt or an env is refused with -32601 unless ipc.orchestration, ipc.scripting or ai_unrestricted is true in paneflow.json, or a spawn or layout grant covers the calling pane.

Owner: worker. Gate: orchestration. Reply: ready.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `layout` | `table` | yes | Holds between 1 and 32 panes |

| Result | Type |
| --- | --- |
| `panes` | `integer` |
| `restored` | `boolean` |

```lua
local result = paneflow.workspace.restore_layout{ layout = { type = "split", direction = "vertical", children = { { type = "pane", surfaces = { {} } }, { type = "pane", surfaces = { {} } } } } }
```

```json
{
  "restored": true,
  "panes": 2
}
```

### `workspace.select`

Show the workspace at an index.

Owner: worker. Gate: none. Reply: ready.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `index` | `integer` | yes | Zero-based workspace index |

| Result | Type |
| --- | --- |
| `selected` | `integer` |

```lua
local result = paneflow.workspace.select{ index = 1 }
```

```json
{
  "selected": 1
}
```

### `workspace.up`

Open a workspace from pane specs, each with its own directory, command or prompt.

A request that sets a command, a prompt or an env is refused with -32601 unless ipc.orchestration, ipc.scripting or ai_unrestricted is true in paneflow.json, or a spawn or layout grant covers the calling pane.

Owner: worker. Gate: orchestration. Reply: async.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `layout` | `string` | no | Layout preset |
| `name` | `string` | no | Workspace title |
| `panes` | `table[]` | yes |  |
| `space` | `string` | no |  |

| Result | Type |
| --- | --- |
| `index` | `integer` |
| `labels` | `string[]` |
| `notices` | `string[]?` |
| `panes` | `integer` |
| `surface_ids` | `integer[]` |
| `title` | `string` |

```lua
local result = paneflow.workspace.up{ name = "agents", panes = { { label = "api" }, { label = "web" } } }
```

```json
{
  "index": 1,
  "title": "agents",
  "panes": 2,
  "surface_ids": [
    11,
    12
  ],
  "labels": [
    "api",
    "web"
  ]
}
```