Star ๅކๅฒ่ถ‹ๅŠฟ
ๆ•ฐๆฎๆฅๆบ: GitHub API ยท ็”Ÿๆˆ่‡ช Stargazers.cn
README.md

shell-use

shell-use is a rust powered cli for controlling, inspecting, testing, and recording shell sessions and terminal apps. It supports all standard terminal actions (send keys, mouse clicks) & user actions (screenshot, record sessions), & testing (matches screenshot, contains text). shell-use supports Windows, Linux, & macOS and it supports a wide range of shells (see Supported shells).

Install

install script

macOS / Linux:

curl --proto '=https' --tlsv1.2 -LsSf https://raw.githubusercontent.com/microsoft/shell-use/main/install/install.sh | sh

Windows PowerShell:

irm https://raw.githubusercontent.com/microsoft/shell-use/main/install/install.ps1 | iex

Use SHELL_USE_VERSION to select a specific version or SHELL_USE_INSTALL_DIR to select an install location.

homebrew (macOS/linux)

brew tap microsoft/shell-use https://github.com/microsoft/shell-use
brew install shell-use

winget (windows)

winget install Microsoft.ShellUse

download from releases

Download the latest release.

Quick start

Run a command and check the result:

shell-use open                  # start a shell session (auto-starts the daemon)
shell-use submit "echo hello"   # type the command, press Enter
shell-use wait command          # block until it finishes
shell-use expect text "hello"   # assert it showed up
shell-use expect exit-code 0    # assert it exited 0
shell-use close

Drive a full-screen TUI the same way:

shell-use run vim file.txt
shell-use wait idle             # let the screen settle
shell-use press i
shell-use type "some text"
shell-use press Escape : w q Enter
shell-use wait exit

Built for agents

shell-use is an AI native cli. Point yours at the built-in docs and it can serve itself the rest:

  • shell-use agent-context prints versioned JSON for every command, flag, enum, default, and exit code. It is generated from the cli, so it cannot drift from the real surface.
  • shell-use usage prints a one-screen cheatsheet.
  • shell-use skill prints the full workflow guide (SKILL.md).

Skill quick start

shell-use skill --add

Adds the shell-use skill to the location the user selects in the TUI.

Each command returns a stable exit code (see Exit codes), so an agent can tell an assertion failure from a missing session without scraping text.

Programmatic usage

shell-use has python & node client libraries that drive the daemon with the same commands as the cli. The shell-use binary still needs to be on your PATH (or pointed to with SHELL_USE_BIN). The clients manage the daemon for you, similar to the cli.

Python (shell-use)

pip install shell-use
import asyncio
from shell_use import ShellUse

async def main():
    async with ShellUse() as su:
        await su.open()
        await su.submit("echo hello")
        await su.wait_command()
        await su.expect_text("hello")
        await su.expect_exit_code(0)

asyncio.run(main())

Node / Deno / Bun (@microsoft/shell-use)

npm install @microsoft/shell-use # Node 20+

bun add @microsoft/shell-use # Bun

deno add npm:@microsoft/shell-use # Deno 2
import { ShellUse } from "@microsoft/shell-use";

const su = new ShellUse();
await su.open();
await su.submit("echo hello");
await su.waitCommand();
await su.expectText("hello");
await su.expectExitCode(0);
await su.close();

Note: On Windows, Deno requires all permissions (-A / --allow-all) instead of just --allow-read --allow-write due to the use of named pipes for IPC with the daemon.

Command reference

Global flags: --session <name> (env SHELL_USE_SESSION, default default), --json for machine-readable output, and --verbose/-v to log PTY traffic (see Debugging).

Session & lifecycle

CommandDescription
open [--shell S] [--cols N --rows N] [--cwd D] [--env K=V]Spawn a shell session.
run <program> [args...]Spawn a session running a program directly.
sessionsList active sessions.
close [--all]Close the current session (or all).
daemon status / daemon stopInspect / stop the daemon.

Inspection

CommandDescription
statecwd, size, cursor, last command + exit code, text snapshot.
text [--full]Plain text of the viewport (or scrollback).
screenshot [-o file.svg] [--full]Terminal text to stdout, or a crisp full-color SVG image (svg-term-style window) to a file.
cells X Y [W H]Per-cell attributes (char, fg, bg, flags).
get command|output|exit-code|cwd|cursor|sizeStructured getters.

Input

CommandDescription
type "text"Type literal text.
submit ["text"]Type then press the shell return key.
press <Key...>Named keys, e.g. press Escape : w q Enter, press Ctrl+C.
keys "Control+a"A single key combo.
mouse click X Y / mouse click --on-text "OK" [--clicks N]Click by coords or label.
mouse move|down|up|drag|scroll ...Full mouse control.

PTY

CommandDescription
resize COLS ROWSResize the PTY and emulator.
write <data>Write raw bytes (no return key).
signal INT|TERM|KILL / killSignal / kill the child.

