# TerminalResourceBuilderExtensions Methods

- Package: [Aspire.Hosting](/reference/api/csharp/aspire.hosting.md)
- Type: [TerminalResourceBuilderExtensions](/reference/api/csharp/aspire.hosting/terminalresourcebuilderextensions.md)
- Kind: `Methods`
- Members: `1`

Provides extension methods for configuring interactive terminal support on resources.

<a id="withterminal"></a>
<a id="withterminal-iresourcebuilder-t-action-terminaloptions"></a>

## WithTerminal(IResourceBuilder<T>, Action<TerminalOptions>)

> **Experimental:** ASPIRETERMINAL001 - [Learn more](/diagnostics/aspireterminal001/)

- Name: `WithTerminal(IResourceBuilder<T>, Action<TerminalOptions>)`
- Modifiers: `extension`
- Returns: [IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md)
- Source: [GitHub](https://github.com/microsoft/aspire/blob/b5f143315ffb6968ea939a9978797a5b20e4c688/src/Aspire.Hosting/TerminalResourceBuilderExtensions.cs#L70-L110)

Configures a resource to expose an interactive terminal session.

```csharp
public static class TerminalResourceBuilderExtensions
{
    public static IResourceBuilder<T> WithTerminal<T>(
        this IResourceBuilder<T> builder,
        Action<TerminalOptions>? configure = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` ([IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md))
  The resource builder.
- `configure` (`Action<TerminalOptions>`) `optional`
  An optional callback to configure the terminal options.

## Returns

[IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md) -- A reference to the `ApplicationModel.IResourceBuilder`1` for chaining additional configuration.

## Remarks

When a resource is configured with `.WithTerminal()`, DCP allocates a pseudo-terminal (PTY) per replica and a hidden terminal host process bridges the PTY traffic over Hex1b's HMP v1 protocol. The terminal session can be accessed from the Aspire Dashboard's terminal page or via the `aspire terminal` CLI command.

One terminal host process is spawned per parent replica (e.g. `WithReplicas(3).WithTerminal()` → 3 terminal host processes named `{parent}-terminalhost-0` .. `{parent}-terminalhost-2`). The order of `WithReplicas(...)` and `WithTerminal()` does not matter: the per-replica hosts are materialized during [BeforeStartEvent](/reference/api/csharp/aspire.hosting/beforestartevent.md) after the model is fully built, so the final replica count is always honoured.

## Examples

### Example 1

Add terminal support to an executable resource:

```csharp
var agent = builder.AddExecutable("agent", "my-agent", ".")
    .WithTerminal();
```

### Example 2

Add terminal support with custom dimensions to a multi-replica resource. The order of WithReplicas and WithTerminal does not matter:

```csharp
var agent = builder.AddExecutable("agent", "my-agent", ".")
    .WithReplicas(3)
    .WithTerminal(options =>
    {
        options.Columns = 200;
        options.Rows = 50;
    });
```

## ATS metadata

### Ignored by ATS

- Reason: Polyglot AppHosts use the parameterless withTerminal dispatcher export.
