---
title: "Attach to an existing command"
description: "Replays retained output for an existing execution identity without dispatching it again, then follows it to a final result."
canonical: "https://www.cool.computer/docs/api-reference/execution/attach-to-an-existing-command"
---
# Attach to an existing command

> Replays retained output for an existing execution identity without dispatching it again, then follows it to a final result.

```http
POST https://api.cool.computer/api/computers/{id}/exec/attach
```

Replays retained output for an existing execution identity without dispatching it again, then follows it to a final result. Output and drop frames have monotonic replay cursors. The final exit frame is cursorless and is always returned for a completed execution, including when after_id equals the execution's last allocated cursor. An after_id beyond that cursor fails with invalid_execution_cursor.

## Authorization

- A Cool Computers API key, user access token, or claimed agent access token in the Authorization header. Follow https://www.cool.computer/auth.md for agent registration and https://www.cool.computer/authentication.md for direct user credentials.

## Parameters

- `id` (path, string, at least 1 characters, required): The computer's name, such as agent-atlas, or its id (cmp_…). Every caller may use either, the computer's own runtime token included.

## Request body

Required.

- `application/json` (object)
  - `execution_id` (string, pattern `^cmp_[0-9a-f]{24}\.exec\.[0-9a-f]{32}$`, required): The exact existing execution identity bound to the target computer. Attaching never launches a command.
  - `after_id` (integer, at least 0): Replay only output and drop frames after this cursor. The last allocated cursor is valid and still returns the stored final result; a greater value fails with invalid_execution_cursor.

## Responses

- `200`: Newline-delimited replay and one final result for the same execution identity.
  - `application/x-ndjson` (object)
    - `execution_id` (string, pattern `^cmp_[0-9a-f]{24}\.exec\.[0-9a-f]{32}$`, required)
    - `id` (integer, at least 1): Monotonic replay cursor present only on stdout, stderr, and drop frames.
    - `timestamp` (string, date-time)
    - `type` ("pid" or "stdout" or "stderr" or "drop" or "exit" or "error", required)
    - `status` ("running" or "succeeded" or "failed" or "cancelled" or "owner_lost")
    - `pid` (integer, at least 1)
    - `stdout` (string)
    - `stderr` (string)
    - `dropped_bytes` (integer, at least 0)
    - `dropped_frames` (integer, at least 0)
    - `exit_code` (integer)
    - `signal` (string)
    - `code` (string)
    - `error` (string)
    - Exactly one of: `status` ("running") and `pid` and `type` ("pid"), without `id`; `id` and `stdout` and `type` ("stdout"); `id` and `stderr` and `type` ("stderr"); `id` and `dropped_bytes` and `dropped_frames` and `type` ("drop"); `status` and `exit_code` and `type` ("exit"), without `id`; `code` and `error` and `type` ("error"), without `id`
- `400`: Bad Request. A cursor beyond the execution history uses problem code invalid_execution_cursor.
- `401`: Unauthorized.
- `402`: Payment Required. `pro_required`: VMs need Pro; start Pro with cool billing upgrade, or fix a lapsed subscription with cool billing portal, or use the Account page.
- `403`: Forbidden.
- `404`: The computer or execution identity was not found. An absent execution uses problem code execution_not_found.
- `409`: The execution owner cannot yet be reconciled. The problem code is execution_unknown.
- `410`: The completed execution result is no longer retained. The problem code is execution_retired.
- `429`: Too Many Requests. If the problem code is api_request_rate_exceeded, wait for Retry-After seconds; other problem codes describe a separate limit.
- `500`: Internal Server Error.
- `503`: Service Unavailable. `computer_starting` means the computer is starting, or stopped and being started again; wait for Retry-After seconds, then retry. Otherwise inspect the problem code and resolution.
- `default`: A machine-readable API error with a stable code and recovery instruction.

An error is an `application/problem+json` document with a stable `code`; [API errors](/docs/api-reference/errors) says how to handle one.

## Example

```sh
curl -X POST "https://api.cool.computer/api/computers/$PARAM_ID/exec/attach" \
  -H "authorization: Bearer $TOKEN" \
  -H "content-type: application/json" \
  --data '{"execution_id":"cmp_0123456789abcdef01234567.exec.0123456789abcdef0123456789abcdef"}'
```
