Macterm

The macterm CLI

The macterm command controls the running app: projects, tabs, panes and their sessions. It uses a local Unix socket.

Each shell that Macterm starts already has macterm in its PATH:

$ macterm status
Macterm 1.4.0 (pid 4242)
Server 1.0.1+thdxg.3f9a61c0e2b4d857 (pid 5120)

$ macterm tab new --run "npm run dev"
tab:3  *  npm  1 pane

$ macterm grid 2x2 --run "tail -f log/dev.log"

In any other shell, use the bundle path, or make a symlink to it in a folder in your PATH:

/Applications/Macterm.app/Contents/Resources/bin/macterm status

Every command that talks to the app accepts --json for a payload that a script can read. It also accepts --socket <path> to select the socket of one session server. See Finding the server. --help works at every level.

Commands

The grammar is macterm <noun> <verb> [options]. A noun with no verb means list.

Command Description
status Shows the app (Macterm <version> (pid N)) and the session server (Server <version> (pid N)), one line each. If the app does not run, it shows the server line only and exits with 2. To see the project of each window, use window list. In --json, version and pid are the app's, and server has the version and the pid of the server. With no app, --json has only server.
project list Lists all projects with refs (project:1), the active marker and tab counts. On a terminal, the list shows as a tree. To a pipe, each project is one line, with the name of its parent (- at the top level). If the parent is inside another project, its name is the path of names from the top level, for example Work > api. In --json, parent is that path (empty at the top level) and parentID is the UUID of the parent.
project create <path> [--name N] [--parent P] [--select] Adds a project for a local directory or a remote spec. It is not idempotent. Each run adds a new project. --parent puts the new project inside the project P, as New Project Inside does. The default is the top level. P must be a project of the sidebar tree. --name defaults to the name of the directory. It cannot be empty. It follows the rules of a project name.
project select <project> [--window W] Makes a project active and shows its project screen, as a click on its sidebar row does. pinned selects the pinned tabs. A project inside another project has a path of names: macterm project select "Work>api". Work > api is the same path. Put a path in quotes, because a shell reads > as a redirect. Every project option (--project, --parent, --to-project, --to) takes a path too.
project move <project> [--to P] [--slot N] Moves a project, with the projects inside it. --to P moves it into the project P, at the end. --to root moves it to the top level. --slot N puts it at position N among the projects of its parent, counted from 1. With --to, N is a position in P. Give --to, --slot, or both. P must be a project of the sidebar tree, and cannot be the project or a project inside it. For a project with the name root, give its UUID or index.
project rename <project> <name> Renames a project. The name follows the rules of a project name.
project remove <project> [--force] Removes a project and every project inside it, and kills their sessions. Returns busy when a pane runs a program, unless you use --force. It does not touch your files.
tab list [--project P] Lists the tabs of a project (default: the active project).
tab new [--project P] [--run CMD] [--no-focus] Makes a new tab. The tab becomes active unless you use --no-focus. --run types CMD into the new shell.
tab select <tab> [--window W] Makes a tab active (tab:3, an index, a UUID, or an exact title).
tab move <tab> [slot] [--to-project P] Changes the order of a tab, moves it to another project, or both. slot is the final position, counted from 1. With --to-project, the tab goes to the end of the tabs of P, and slot is a position in P. P must be a project of the sidebar tree. Give slot, --to-project, or both.
tab rename <tab> [title] [--reset] Renames a tab, or restores the automatic title.
tab close <tab> [--force] Closes a tab and kills its sessions. Returns busy when a pane runs a program, unless you use --force. If you close a pinned tab, its row and saved layout stay.
tab remove <tab> [--force] The same as tab close.
window list Lists the open windows in the order of their creation (window:1).
window new Opens another window on the current project.
window focus <window> Brings a window to the front.
window close [--window W] Closes a window. The last visible window hides instead.
widget list Lists the desktop widgets in the order of their creation (widget:1), with name, size, locked or editing state, and session name.
widget new [--size S] [--name N] [--run CMD] Adds a locked desktop widget that runs your login shell, in the middle of the desktop. S is a grid span, COLUMNSxROWS, for example 3x2. The default is 3x3. --run types CMD into the shell each time that the widget starts one.
widget set <widget> --size S Changes the size of a widget. It snaps to the grid.
widget edit <widget> Unlocks a widget for typing, moving and resizing. Returns busy while you edit another widget.
widget done Locks the widget that you edit.
widget remove <widget> [--force] Removes a widget and ends its shell. Returns busy when a program runs in it, unless you use --force.
palette list Lists the palettes of the installed extensions, in ~/.config/macterm/extensions. It reads them again each time. It shows the id (<extension>/<file>), the keybind, and the name of the palette or the error that stopped Macterm from reading the file.
pane list [--project P] [--tab T] Lists panes with refs, session names, cwd, foreground process and execution state.
pane inspect [target] Shows a snapshot of the terminal state of a pane.
pane dump [--scrollback] [target] Prints the terminal text of a pane. It prints text only, so you can use it in a pipeline.
pane split [--direction right|left|down|up|auto] [--run CMD] [--no-focus] [target] Splits a pane. The new pane gets the cwd of the pane. auto selects the longer axis. --no-focus keeps the current focus and zoom.
pane focus <target> Focuses a pane. It selects the tab, brings the window forward and restores keyboard focus.
pane focus --direction left|down|up|right [target] Focuses the nearest pane in that direction. At the outermost edge, it does nothing and gives no error.
pane close (--pane P | --session S) [--force] Closes a pane. It always needs an explicit target.
pane run [--no-submit] [target] -- <command…> Types a command and a newline into a live pane. --no-submit leaves the text at the shell prompt. See Typing into a pane.
pane key <chord> [target] Sends one key press (a, ctrl+c, escape, up).
pane zoom [target] Turns zoom on or off for a pane.
pane resize-split --axis horizontal|vertical --ratio R [target] Sets the ratio (0.15 to 0.85) of the nearest split on that axis.
grid <RxC> [--run CMD] [target] Splits a pane into an equal grid of R×C panes (16 cells at most). --run starts CMD in every new pane.
session list / session info <name> Lists sessions and shows which pane is connected to each one.
session kill <name> Kills a session. The shell of a connected pane exits.
layout apply [--project P] [--force] Changes the workspace to match the layout file of the project. Returns busy instead of closing panes.
layout save [--project P] Writes the live workspace to ~/.config/macterm/projects/<slug>.yaml.
tutor [project|pinned] Prints a short tutorial with your own keybinds. It needs a running app.
ssh <ssh args…> Runs ssh with the terminal integration of Macterm. It needs no running app. The flags are the flags of ghostty +ssh: --terminfo=false, --forward-env=false, --cache=false and --verbose.
api list [--json] Lists the methods of the server protocol that the CLI can call, with the protocol level that added each one. It needs no running server. See The server protocol.
api describe <method> Prints one method as JSON, with its arguments and its result as JSON Schema. It needs no running server.
api call <method> [--args JSON] Sends one request to the server and prints its result as JSON. --args is a JSON object, or - to read it from stdin. The default is {}.
mcp Runs the MCP server for coding agents on stdin and stdout. It works with no running app.
skills Prints how to add the MCP server, which replaces the agent skills of Macterm. It needs no running app.

