Overview
Thebash tool runs shell commands with login-shell semantics and persists current working directory (cwd) and environment variables across tool calls within a loaf session.
Features
- State Persistence: Maintains cwd and environment variables across multiple bash tool calls
- Background Execution: Run long-running processes asynchronously with session management
- PTY Support: Full terminal emulation for interactive programs and TUIs
- Cross-Platform: Supports zsh/bash/sh on Unix and PowerShell/cmd on Windows
bash
Execute shell commands synchronously with automatic state capture.Parameters
Shell command text to execute.
Optional timeout in seconds (max 1200).
Optional starting working directory for this command. Also updates the tool session cwd baseline for subsequent calls.
Optional environment variable overrides for this command. Variables are persisted in the tool session.
Reset persisted bash tool cwd/env state before execution.
When true, start command asynchronously and return a background session ID.
Optional friendly name for a background bash session.
When
run_in_background is true, reuse an existing running session with same session_name and cwd.When
run_in_background is true, use a PTY terminal transport so TUIs/installers and key navigation work.PTY columns when
full_terminal=true (min 40, max 400).PTY rows when
full_terminal=true (min 10, max 200).Usage Example
Background Bash Tools
read_background_bash
Read buffered stdout/stderr from a running or exited background bash session.Parameters
Session ID returned by bash with
run_in_background=true.Max characters per stream to return (max 120000).
Stream selector:
both, stdout, or stderr.When true, do not advance internal read cursor.
Usage Example
write_background_bash
Write text or key input to a running background bash session.Parameters
Session ID returned by bash with
run_in_background=true.Text to write to stdin.
Optional special key name. See Special Keys below.
Repeat key presses when
key is provided.Append newline to input before writing.
Special Keys
The following special keys are supported:enter- Enter/Return keytab- Tab keyesc- Escape keyup,down,left,right- Arrow keyshome,end- Home and End keyspgup,pgdown- Page Up and Page Downbackspace,delete- Backspace and Delete keysctrl+c,ctrl+d,ctrl+z- Control key combinations
Usage Example
stop_background_bash
Stop a background bash session.Parameters
Session ID returned by bash with
run_in_background=true.When true, send SIGKILL. Default false (SIGTERM).
Usage Example
resize_background_bash
Resize terminal dimensions for a running PTY-backed background bash session.Parameters
Session ID returned by bash with
run_in_background=true.Terminal columns (40-400).
Terminal rows (10-200).
Usage Example
list_background_bash
List known background bash sessions and their state.Parameters
Include exited sessions.
Usage Example
PTY Mode
Whenfull_terminal=true is set for background bash sessions, the tool uses a PTY (pseudo-terminal) transport. This enables:
- Full ANSI color and formatting support
- Interactive TUI applications (vim, htop, etc.)
- Navigation with arrow keys and special keys
- Proper handling of terminal-aware installers
State Persistence
The bash tool maintains session state across calls:- Working Directory: Changes to cwd persist across bash tool invocations
- Environment Variables: Custom environment variables are maintained in the session
- Reset: Use
reset_session: trueto clear persisted state