# 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>)

- 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/2d325b13709752ba6d9a943635c5e2940a2530c0/src/Aspire.Hosting/TerminalResourceBuilderExtensions.cs#L77-L116)

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. When neither [TerminalOptions.Columns](/reference/api/csharp/aspire.hosting/terminaloptions/properties.md#columns) nor [TerminalOptions.Rows](/reference/api/csharp/aspire.hosting/terminaloptions/properties.md#rows) is configured, opening the dashboard terminal automatically fits the grid to the view. Explicit dimensions retain the producer's current grid until the viewer requests a resize. Terminal host resources can be revealed using the dashboard's Show hidden resources control to inspect their state and diagnostic telemetry. Terminal host telemetry is disabled when [DistributedApplicationOptions.DisableDashboard](/reference/api/csharp/aspire.hosting/distributedapplicationoptions/properties.md#disabledashboard) is `true`.

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

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.
- Synchronous exports run on a background thread.