Tabs and projects

A tab and a project have the same verbs where they do the same thing, as in the app.

Verb Tab Project
Move into another project tab move <tab> --to-project <project> project move <project> --to <project>
Change the order tab move <tab> <slot> project move <project> --slot <slot>
Remove tab remove <tab> (or tab close) project remove <project>
Make one tab new project create <path>, or project create <path> --parent <project> inside a project

A project option accepts a name, a path of names, a UUID or an index. A path of names starts at the top level and has > between the names, for example "Work > api" or "Work>api". Put the path in quotes, because the shell reads > as a redirect. If two projects have the same name, for example two nested projects, use the path or the UUID.

Starting a background terminal

tab new --no-focus starts the shell of a tab and does not change the selected tab. An empty workspace takes its first tab with no focus history. pane split --no-focus starts a split and does not move the pane focus or clear the zoom. Neither command switches projects or windows. This is also true when the target project or tab is not visible. Without the flag, creation selects the new tab or pane as usual.

macterm tab new --project api --no-focus --run "npm test"
macterm pane split --session "$MACTERM_SESSION" --no-focus --run "npm run dev"

The shell starts with no visit to the child, with or without --run. Creation returns before the shell is ready for more input. If you use pane run, wait for the shell prompt. Use --json to get the identity of the new tab or pane. Use pane list --project P --tab T to find the session of a new tab. tab new uses the active project by default. It does not use the project of the caller. If the two can be different, pass --project.

