Aspire

aspire terminal attach command

aspire terminal attach - Attach the local terminal to an interactive PTY session for a resource.

Aspire CLI
aspire terminal attach <resource> [options]

The aspire terminal attach command connects your local terminal to the interactive pseudo-terminal (PTY) session of a resource that was registered with WithTerminal(). Once attached, you interact with the resource’s terminal, as if it were running directly in your console. For example, you can drive its TUI or type into its shell.

The command discovers the running AppHost, verifies it supports the terminals.v1 capability, looks up the resource, and connects to one of its terminal replicas. A singleton resource accepts its display name or exact instance ID. A replicated resource requires an exact instance ID. Run aspire describe and use the desired replica’s value in the Name column. If a display name matches multiple instances, the command fails and lists their instance IDs instead of prompting for a replica.

Multiple peers can attach to the same session at once. By default, attach takes the primary role and drives the terminal’s dimensions. Pass --viewer to join as a passive viewer instead. This technique is useful when another peer, such as the dashboard, is currently driving the session.

While attached, the following hotkeys are available:

HotkeyAction
Ctrl+B DDetach from the session and exit cleanly.
Ctrl+B TTake control (request the primary role).

If the selected replica has already exited, the command attaches to the historical output buffer; no live input is sent.

The following arguments are available:

  • <resource>

    The resource display name for a singleton, or the exact resource instance ID for a replica. Use aspire describe to discover instance IDs. The resource must have been registered with .WithTerminal().

The following options are available:

  • --apphost <apphost>

    The path to the Aspire AppHost file or project file, such as apphost.mts, apphost.cs, or an AppHost .csproj.

  • --viewer

    Connect as a viewer (secondary) instead of taking primary control. Viewers see the terminal output but do not drive its dimensions. This option is useful when another peer (for example, the dashboard) is currently driving the session. Take control later with Ctrl+B T.

  • -?, -h, --help

    Prints help and usage documentation for the available commands and options.

  • -l, --log-level <Critical|Debug|Error|Information|None|Trace|Warning>

    Set the minimum log level for console output. Use this option to increase diagnostics while troubleshooting or reduce output in scripted runs.

  • --non-interactive

    Run the command in non-interactive mode, disabling all interactive prompts and spinners.

  • --nologo

    Suppress the startup banner and telemetry notice.

  • --banner

    Display the animated Aspire CLI welcome banner.

  • --wait-for-debugger

    Wait for a debugger to attach before running a command.

  • Attach to a resource’s terminal:

    Aspire CLI
    aspire terminal attach agent
  • Attach to an exact instance of a replicated resource. Replace agent-abc123 with an instance ID from aspire describe:

    Aspire CLI
    aspire terminal attach agent-abc123
  • Join an existing session as a passive viewer:

    Aspire CLI
    aspire terminal attach agent --viewer