Skip to content

Shell & Process Tools

Execute commands and manage long-running processes

The Shell & Process category includes 6 tools for running commands, managing background processes, and delegating complex coding tasks.

Execute a shell command with PTY support. Returns stdout and exit code. If the command waits for input, returns waiting_for_input=true with a session_id for follow-up interaction.

ParameterTypeRequiredDescription
commandstringYesShell command to execute
timeoutintNoTimeout in seconds (default: 120, max: 3600)
working_dirstringNoWorking directory
backgroundboolNoStart in background, return session_id immediately

Read output from a running or completed process. Use offset for incremental reads to avoid re-reading previous output.

ParameterTypeRequiredDescription
session_idstringYesSession ID from shell_command
offsetintNoByte offset to start reading from

Send input to a running process. Always include a trailing \n to simulate pressing Enter.

ParameterTypeRequiredDescription
session_idstringYesSession ID of the process
inputstringYesText to send (include trailing \n)

List all active and recent process sessions.

ParameterTypeRequiredDescription
filterstringNoFilter by command or session ID

Kill a running process. Sends SIGTERM first, followed by SIGKILL after 5 seconds if the process does not exit.

ParameterTypeRequiredDescription
session_idstringYesSession ID to kill

Delegate a task to OpenCode, a specialized AI coding agent. OpenCode can read and write files, run commands, search code, and perform complex software engineering tasks autonomously.

ParameterTypeRequiredDescription
taskstringYesTask description with full context
dirstringYesProject root directory
session_idstringNoContinue an existing OpenCode session
modelstringNoOverride model (provider/model format)
agentstringNoAgent type: build (default, full access) or explore (read-only)

Use the process tools together to manage long-running commands like dev servers, watchers, or test suites:

  1. Start a background process — call shell_command with background=true. You get back a session_id immediately without waiting for the command to finish.

  2. Check output periodically — call process_read with the session_id. Use offset to read only new output since your last check, avoiding duplicate data.

  3. Send input when needed — call process_write to respond to prompts or send commands to interactive processes. Always include a trailing \n.

  4. Clean up — call process_kill when the process is no longer needed. This frees up the session and terminates the underlying command.

shell_command (background=true)
|
v
session_id
|
+---> process_read (offset=0) --> read initial output
+---> process_read (offset=1024) --> read new output
+---> process_write ("yes\n") --> respond to prompt
+---> process_kill --> terminate