Use the CLI that is in the app that you target. The CLI and the session server must be the same build. At the start of each connection, the server refuses a CLI of another build. The CLI then exits with 1 and does nothing. stderr shows the build of the server and the build of the CLI.

Targeting a pane

Projects and tabs accept a name, a UUID or the index from the list output, counted from 1 (3 or tab:3). A name that two items have gives an ambiguous error. The CLI never selects the first match in silence. Project indexes count every project in sidebar order: a project, then the projects inside it. A project also accepts a path of names (see Tabs and projects).

Pane commands find their target in this order:

  1. --session <name>: the session name. It is stable across restarts. Pane UUIDs change at every start, and session names do not. The CLI finds the session in the project that holds it, unless --project names a project.
  2. --pane <uuid|index>.
  3. MACTERM_SESSION: inside a pane. A bare macterm pane split therefore splits the pane that you are in. An explicit --tab turns this off.
  4. In all other cases, the focused pane of the active tab.

The pane of a desktop widget belongs to no project. pane dump, pane inspect, pane run and pane key reach it with --session only. Inside the widget, they also reach it with MACTERM_SESSION.

pane close never uses MACTERM_SESSION. pane focus --direction treats the resolved target as the origin. It reports the pane that has the focus at the end.

Typing into a pane

pane run types everything after -- exactly as you wrote it, with the dashes:

macterm pane run --session macterm-api-8f327ce4a3f8 -- ls -la

Before --, its own flags are read at any place (--no-submit, the target selectors, --socket and --json). Words with no leading dash are typed. So macterm pane run ls and macterm pane run clear --session macterm-api-8f327ce4a3f8 need no --. Any other word that starts with - before -- is an error, and nothing is typed. For example, macterm pane run ls -la fails. It prints the same command with its text after --. --help before -- prints help.

pane run and pane key also work for a pane of a remote project, while Macterm is connected to its host. They use the ssh connection that Macterm uses for that host, and never log in. If the host is not connected, they type nothing and fail with this error:

The host <host> is not connected. Open Macterm to connect it.

Open the project in Macterm, then run the command again. Other errors from a host also say what to do.

Text that pane run or pane key types gets no Save Password? offer. See Passwords.

Reading a pane

$ macterm pane inspect
session             macterm-api-8f327ce4a3f8
grid                132×65
cell px             16×40
surface px          2176×2682
scrollback          360 total, 295 offset, 65 len
alt-screen          false
content scale       2.0
foreground          79497 (nvim src/main.rs)
process exited      false
needs confirm quit  false
read-only           false

pane dump prints the text of the viewport. --scrollback adds the full scrollback before it. It reads the own cells of the terminal, so it sees what a full-screen program draws.

pane dump and pane inspect read the session, not a window. They work for a pane that no window shows. The app gives the cell size, the surface size, the content scale and read-only. If the app does not run, or no window shows the pane, pane inspect shows - for these four.

read-only is true while the pane is read-only. While Macterm runs, pane run and pane key then return read_only and type nothing. pane key refuses every key, also a key that is a Ghostty keybind.

MCP server

macterm mcp is an MCP server for coding agents, for example Claude Code, Codex, Gemini CLI and OpenCode. The agent starts it and talks to it on stdin and stdout. It opens no network port.

Each tool is one method of the server protocol. The tools read and type into sessions, and change projects, tabs, panes, windows, widgets and layouts. The name of a tool is the name of its method with _ in place of .: the tool session_send is the method session.send. macterm api describe session.send shows the arguments of the tool session_send.

To add the server to an agent, run the command for that agent:

Agent Command or config
Claude Code claude mcp add --scope user macterm -- /Applications/Macterm.app/Contents/Resources/bin/macterm mcp
Codex codex mcp add macterm -- /Applications/Macterm.app/Contents/Resources/bin/macterm mcp
Gemini CLI gemini mcp add -s user macterm /Applications/Macterm.app/Contents/Resources/bin/macterm mcp
OpenCode Add "mcp": {"macterm": {"type": "local", "command": ["/Applications/Macterm.app/Contents/Resources/bin/macterm", "mcp"]}} to opencode.json.

For other agents (for example Cursor), add /Applications/Macterm.app/Contents/Resources/bin/macterm mcp to their MCP config as a stdio server. macterm mcp --help prints these commands.

macterm mcp also works while Macterm is not running. A tool call then fails, and the agent tells you to start Macterm. The next call finds the app. You do not need to start the agent again.

The server has two resources for the file formats that an agent writes:

