# Import

> Open HAR files, Charles JSON sessions (.chlsj) and Cloak Proxy sessions in the traffic list, and turn a cURL command into a request you can send.

Source: https://docs.subcloak.com/cloak-proxy/sessions/import/

Cloak Proxy can open traffic captured somewhere else: a HAR file saved from a browser's developer tools or another proxy, a Charles JSON session, or a Cloak Proxy session from a teammate. Imported requests appear in the traffic list next to live traffic, so you can inspect, filter, compare, repeat and analyze them like anything you captured yourself. You can also paste a `curl` command to rebuild a single request.

## Supported formats

| Format | Extension | Notes |
|---|---|---|
| Cloak Proxy session | `.cloaksession` | Everything, exactly as saved. See [Save and open sessions](https://docs.subcloak.com/cloak-proxy/sessions/save-and-open/). |
| HAR 1.2 | `.har` | Saved by browsers' developer tools and most HTTP debugging tools. |
| Charles JSON session | `.chlsj` | A Charles session exported in its JSON format. |
| JSON | `.json` | Tried as a Cloak Proxy session, then HAR, then Charles. |
| cURL command | (pasted text) | Loads one request into Compose. See [Import a cURL command](#import-a-curl-command). |

Charles settings (rules from Map Local, Rewrite and the other tools) are imported with **Tools › Import Rules…**, not here. See [Import Charles settings](https://docs.subcloak.com/cloak-proxy/tools/rules-and-matching/#import-charles-settings).

## Open a file

1. Choose **File › Open Session…** or press <kbd>⌘</kbd> <kbd>O</kbd>.
2. Select one or more `.cloaksession`, `.har`, `.chlsj` or `.json` files.
3. Click **Open**.

You can also drag files onto the main window, or press <kbd>⇧</kbd> <kbd>⌘</kbd> <kbd>A</kbd> and choose **Open Session, HAR or Charles File…**.

Cloak Proxy works out the format from the contents, not just the extension. For `.cloaksession` and `.json` files it tries a Cloak Proxy session first, then HAR, then Charles.

### What happens to imported requests

- They're **added** to the traffic list. Press <kbd>⌘</kbd> <kbd>K</kbd> first if you want to see only the file.
- They're numbered after the requests already in the list.
- Requests with no app recorded appear in the sidebar under **Imported: name**, where name is the file name without its extension. Select it to see only that file's requests.
- Highlights and comments saved in a Cloak Proxy session or HAR file are restored. See [How HAR files are read](#how-har-files-are-read).
- The first imported request is selected.
- HTTPS requests are marked as decrypted, so their headers and bodies show in the [inspector](https://docs.subcloak.com/cloak-proxy/inspect/inspector/).

If the file isn't a format Cloak Proxy recognizes, it shows **Couldn't open** with the file name and "This file isn't a Cloak Proxy session, HAR, or Charles session".

## How HAR files are read

| HAR field | Becomes |
|---|---|
| `request.method`, `request.url`, `request.httpVersion`, `request.headers` | The request line and headers. Missing values default to `GET` and `HTTP/1.1`. |
| `request.postData.text` | The request body. Base64 bodies (`"encoding": "base64"`) are decoded. |
| `response.status`, `statusText`, `httpVersion`, `headers` | The response. |
| `response.content.text` | The response body, decoded from base64 when marked. |
| `startedDateTime`, `time` | When the request started and how long it took. |
| `_cloakClient` | The app that sent the request, for HAR files exported by Cloak Proxy. |
| `response._error` | The failure reason, for HAR files exported by Cloak Proxy. |
| `comment` (on the entry) (added in Cloak Proxy 0.2.0) | The request's [comment](https://docs.subcloak.com/cloak-proxy/inspect/traffic-list/#comment-on-a-request). `comment` is a standard HAR field, so comments written by other tools come in too. |
| `request.cookies`, `response.cookies` (added in Cloak Proxy 0.5.1) | When the entry's headers have no `Cookie` (or `Set-Cookie`) header, one is built from the list, so cookies written by tools that keep only the list come in. Headers that have them win. |
| `timings` (added in Cloak Proxy 0.5.1) | The Summary tab's timing rows (**Request**, **DNS**, **Waiting**, **Download**), from any tool's HAR. |
| `_webSocketMessages` (added in Cloak Proxy 0.5.1) | The connection's messages, from Cloak Proxy's or Chrome's HAR files: direction, time, kind and data. |
| `_cloakTruncated` (added in Cloak Proxy 0.5.1) | The body is marked **Truncated**, as when it was captured. |
| `_cloakHighlight` (added in Cloak Proxy 0.2.0) | The request's [highlight color](https://docs.subcloak.com/cloak-proxy/inspect/traffic-list/#highlight-requests-by-color): `red`, `orange`, `yellow`, `green`, `blue`, `purple` or `gray`. Other values are ignored. Written by Cloak Proxy's HAR export. |

A response with status `0` or no response becomes a failed request with the reason "No response". HAR stores bodies already decoded, so Cloak Proxy removes the response's `Content-Encoding` header to keep the body viewers from decoding them a second time. Entries without a valid URL are skipped.

## How Charles sessions are read

| Charles field | Becomes |
|---|---|
| `scheme`, `host`, `actualPort` or `port`, `path`, `query` | The URL. The port is left out when it's the default for the scheme. |
| `method`, `protocolVersion` | The request line. `CONNECT` transactions are skipped. |
| `request.header.headers`, `request.body` | Request headers and body. Bodies can be `text` or base64 `encoded`. |
| `response.status`, `response.header.headers`, `response.body` | The response. `Content-Encoding` is removed, as for HAR. |
| `times.start`, `times.end` | Timing. |
| `clientAddress` | The client's address. |
| `status`, `errorMessage` | A transaction whose status isn't `COMPLETE`, or that has no response, becomes a failed request with its error message. |

## Import a cURL command

A `curl` command copied from a browser's developer tools, API documentation or a teammate can be turned into a request you can edit and send. It opens in the Compose window rather than the traffic list. When you send it, the request and its response are captured like any other.

1. Choose **File › Compose Request** or press <kbd>⌥</kbd> <kbd>⌘</kbd> <kbd>N</kbd>.
2. Click **Import cURL…**. If the clipboard holds a command starting with `curl`, it's already filled in.
3. Paste or edit the command and click **Import**.
4. Check the method, URL, headers and body, then send the request.

You can also paste a whole `curl …` command into Compose's URL field. Cloak Proxy recognizes it and imports it the same way.

```bash title="A command Compose can import"
curl 'https://api.example.com/v1/users?page=2' \
  -H 'Authorization: Bearer sk_test_xxxx' \
  -H 'Accept: application/json' \
  --compressed
```

### Supported curl options

| Option | Effect |
|---|---|
| `-X`, `--request` | Method. |
| `-H`, `--header` | A header. |
| `-d`, `--data`, `--data-raw`, `--data-binary`, `--data-ascii` | Body. Several are joined with `&`. Sets the method to `POST` unless one is given, and `Content-Type: application/x-www-form-urlencoded` unless a `Content-Type` header is given. |
| `--data-urlencode` | A URL-encoded body field. |
| `--json` | A body, plus `Content-Type: application/json` and `Accept: application/json` unless those headers are given. |
| `-F`, `--form` | A `multipart/form-data` field. |
| `-u`, `--user` | An `Authorization: Basic` header. |
| `-A`, `--user-agent` | `User-Agent` header. |
| `-e`, `--referer` | `Referer` header. |
| `-b`, `--cookie` | `Cookie` header, when the value contains `=` (a cookie file name is ignored). |
| `-I`, `--head` | `HEAD` request. |
| `-G`, `--get` | Moves the `-d` data into the query string and sends a `GET`. |
| `--url` | The URL. |

Options that don't change the request itself, such as `--compressed`, `-k`, `-L`, `-s`, `-v`, `-o`, `-x`, `--max-time` and `--cert`, are accepted and ignored, as are unknown options. Single quotes, double quotes, `$'…'` strings, backslash escapes and line continuations are handled. A URL without a scheme gets `http://`.

Files can't be read from a pasted command. `-d @file` becomes the placeholder `<contents of file>` and `-F name=@file` becomes a file part named after the file with `<file>` as its content, so you can replace them before sending.

If the command can't be read, the **Import cURL…** sheet shows the reason under the command and stays open. When you paste into the URL field instead, Compose shows **Couldn't import that curl command:** with the reason, such as "That doesn't start with curl." or "No URL found in the command."

For more on Compose, see [Repeat and Compose](https://docs.subcloak.com/cloak-proxy/tools/repeat-and-compose/). To save imported requests in a collection instead, the [API client](https://docs.subcloak.com/cloak-proxy/api-client/import-and-export/) imports cURL, HAR, Postman and OpenAPI too.

> **Imported files can hold someone else's credentials:**
> A HAR or session file from someone else often contains their cookies and tokens. Don't replay requests from it against a live service unless you're allowed to, and delete the file when you're done.

## Import from the command line or MCP

- The MCP server's `import_session` tool opens a HAR, Charles or Cloak Proxy session file into the traffic list. See [MCP tools reference](https://docs.subcloak.com/cloak-proxy/automation/mcp-tools-reference/).
- `cloakctl run --mock recorded.har` answers requests from a recorded HAR or session instead of the network. See [Headless and CI](https://docs.subcloak.com/cloak-proxy/automation/headless-and-ci/).
- [Mock Sets](https://docs.subcloak.com/cloak-proxy/tools/mock-sets/) can also be created from a HAR or session file with **Import HAR or Session…**.

## Related

  - [Save and open sessions](https://docs.subcloak.com/cloak-proxy/sessions/save-and-open/): The .cloaksession format and what it keeps.
  - [Export](https://docs.subcloak.com/cloak-proxy/sessions/export/): Write HAR, CSV, Postman and OpenAPI.
  - [Repeat and Compose](https://docs.subcloak.com/cloak-proxy/tools/repeat-and-compose/): Edit and send requests by hand.
  - [Insights overview](https://docs.subcloak.com/cloak-proxy/insights/overview/): Analyze imported traffic for secrets and problems.