Wait

CommandDescription
wait text "T" [--regex --full --not --timeout MS]Until text is (not) visible.
wait idleUntil the screen stops changing.
wait commandUntil the current command finishes.
wait exitUntil the session exits.

Expect (exit 0 = pass, 1 = fail)

CommandDescription
expect text "T" [--regex --full --no-strict --not --fg C --bg C --timeout MS]Visibility + optional color.
expect exit-code NLast command's exit code.
expect output "T" [--regex]Last command's captured output.
expect snapshot NAME [-u] [--include-colors]Compare against __snapshots__/NAME.snap.

Colors accept ANSI-256 (9), hex (#ff0000), or rgb (255,0,0).

Screenshots

Screenshots render a snapshot of the session in the current terminal by default, but can render an SVG using the -o output flag. Nerd Font icons are embedded as vector paths, so SVGs remain self-contained without changing the font stack for regular text.

full-color SVG screenshot of a TUI rendered by shell-use

Recording

Every session records automatically from the moment it opens, in the standard asciinema v2 cast format.

CommandDescription
get-recording [session]Print the session's recording (cast) to stdout.
shell-use get-recording > demo.cast   # capture the current session's recording
asciinema play demo.cast              # replay it
agg demo.cast demo.gif                # render a GIF

Live monitor

Watch a live session in a second terminal while an agent drives it. Both share the same daemon. monitor takes over an alternate screen and streams the session in full color at ~20fps; press q, Esc, or Ctrl-C to detach.

https://github.com/user-attachments/assets/741c985f-7861-41c5-9ceb-0f82f705b43f

CommandDescription
monitorAttach a live, full-color framed view of the session (--session selects which).
shell-use --session work monitor   # watch the 'work' session live

It needs an interactive terminal (exit 2 otherwise) and an existing session (exit 3 if none). The view reads only the shared screen state, so watching never blocks the commands the agent is running, and resizing the window just re-fits the frame.

Agents

CommandDescription
usageCompact command cheatsheet.
agent-contextVersioned JSON describing every command, flag, enum, default, and the exit-code taxonomy (generated from the CLI, so it can't drift).
skillLong-form workflow guide (SKILL.md).

Exit codes

Every command returns a stable exit code so an agent can branch on the failure class without parsing text:

CodeMeaning
0success
1assertion or wait condition not met (expect/wait)
2usage / invalid argument
3no active session (run open/run first)
4daemon or IPC error
5internal error

With --json, failures also carry a "kind" field (assertion/usage/no_session/internal).

Supported shells

  • bash
  • zsh
  • fish
  • PowerShell (powershell and pwsh)
  • xonsh
  • elvish
  • nushell
  • cmd

Comparison

shell-usetui-useterminal-use
LanguageRustTypeScript/NodeRust
Emulatoralacrittyxterm (headless)alacritty
Shell command trackingโœ… command boundaries, exit codes, cwdโŒโŒ
Testing / snapshotsโœ… expect text / output / exit-code / snapshotโŒโŒ
Color & per-cell attributesโœ… fg/bg, ANSI-256/hex/rgb, cellsโŒ plain text (+ highlights)via PNG
Image screenshotsโœ… SVGโŒโœ… PNG
Built-in recordingโœ… always-on asciinema cast + GIFโŒโŒ
Live monitor viewโœ…โŒโœ…
Stable exit-code taxonomy for agentsโœ…โŒโŒ
Python & JavaScript bindingsโœ…โŒโŒ
RuntimenativeNode.jsnative
PlatformsWindows + UnixWindows + UnixLinux / macOS

Debugging

By default the daemon writes no log. Start it with --verbose to record every byte read from and written to the PTY, plus lifecycle events, to ~/.shell-use/<session>.log.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

Trademarks

This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft's Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies.

ๅ…ณไบŽ About

๐Ÿ’ป Make the terminal / shell accessible for AI agents. Automate tasks with ease.
ai-toolsautomationbashclie2e-testingfishllmpowershellpwshshell-useterminaltestingtui

่ฏญ่จ€ Languages

Rust72.7%
Python12.5%
TypeScript8.4%
JavaScript3.2%
Shell0.9%
PowerShell0.9%
Ruby0.5%
Elvish0.4%
Nu0.3%
Xonsh0.2%

ๆไบคๆดป่ทƒๅบฆ Commit Activity

ไปฃ็ ๆไบค็ƒญๅŠ›ๅ›พ
่ฟ‡ๅŽป 52 ๅ‘จ็š„ๅผ€ๅ‘ๆดป่ทƒๅบฆ
34
Total Commits
ๅณฐๅ€ผ: 10ๆฌก/ๅ‘จ
Less
More

ๆ ธๅฟƒ่ดก็Œฎ่€… Contributors