# Replay with the CLI

## Replaying a Request

### Command

```bash
stoobly-agent request replay "<REQUEST-KEY>"
```

### Options

```sh
$ stoobly-agent request replay --help
```

```
Usage: stoobly-agent request replay [OPTIONS] REQUEST_KEY

  Replay a request

Options:
  --format [body|json]            Format replay response.
  --host TEXT                     Rewrite request host.
  --lifecycle-hooks-script-path TEXT
                                  Path to lifecycle hooks script.
  --log-level [debug|info|warning|error]
                                  Log levels can be "debug", "info",
                                  "warning", or "error"

  --overwrite                     Replay request and overwrite existing
                                  response.

  --record                        Replay request and record.
  --save                          Replay request and save to history.
  --scenario-key TEXT             Record to scenario.
  --scheme [http|https]           Rewrite request scheme.
  -h, --help                      Show this message and exit.
```

### Replay but Do Not Save

To replay a request and NOT save it anywhere, run the command with no flags:

```bash
$ stoobly-agent request replay REQUEST_KEY
```

This can be useful for replaying the request before doing any mutating operations to confirm the API changes are expected.

### Replay and Create a New Request

The `--record` flag will replay the original request, but create an entirely new request:

```bash
$ stoobly-agent request replay --record REQUEST_KEY
```

This can be useful if you want to save the request to Stoobly and inspect it as a separate request in the UI. Please be aware that this will not allow you to update the original request with the new one since **it is considered a different request altogether**.

### Replay and Save to Replay History

The `--save` flag will replay the request and save it to the [Replay History](/core-concepts/mock-api/requests/replay-history.md) for that request:

```sh
$ stoobly-agent request replay --save REQUEST_KEY
```

This links the rerecording with the original request **but won't change the response yet**. This enables you to manually overwrite and update the response **later**.

### Replay and Immediately Overwrite

To update a request immediately, use the `--overwrite` flag which will do the same as the `--save` flag AND also set the request's response to that latest replayed instance:

```bash
$ stoobly-agent request replay --overwrite REQUEST_KEY
```

This command option is the most convenient one because it replays, rerecords, and overwrites the response all in one go.

{% hint style="info" %}
**Optional:** After overwriting the request, snapshot it to persist the change for version control, sharing, or rollback:

```bash
stoobly-agent request snapshot "<REQUEST-KEY>"
```

{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.stoobly.com/guides/how-to-replay-requests/replay-with-the-cli.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
