terminal-use
terminal-use
An MCP server that lets an AI agent use a real terminal the way a person does: type, press keys, click, read the screen, take a screenshot.

Every frame above was drawn by terminal-use's own screenshot renderer; the caption on each is the tool call that produced it.
Most agent shell tools run a command and hand back its output. That breaks down for anything interactive — vim, htop, a REPL, an installer asking questions, git rebase -i, an SSH session. terminal-use gives the agent a shell on a real pseudo-terminal, rendered by a real terminal emulator, so full-screen and interactive programs work and the agent sees what you would see.
Real PTY, real emulator — colors, cursor movement and the alternate screen are interpreted, not passed along as escape codes.
Text and pixels — read the screen as plain text, or as a PNG when layout and color matter.
Waits properly — block until a command actually finishes, or until some text appears.
Watch along — attach your own terminal to any session and type alongside the agent.
Quick start
Requires Node.js 22.12 or newer, on macOS, Linux or Windows.
Pick your client:
Client | How to add it |
Claude Code |
|
Cursor | |
VS Code | |
Codex |
|
Gemini CLI |
|
Claude Desktop, and any other client that takes a command: add this to its MCP configuration (for Claude Desktop: Settings → Developer → Edit Config).
{
"mcpServers": {
"terminal-use": {
"command": "npx",
"args": ["-y", "terminal-use"]
}
}
}Start a new session in your client and ask it to do something in a terminal, for example: "Open vim, write a haiku into /tmp/haiku.txt, save and quit, then show me a screenshot of cat-ing it."
Server options go after the command: npx -y terminal-use --cols 100 --rows 40.
Option | Default | |
|
| Shell to run in new sessions |
| where the server was started | Working directory for new sessions |
|
| Terminal size |
|
| Lines of history kept |
| off | Start shells as login shells (see below) |
"command not found" inside a session
If programs that work in your own terminal (node, brew, pyenv…) are missing inside a session, the server probably inherited a bare environment. That happens when the MCP client is started from the Dock or a launcher instead of a terminal: your PATH is set up by your shell's profile files (~/.zprofile, ~/.bash_profile, ~/.profile), and nothing has read them.
A login shell reads those files. Turn it on for every session with the --login server flag, or for one session with login: true on terminal_create. It is off by default because it makes each shell slower to start and runs whatever your profile runs. It has no effect in PowerShell or cmd.exe, which have no login mode.
Related MCP server: can-see
Tools
Every tool except terminal_create and terminal_list takes the sessionId that terminal_create returns.
Tool | What it does |
| Start a session: an interactive shell, or one program with |
| List sessions. |
| End a session. |
| Type text. |
| Press a key or combination: |
| Wait for the running command to finish, for a regex to appear, or for output to go quiet. |
| Read the screen or scrollback as text. |
| Render the screen as a PNG. |
| Left-click a cell, with a preview step. |
| Turn the mouse wheel over a cell. |
| Send several inputs in one call and get the screen back once. |
| Change the terminal size. |
| Clear the screen and scrollback, or restart the shell with |
Docker
The repository has a Dockerfile for running the server in a container:
docker build -t terminal-use .
docker run -i --rm -v "$PWD":/workspace terminal-useIn an MCP client, use docker as the command with run -i --rm terminal-use as its arguments. The terminals the agent gets are then shells inside the container, not on your machine: it sees only what you mount, which is the point if you want it boxed in. Attaching from your own terminal is not available in this setup.
The skill
terminal-use comes with an Agent Skill: a short guide for the agent on how to use these tools well — when to use a command session, how to wait, how to read what is selected — plus recipes for vim, pagers, REPLs, menu-driven programs, ssh prompts and end-to-end testing of a TUI. It lives in skills/terminal-use.
Hosts that load skills from MCP servers get it automatically. The server implements the MCP Skills extension (
io.modelcontextprotocol/skills): the skill is listed byskills/listand its files are served asskill://terminal-use/...resources. Few hosts support this yet.Hosts that load skills from disk can install the same files. For Claude Code:
cp -r "$(npx -y terminal-use skills-dir)/terminal-use" ~/.claude/skills/
The skill is optional. Without it the agent still has the tool descriptions and the server's built-in instructions.
Shell sessions and command sessions
By default a session is an interactive shell: type commands into it as you would at a prompt.
Pass command to terminal_create to run one program in the terminal instead:
{"command": "npm test -- --watch", "cwd": "/path/to/project", "env": {"CI": "1"}}The command goes through the session's shell (sh -c, PowerShell -Command, or cmd /c), so quoting, pipes and redirection work as they do at that shell's prompt. Input goes straight to the program. When it exits:
its exit status is reported (by the call that was in progress, by
terminal_wait, and interminal_list);the final screen stays readable with
terminal_readandterminal_screenshot;input tools return an error with the exit status rather than restarting anything;
terminal_resetwithhardReset: trueruns it again, andterminal_destroyremoves it.
This is the mode for testing a CLI or TUI: launch it, drive it, check how it ended.
Watching and typing along
terminal_create returns a command you can run in your own terminal to join the session:
node /path/to/terminal-use/bin/terminal-use.js attach 3 --socket /tmp/terminal-use-501/41234-3.sockYou see what the agent sees and can type into the same shell. It works like a shared tmux session: several people can attach at once, and Ctrl+] detaches.
You get the current screen and recent scrollback on connect, not a blank terminal.
--resizemakes the session follow your window size. By default the session keeps its own.--socketpicks the server. Each MCP client runs its own terminal-use, and they all number sessions from 1; without--socket,attach <id>works when only one running server has that id and lists the candidates otherwise.On Windows the session is reached through a named pipe instead of a socket file; the command you are given works the same way.
Sockets are per-user (
0600, inside a0700directory under the system temp dir). Anyone who can connect gets a shell as you, so they are not exposed any further than that.
How it works
agent ──MCP──▶ terminal-use ──▶ node-pty ──▶ your shell
│
└─ @xterm/headless ◀── everything the shell prints
│
├─ terminal_read (text)
└─ terminal_screenshot (PNG)node-pty runs the shell on a pseudo-terminal. Everything it prints is fed to a headless xterm.js emulator, and that emulator's buffer is the single source of truth: reads and screenshots both come from it, so the agent gets the rendered screen rather than a stream of escape codes.
Details
Waiting for things
terminal_type, terminal_press and terminal_click return once output has been quiet for a moment (idleMs, default 200 ms) and never wait longer than 10 seconds. That suits keystrokes. It doesn't suit a build, which can be silent for a while long before it is done. For anything slow, follow up with terminal_wait:
Default — wait for the command to finish. terminal-use asks the kernel which process owns the terminal's foreground. A shell hands the terminal to each command it runs and takes it back afterwards, so when the shell owns it again, the prompt is back. This needs no shell integration or prompt parsing, and works for commands that print nothing.
pattern— wait for a regex to match the screen. For things that never exit (Listening on port), REPL prompts, or a particular state of a TUI.^and$match at line starts and ends; a leading(?i)or(?s)sets further flags.until: "quiet"— wait for output to stop forquietMs(default 1 s). The same rule the typing tools use, without the 10-second cap.
In a command session, the default mode waits for the program to exit and reports its exit status.
timeoutMs defaults to 30 seconds (maximum 10 minutes). A timeout isn't an error: the response says the command is still running, and you can wait again.
On Windows there is no way to ask who owns the terminal, so in a shell session the default mode waits for two seconds of silence instead, and says it is a guess. Prefer a pattern there, or run the program as a command session, where waiting for it to exit works on every platform.
Limits worth knowing: background jobs (cmd &) don't count as running. Inside a nested program such as ssh or a REPL, the outer shell doesn't get the foreground back until that program exits, so use pattern or until: "quiet" there. No exit status is reported; run echo $?.
Reading the screen
terminal_read returns text in screen-sized pages: page: 0 is the current screen, page: 1 the one before it, and so on back through scrollback.
Lines the terminal wrapped at its right edge are joined back into the single line the program printed (joinWrapped: false gives one line per screen row).
Text can't show color, so it can't show which menu entry is selected. Reads therefore end with a list of what is highlighted on screen — text in reverse video or on a background color — with the row and columns terminal_click takes:
Highlighted on screen (reverse video or background color; screen row, columns):
row 7, cols 3-18: "Unstaged changes"If most of the screen is colored panels, the list is replaced by a pointer to terminal_screenshot. Turn it off with highlights: false.
The cursor is marked with ▌. On an empty cell it simply takes the place of the blank. On a character it is inserted in front of that character, which shifts the rest of that one line right by a column; the header says which character it is on. The marker is left out while the program hides the cursor (most full-screen programs do), and cursor: false returns the text untouched.
Screenshots
terminal_screenshot renders the screen with the bundled JetBrains Mono. This is what a call returns, here with a visual selection in vim:

