Skip to main content

Overview

The ACP SDK allows agents to create terminals and execute commands in the client’s environment. This enables agents to run build tools, tests, scripts, and other command-line operations.
Terminal operations are only available if the client advertises the terminal capability during initialization.

Creating Terminals

The createTerminal method executes a command in a new terminal:
string
required
The session ID creating the terminal
string
required
The command to execute
string[]
Optional command arguments
string
Optional working directory for the command
Record<string, string>
Optional environment variables
object
required
A handle to control and monitor the terminal
Returns a TerminalHandle that can be used to get output, wait for exit, kill the command, or release the terminal.

Example

TerminalHandle Class

The TerminalHandle class provides methods to control and monitor a terminal:

currentOutput

Gets the current terminal output without waiting for the command to exit.
string
required
The current output from the terminal
number
The exit code if the command has already exited
string
The signal that terminated the process, if applicable

Example

waitForExit

Waits for the terminal command to complete and returns its exit status.
number
The exit code of the process
string
The signal that terminated the process, if applicable
This method blocks until the command completes, providing the exit code and/or signal that terminated the process.

Example

kill

Kills the terminal command without releasing the terminal.
The terminal remains valid after killing, allowing you to:
  • Get the final output with currentOutput()
  • Check the exit status
  • Release the terminal when done
Useful for implementing timeouts or cancellation.

Example

release

Releases the terminal and frees all associated resources.
If the command is still running, it will be killed. After release, the terminal ID becomes invalid and cannot be used with other terminal methods. Tool calls that already reference this terminal will continue to display its output.
Always call release() when done with the terminal to free resources.

Example with await using

The TerminalHandle class supports async disposal via Symbol.asyncDispose, allowing automatic cleanup:

Embedding Terminals in Tool Calls

Terminals can be embedded in tool calls by using their ID in ToolCallContent with type “terminal”:

Error Handling

Handle errors appropriately when working with terminals:

Complete Example

Here’s a complete example that demonstrates terminal operations:

Best Practices

Always Release

Always call release() when done to free resources, or use await using

Handle Timeouts

Implement timeouts using kill() to prevent commands from running indefinitely

Check Capabilities

Verify the client supports terminal operations before attempting to use them

Capture Output

Get final output after waitForExit() for complete command results