Each resource is a JSON Schema with an example. An agent may read a resource only when you ask it to.

The server refuses input from an agent to a pane that reads a password, for example a sudo or ssh prompt. The agent then asks you to type the password. The server does not see every prompt: a program that reads a password in raw mode is not refused.

Agent skills

The MCP server replaces the agent skills of Macterm. If you installed them, remove them from the skills folder of your agent, then add the server. macterm skills now prints a notice and the commands above. A later release removes macterm skills.

Environment

Macterm exports these variables into every shell that it starts:

Variable Meaning
MACTERM_RUNTIME_DIR The folder of the session server and its socket. The CLI uses it to find the server.
MACTERM_SOCKET The path of control.sock, the frozen v1 socket of the app. The CLI uses it only for macterm askpass. See The v1 socket.
MACTERM_SESSION The own session name of the pane, for self-targeting.
PATH Macterm adds the Resources/bin of the bundle at the start.

Finding the server

The CLI talks to the session server of Macterm, not to the app. The server relays the commands that need the app, such as window and layout, to the app. The CLI never starts the server. It finds the socket of the server in this order:

  1. --socket <path>: this socket only.
  2. MACTERM_RUNTIME_DIR: the socket .server in this folder. Macterm sets it in every pane.
  3. The folder of each build of Macterm, the release build first: $TMPDIR/macterm/.server, then $TMPDIR/macterm-debug/.server. When XDG_RUNTIME_DIR is set, it replaces $TMPDIR. When neither is set, the folders are ~/.local/state/macterm/run and ~/.local/state/macterm-debug/run.

The first server that answers is the target. If that server refuses the CLI, the CLI stops. It does not try the next socket.

Exit codes

stdout has output only when a command succeeds. All other text goes to stderr.

Code Meaning
0 Success.
1 The server or the app returned an error.
2 No server answered, or the server runs and the app does not. If no server answered, stderr lists every socket path that the CLI tried.
64 The command line is not correct (a usage error).

status exits with 0 only when the app runs. To make a script wait until the app is ready, use this loop:

until macterm status >/dev/null 2>&1; do sleep 0.2; done

Scripting example

dev-up.sh
#!/bin/sh
set -e
mac=/Applications/Macterm.app/Contents/Resources/bin/macterm

# Wait for the app, then open the repo as a project.
until "$mac" status >/dev/null 2>&1; do sleep 0.2; done
"$mac" project create ~/dev/myapp --select

# A tab running the dev server, split for a test watcher.
"$mac" tab new --run "npm run dev"
"$mac" pane split --direction down --run "npm test -- --watch"

The server protocol

The CLI uses the protocol of the session server. macterm api list shows its methods, and macterm api describe <method> shows the arguments and the result of one method as JSON Schema. Both read the protocol of the CLI's own build, so they always match your version. macterm api call <method> --args '<json>' sends one request and prints the result:

macterm api list
macterm api describe tab.new

The arguments and the result use the keys of the protocol (snake_case).

The socket of the server has mode 0600 in a directory with mode 0700. The CLI refuses a socket that another user owns. Only the same user can use it. There is no token authentication.

The v1 socket

The app also keeps ~/Library/Application Support/Macterm/control.sock, the socket of Macterm v1. It is frozen: it gets no new commands. The CLI uses it only for macterm askpass. Scripts that speak the v1 protocol also use it. For a new script, use the CLI or macterm api call.

Use one request for each connection. Write one JSON line that ends with a newline. Close the write end of your connection. Read one line back.

request
{"v":1,"id":"<any-string>","command":"pane.split","args":{"direction":"down","run":"btop"}}

v is the minimum protocol version that the request needs. It is not the version of the client. Ordinary commands use 1. "focus":false needs "v":2. The app rejects a request version that it does not support before it does the command.

response
{"v":3,"id":"<echoed>","ok":true,"data":{"panes":[{"id":"…","session":"macterm-api-1a2b3c4d5e6f","index":2}]}}

A failure looks like {"ok":false,"error":{"code":"…","message":"…","action":"…"}}. The codes are starting, unknown_command, bad_request, not_found, ambiguous, busy, no_surface, read_only, unsupported_version, denied, cancelled and internal. Both sides ignore unknown fields.

echo '{"v":1,"id":"x","command":"status"}' | nc -U ~/Library/Application\ Support/Macterm/control.sock

control.sock has mode 0600 in a directory with mode 0700.