Sessions take a theme at creation: dark (default), light, solarized-dark or solarized-light.
JetBrains Mono covers Latin, Greek, Cyrillic, box-drawing and common symbols. Emoji, Chinese/Japanese and Korean text fall back to fonts already on the system, because bundling them would add tens of megabytes:
Emoji | CJK | Hangul | |
macOS | Apple Color Emoji | Hiragino Sans GB / PingFang | Apple SD Gothic Neo |
Windows | Segoe UI Emoji | Microsoft YaHei / Yu Gothic | Malgun Gothic |
Linux | Noto Color Emoji | Noto Sans CJK | Noto Sans CJK |
macOS has these out of the box, and Windows has the emoji font (the East Asian fonts come with the matching language features). On Debian or Ubuntu, install them with apt install fonts-noto-color-emoji fonts-noto-cjk. Without them (a bare Docker image, say) those characters render as empty boxes in screenshots. Nerd Font and Powerline icons render as boxes everywhere. terminal_read is unaffected and always returns the real characters.
Typing, pasting and batching
terminal_type sends characters as keystrokes. For multi-line text going into an editor, a REPL or a shell prompt, add paste: true: programs that support bracketed paste receive it as one paste and insert it verbatim, without auto-indenting or running each line as it arrives. Programs that don't support it get the plain characters.
terminal_batch sends a list of inputs in one call and returns the screen once at the end, which saves a round trip per keystroke when the steps are already known:
{
"sessionId": 1,
"actions": [
{"type": "press", "key": "ArrowDown", "count": 3},
{"type": "press", "key": "Enter"},
{"type": "wait", "pattern": "Commit message"},
{"type": "type", "text": "Fix typo"},
{"type": "press", "key": "Ctrl+S"}
]
}Actions are type, paste, press, click, scroll and wait (a fixed ms, or a pattern to appear). The batch is checked before anything is sent, and stops at the first action that fails, reporting how far it got.
Clicking and scrolling
Left button only. Coordinates are 1-indexed;
(1, 1)is the top-left cell.previewis on by default. A preview returns a screenshot with a ring drawn around the target cell and sends no click. Repeat the call withpreview: falseto click. Full-screen programs often have destructive actions one click away, so it is worth the extra step.terminal_scrollturns the wheel over a cell. Programs that track the mouse get wheel events there, so the pane under the pointer scrolls; full-screen programs that don't (less,man) get arrow keys, as in a normal terminal. At a shell prompt there is nothing to scroll — read earlier output withterminal_readandpage.A real click needs the program to have turned on mouse reporting —
vimwithset mouse=a,fzf,lazygit,htopand most modern TUIs do. At a plain shell prompt the call returns an error instead of printing escape codes into your command line.
Session lifecycle
Sessions are independent. Calls to one session run in order; calls to different sessions don't block each other.
If a shell session's shell exits, the session sits idle for six hours, or the 50-session limit is reached, the session is shut down but its id stays reserved for 30 days. The next call to that id starts a fresh shell with the same size, shell, working directory and theme, and returns a notice saying what happened — including the last screen the old shell printed, if it exited on its own. The command in that call is not run; send it again if you still want it.
Idle means no tool calls and no output. A dev server that is still printing is not idle.
terminal_destroyends a session for good; its id is not reserved.When the MCP client disconnects or the server is stopped, every shell is closed and every attach socket removed.
Protocol support
Built on the official MCP TypeScript SDK (v2). Over stdio it speaks both the 2026-07-28 revision of the protocol, which is stateless, and the earlier handshake-based revisions; the client's first message decides which.
Stateless refers to the protocol, not the terminals: sessions live in the server process and are addressed by the sessionId you pass on each call. The server also provides usage instructions, titles and behavior hints for each tool, cancellation, progress updates from terminal_wait, and the Skills extension described above.
Platform support
macOS (arm64, x64) | Supported; tested in CI |
Linux (arm64, x64) | Supported; tested in CI on Node 22 and 26 |
Windows (x64) | Supported; tested in CI against PowerShell and |
On Windows, sessions run through ConPTY, the default shell is Windows PowerShell, and two things differ: terminal_wait cannot detect that a shell command has finished (see Waiting for things), and login does nothing.
The native dependencies (node-pty, @napi-rs/canvas) ship prebuilt binaries, so no compiler is needed to install.
Development
git clone https://github.com/computer-agent-labs/terminal-use.git
cd terminal-use
yarn install
yarn build # compile src/ to dist/
yarn test # build, then run the full suiteOther scripts:
yarn dev # run the server straight from source
yarn lint # eslint
yarn typecheck # tsc, no output
yarn test:unit # unit tests only
yarn test:windows # what CI runs on Windows: shell-independent tests + tests/windows
yarn smoke # quick end-to-end check without an MCP client
yarn demo # regenerate docs/demo.gif (needs ffmpeg, vim and python3)To point your MCP client at a local checkout, build it and use the path to the bin script:
claude mcp add terminal-use --scope user -- node "$PWD/bin/terminal-use.js"The code is laid out by layer: src/pty (spawning, key and mouse encoding), src/emulator (the xterm buffer, rendering, waiting), src/session (one terminal), src/attach (the socket you attach through) and src/mcp (the tools). The agent skill is in skills/.
Security
terminal-use gives the connected client a shell on your machine, running as you, with no sandbox. Connect it only to clients you would trust with a terminal, and use your client's tool-approval settings to control what runs unprompted. It opens no network ports; attach sockets are restricted to your own user. See SECURITY.md for details and for how to report a vulnerability.
Contributing
Issues and pull requests are welcome. CONTRIBUTING.md covers setting up, running the tests, and what a good pull request looks like. This project follows the Contributor Covenant.
License
MIT. The bundled JetBrains Mono fonts are licensed under the SIL Open Font License.
Available Tools
13 toolsterminal_batchRun several terminal inputsADestructive
Send a sequence of inputs in one call and get the screen back once at the end — for driving a full-screen program without a round trip per keystroke (open a menu, move down three, press Enter, type a name, confirm). Actions run in order, each given a moment to take effect before the next.
Each action is an object with a type and the fields that type uses:
type:text— typed as keystrokes; \n presses Enter.paste:text— delivered as one bracketed paste where the program supports it.press:key, optionalcount— same key specs as terminal_press.click:col,row— left click, sent immediately with no preview; needs the program to track the mouse.scroll:direction, optionalamount,col,row— as terminal_scroll.wait:msfor a fixed pause, orpattern(optionaltimeoutMs) to continue once a regex matches the screen.
The batch is validated before anything is sent. It stops at the first action that fails (a pattern that never appears, a click the program cannot receive, the process exiting) and reports how far it got, with the screen as it stands. Use it when you already know the steps; when you need to look between steps, use the individual tools.
Inputs: actions (required), sessionId (required), idleMs, maxWaitMs, +1 more.
terminal_clickClick in terminalADestructive
Deliver a left mouse-button click at a cell in the terminal. Only works when the program currently in the foreground has opted into mouse tracking (vim with set mouse=a, fzf, lazygit, less with mouse mode, etc.) — at a plain shell prompt mouse mode is off and the click would just print escape sequences as text, so we refuse the actual click in that case.
Coordinates are 1-indexed and refer to the live screen viewport: col 1, row 1 is the top-left cell, and the bottom-right cell is (terminal width, terminal height) which you can see via terminal_read's state header.
PREVIEW MODE (default preview: true): does NOT click. Returns a PNG with a bright magenta ring + dot drawn around the target cell so you can verify your coordinates. Always do this first when you are not 100% sure where the click should land — TUIs often have destructive actions one click away (delete branch, kill process, etc.).
EXECUTE MODE (preview: false): actually sends the mouse press+release sequence and settles for output. Use this only after you've previewed and confirmed, or when you're confident.
CAVEATS: idleMs and maxWaitMs are ignored in preview mode (preview doesn't settle). When the target cell is near the right edge of the viewport, the coordinate label drawn next to the magenta ring may be clipped — the ring itself is always within frame, so trust it over the label.
Inputs: col (required), row (required), sessionId (required), idleMs, +3 more.
terminal_createCreate terminal sessionA
Spawn a new terminal session and return its sessionId. You must call this before any per-session tool — there is no shared default session. By default the session is an interactive shell. Pass command to run one program in the terminal instead (a TUI, a test run, a CLI under test): the session then lasts as long as that program, reports its exit status when it ends, and keeps its final screen readable until you destroy it. If the server already holds 50 live sessions, the least-recently-used one is evicted to make room (its sessionId is tombstoned and any later call against it will respawn with an 'evicted' notice).
Inputs: cwd, env, cols, rows, +6 more.
terminal_destroyDestroy terminal sessionADestructive
Kill a session and forget the sessionId entirely. The shell process is terminated and the sessionId is not tombstoned — future calls against it will error with "Unknown sessionId". Use this when you're explicitly done with a session. Tombstones (which auto-respawn on next access) only happen for system-driven terminations: idle-kill, eviction, or shell exit.
Inputs: sessionId (required).
terminal_listList terminal sessionsARead-onlyIdempotent
List every active session and every tombstoned (recently-killed but reserved) sessionId. Tombstones are reservations: the shell is gone but the sessionId can still be called against — doing so respawns a fresh shell under the same id and surfaces the original termination reason (shell-exit, idle-killed, or evicted). Tombstones expire after 30 days; after that the id is gone.
Inputs: no named parameters.
terminal_pressPress key in terminalBDestructive
Press a single named key or key combination. Examples of supported key values: Enter, Tab, Escape, Backspace, Space, ArrowUp / ArrowDown / ArrowLeft / ArrowRight, Home, End, PageUp, PageDown, Delete, Insert, F1..F12, Ctrl+C, Ctrl+D, Ctrl+L, Ctrl+A..Ctrl+Z, Shift+Tab, Alt+B, Ctrl+ArrowLeft, Ctrl+Shift+ArrowRight, etc. Same settle behavior as terminal_type.
Inputs: key (required), sessionId (required), count, idleMs, +1 more.
terminal_readRead terminal textARead-onlyIdempotent
Read a window of the terminal buffer. The buffer is the full xterm-emulated state (scrollback + visible viewport) in one contiguous index space. The window is paged from the bottom upward in multiples of rows. rows defaults to the current screen height and is capped at 1000. page: 0 is the most recent screen-sized chunk; page: 1 is the screen before that, and so on. Trailing blank rows are trimmed implicitly.
Inputs: sessionId (required), page, rows, cursor, +2 more.
terminal_resetReset terminalADestructive
Wipe the terminal buffer and scrollback. By default the shell process keeps running (env vars, cwd, history all preserved). Pass hardReset: true to kill the current shell and spawn a brand-new one — anything mid-execution gets killed. When hardReset: true, you can also override cols, rows, shell, and cwd. In a session created with command, a hard reset runs that command again.
Inputs: sessionId (required), cwd, cols, rows, +2 more.
terminal_resizeResize terminalAIdempotent
Change the terminal size. Both cols and rows are optional; omitting one preserves the current value. Resizes both the PTY and the emulator (so programs running inside see the change via SIGWINCH).
Inputs: sessionId (required), cols, rows.
terminal_screenshotScreenshot terminalARead-onlyIdempotent
Render a screen-sized window of the terminal to a PNG. Height is always the current screen height (term.rows); use page to walk back through scrollback in screen-sized increments at the same dimensions as the live screen. If filePath is set, the PNG is written there and the path is returned. Large images (>2097152 bytes) are also spilled to a temp file automatically.
Inputs: sessionId (required), page, filePath.
terminal_scrollScroll in terminalA
Turn the mouse wheel over a cell of a full-screen program: scroll a pager, a file list, a log pane. Behaves as a terminal emulator does — programs that track the mouse receive wheel events at that cell (so the pane under it scrolls); full-screen programs that do not (less, man) receive arrow keys instead. At a plain shell prompt there is nothing to scroll and the call fails: earlier output is read with terminal_read and its page argument, not by scrolling.
Inputs: direction (required), sessionId (required), col, row, +3 more.
terminal_typeType into terminalADestructive
Type literal characters into the terminal as if a human were pressing keys. Embedded \n is normalized to \r so "git push\n" actually submits. Always waits for the buffer to settle (or to time out) before returning. The wait is capped at 10s; for anything slower (builds, installs, test runs) follow up with terminal_wait, which blocks until the command actually finishes.
Inputs: text (required), sessionId (required), paste, idleMs, +1 more.
terminal_waitWait for terminalARead-onlyIdempotent
Block until the terminal reaches a state, instead of guessing with sleeps or polling terminal_read. Use it after terminal_type for anything that outlives the settle window: builds, installs, test runs, servers starting up.
DEFAULT (no pattern): waits for the running command to finish — i.e. for the shell to take the terminal's foreground back and its prompt to go quiet. This asks the kernel who owns the terminal, so it works with any prompt and stays correct while a command is silent (sleep 60) or chatty. Returns immediately if the shell is already at its prompt. On Windows this cannot be detected in a shell session: the call waits for a stretch of silence instead and says so — prefer pattern there. In a session created with command, it waits for that command to exit and reports its exit status. Background jobs (cmd &) do not count as running, and inside a nested program (ssh, a REPL, a TUI) the outer shell never regains the foreground until that program exits — use pattern there.
until: "quiet": waits until nothing has been printed for quietMs (default 1000), whatever owns the terminal. This is the same "settled" rule terminal_type uses, without its 10s cap — for nested programs where completion cannot be detected and no pattern fits.
WITH pattern: waits until the regex matches the text on screen (the viewport plus the 200 rows above it). Use this for servers that never exit ("Listening on"), REPL prompts, or TUI states. Text that is already on screen counts, so pick a pattern that only the new output can satisfy.
Returns the screen when the condition is met, or when timeoutMs runs out (not an error — the response says the command is still running). In a shell session this does not report an exit status; run echo $? afterwards if you need it.
Inputs: sessionId (required), until, pattern, quietMs, +1 more.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 13 tools
Each tool has a clearly distinct purpose: session lifecycle (create/destroy/list/reset/resize), input (type/press/click/scroll/batch), output (read/screenshot), and synchronization (wait). The main overlap is terminal_batch, which can perform everything type/press/click/scroll do, but descriptions explicitly steer the agent (batch for known sequences, individual tools when you need to look between steps), so confusion is limited.
Every tool follows the same terminal_<verb> snake_case pattern (terminal_create, terminal_read, terminal_wait, etc.), with no deviations in case or verb style. The naming is entirely predictable.
13 tools is comfortably within the ideal 3-15 range for a terminal automation server. Each tool maps to a genuine, non-redundant capability (session management, multiple input modalities, output capture, and blocking waits).
The surface covers the full session lifecycle (create/destroy/list/reset/resize) plus input, output, and synchronization primitives, which is close to complete for driving a terminal. Minor gaps remain, such as no standalone paste tool outside batch and no explicit signal/interrupt tool beyond terminal_press Ctrl+C.
Maintenance
Related MCP Connectors
Remote desktop MCP: let AI see, click, type and run terminal commands on your own Windows or Mac.
1Make games with AI: one MCP server that connects your agent to Unity, Unreal and Godot editors.
Hosted Screenshots MCP server for Claude, ChatGPT and Cursor, with each action switched per account.
Related MCP Servers
- AlicenseAqualityDmaintenanceAn MCP server that lets AI agents launch, interact with, and inspect Textual TUI applications headlessly.124MIT
- AlicenseNot gradedqualityDmaintenanceMCP server that lets AI agents see and interact with terminal/CLI applications through virtual terminals and PNG screenshots.124 npmMIT
- AlicenseAqualityDmaintenanceMCP server that gives AI agents real interactive terminal sessions for running REPLs, SSH, database clients, and any interactive CLI with clean text output and smart completion detection.785 npm20MIT
- AlicenseBqualityDmaintenanceLocal + remote terminal interaction control MCP Server. Lets AI agents control interactive TUI programs the way a human would.297 npmMIT