# Rules and matching

> How debugging-tool rules pick requests by URL, method and app, the order rules and tools run in, and how to create, export and import rules as JSON.

Source: https://docs.subcloak.com/cloak-proxy/tools/rules-and-matching/

Every debugging tool except No Caching and DNS Spoofing works with rules. A rule has a name, an on/off checkbox and a matcher that decides which requests it applies to. This page explains matchers, how to limit a rule to certain apps, the order rules and tools run in, and how to create rules from captured traffic and share them as JSON.

## The matcher

Every rule editor starts with a **Rule** section: a name field and the matcher.

*[Screenshot: The Rule section of a Breakpoint rule: name GET api.example.com/v1/users, method GET, URL https://api.example.com/v1/users, mode Wildcard, Include subpaths unchecked, and a Test a URL field. The matcher is the same in every tool: method, URL pattern, mode, subpaths and a live tester.]*

| Field | Options | What it does |
|---|---|---|
| Name | Any text | Shown in the rule list, in the Breakpoint window, in alert notifications and in the script console. |
| Method | **ANY**, **GET**, **POST**, **PUT**, **PATCH**, **DELETE**, **HEAD**, **OPTIONS** | **ANY** matches every method. Any other choice matches only that method (case doesn't matter). |
| URL | A pattern, for example `https://api.example.com/v1/*` | The pattern to match. An empty URL matches nothing. |
| Mode | **Wildcard** (default), **Regex** | How the URL is read. |
| **Include subpaths (/api also matches /api/…)** | On (default for new rules) or off | Wildcard mode only. Also matches everything below the URL, at path boundaries: `/api` matches `/api`, `/api/` and `/api/…`, not `/apiv2`. (added in Cloak Proxy 0.6.1) Earlier versions added a trailing `*`, which also matched `/apiv2`. |
| **Only these apps** (added in Cloak Proxy 0.2.0) | App names separated by commas, or empty (default) | Limits the rule to requests from those apps. Empty matches every app. See [Limit a rule to apps](#limit-a-rule-to-apps). |
| **Conditions** (added in Cloak Proxy 0.4.0) | None (default), or rows added with **Add Condition** | A header, query parameter, JSON body value, body text or GraphQL operation the request must also have. See [Conditions and GraphQL operations](https://docs.subcloak.com/cloak-proxy/tools/conditions-and-graphql/). |

Matching is always case-insensitive. The URL a rule sees is the full request URL: scheme, host, a port when it isn't the default (`:443` for HTTPS, `:80` for HTTP), path and query string.

## Match with wildcards

In **Wildcard** mode, the pattern must match the whole URL, and `*` stands for any run of characters, including `/` and `?`. Every other character, including `?` and `.`, is literal.

- **Leave out the scheme** to match both `http` and `https`. A pattern like `api.example.com/v1/*` is compared with the URL minus its `http://` or `https://`.
- **Include subpaths** also matches longer paths and any query string, at path boundaries: `/api` matches `/api`, `/api/`, `/api/…` and `/api?…`, but not `/apiv2`, `/api.json` or `/api-docs`. A pattern that already ends in `/` or `*`, or has a query, takes anything after it. (added in Cloak Proxy 0.6.1) Before 0.6.1 it added a `*`, so `/api` also matched `/apiv2`.
- **Without subpaths**, the query string is ignored: the pattern is compared with the URL up to the `?`. If your pattern contains a `?` itself, the query is kept so you can match it.

| Pattern | Subpaths | Matches | Doesn't match |
|---|---|---|---|
| `api.example.com/v1/*` | Either | `https://api.example.com/v1/users`, `http://api.example.com/v1/users?page=2` | `https://api.example.com/v2/users` |
| `https://api.example.com/v1/users` | Off | `https://api.example.com/v1/users`, `https://api.example.com/v1/users?page=2` | `https://api.example.com/v1/users/42`, `http://api.example.com/v1/users` |
| `https://api.example.com/v1/users` | On | `https://api.example.com/v1/users/42`, `https://api.example.com/v1/users?page=2`, and also `https://api.example.com/v1/users-archive` | `https://api.example.com/v1/teams` |
| `https://api.example.com/v1/users/` | On | `https://api.example.com/v1/users/42` | `https://api.example.com/v1/users-archive` |
| `*.example.com/*` | Either | `https://cdn.example.com/app.js`, `https://staging.example.com/` | `https://example.com/` (no subdomain) |
| `api.example.com/search?q=*` | Off | `https://api.example.com/search?q=shoes` | `https://api.example.com/search` |
| `localhost:3000/*` | Either | `http://localhost:3000/api/users` | `http://localhost:8080/api/users` |

> **Tip:**
> With subpaths on, end the pattern with `/` to stay inside a folder. `…/v1/users` also matches `…/v1/users-archive`; `…/v1/users/` doesn't.

## Match with a regular expression

In **Regex** mode, the pattern is a regular expression searched for anywhere in the full URL, case-insensitive. It isn't anchored, so `example` matches any URL containing that word. Add `^` and `$` to anchor it. **Include subpaths** is hidden in this mode.

| Pattern | Matches |
|---|---|
| `^https://api\.example\.com/v[12]/users` | Users endpoints in v1 and v2 of the API. |
| `/orders/\d+(\?.*)?$` | A single order by numeric ID, with or without a query string. |
| `graphql` | Any URL containing `graphql`. |
| `^http://` | Every plain-HTTP request. |

Escape dots (`\.`) when you mean a literal dot. A pattern that isn't a valid regular expression matches nothing.

## Test a pattern

Type a URL into the tester under the pattern, or click **Captured** and pick a captured request: the newest requests the pattern matches come first, then other recent ones. (added in Cloak Proxy 0.5.1) The tester says:

- **Matches**, **URL matches** (the rule has conditions, which a typed URL can't be checked against: pick a captured request to check them), or **No match**.
- Why not, for the first part that doesn't fit: the method, the app, the scheme, the host, the path, **Include subpaths** being off, or the condition that stops a captured request.
- What the tool does with a match: the URL Map Remote sends it to, the file Map Local serves (or that the file isn't there), the status Block List answers with, what the breakpoint pauses, or how many actions a Rewrite rule runs and the URL it makes.
- A hint for common surprises: `*.example.com` doesn't cover `example.com` itself; a `*` in the middle of a path also matches across `/`; a regular expression without `^` and `$` matches part of a URL.

A typed URL without a scheme is tested as `https://`. With a captured request, its method, app, headers and body are tested too, so conditions count. Up to 0.5.0, the tester checked a typed URL only, without the method or the apps.

*[Screenshot: A Breakpoint rule for POST https://*.shopapp.example/v1/orders without subpaths, and the tester showing https://shopapp.example/v1/orders doesn't match: *.shopapp.example covers the subdomains of shopapp.example, not shopapp.example itself, with a hint to use *shopapp.example. The tester says why a URL doesn't match.]*

The `test_rule` MCP tool and `cloakctl rules TOOL test` run the same test for AI assistants and scripts.

(added in Cloak Proxy 0.4.0) Above it, **Matches N of M captured requests** checks the whole rule (URL, method, apps and conditions) against the last 2,000 captured requests as you edit. Click **Show Requests** to select them in the traffic list.

## Limit a rule to apps

(added in Cloak Proxy 0.2.0)

A rule normally applies to matching requests from every app. To apply it only to some apps, list them in the **Only these apps (comma-separated; empty: every app)** field under the URL pattern. Use it when several apps call the same API and you want to change only your own app's traffic: a breakpoint that doesn't stop Safari, a slow network for one app, or a [Rewrite](https://docs.subcloak.com/cloak-proxy/tools/rewrite/) that adds a debug header only to your app.

1. Find the app's name in the **Apps** section of the [sidebar](https://docs.subcloak.com/cloak-proxy/inspect/sidebar/). That's the name to type.

2. Open the rule in the Tools window and type the name into **Only these apps**, for example `MyApp`. Separate several apps with commas: `MyApp, Safari`.

3. Make a request from the app. Requests from other apps that match the URL are now left alone by this rule.

How app names are matched:

| Case | Result |
|---|---|
| The field is empty | The rule matches every app, as before. |
| Names | Compared with the whole app name, ignoring case and the spaces around each name. `myapp` matches `MyApp`; `My` doesn't. |
| A request whose app Cloak Proxy couldn't identify | Doesn't match a rule that lists apps. These requests appear under **All Traffic** but not under **Apps** in the sidebar. |
| A device on your network | Its app name is its IP address, so `192.168.1.20` limits a rule to that phone or computer. |
| [Repeat, Edit and Repeat and Compose](https://docs.subcloak.com/cloak-proxy/tools/repeat-and-compose/) | These requests come from **Cloak Proxy (Repeat)** or **Cloak Proxy (Compose)**, so a rule limited to `MyApp` skips them. Add that name to the list to include them. |

The app list works in every tool that has a matcher: Breakpoint, Map Local, Map Remote, Rewrite, Scripting, Block List, Allow List, Network Conditions and Alerts. With the [Allow List](https://docs.subcloak.com/cloak-proxy/tools/allow-list/), a rule limited to `MyApp` records only that app's matching requests. DNS Spoofing, Mock Sets and No Caching have no matcher, so they can't be limited to an app. To narrow a rule further, by a header, a body value or a GraphQL operation, add [conditions](https://docs.subcloak.com/cloak-proxy/tools/conditions-and-graphql/).

In exported JSON and in the [MCP server](https://docs.subcloak.com/cloak-proxy/automation/mcp-server/), the list is the matcher's `apps` field, for example `"apps" : ["MyApp", "Safari"]`. It's left out when the field is empty.

> **Tip:**
> To stop recording an app's traffic altogether, rather than limiting a rule, mute it. See [Mute noisy apps](https://docs.subcloak.com/cloak-proxy/capture/recording-and-sessions-basics/#mute-noisy-apps).

## Manage rules

| To | Do this |
|---|---|
| Add a rule | Click **+** under the rule list, or **Add Rule** when the list is empty. |
| Delete a rule | Select it and click **−**, or right-click it and choose **Delete**. |
| Duplicate a rule | Select it and click the duplicate button, or right-click it and choose **Duplicate**. The copy gets " copy" added to its name. |
| Turn one rule off | Clear its checkbox. The tool's other rules keep working. |
| Turn the whole tool off | Use the **On**/**Off** switch in the tool's header. Rules are kept. |
| Change the order | Drag rules up or down in the list. |
| Put rules in folders (added in Cloak Proxy 0.4.0) | Click the new-folder button under the list, then drag rules in or right-click and choose **Move to Folder**. See [Rule folders and sets](https://docs.subcloak.com/cloak-proxy/tools/folders-and-sets/). |
| Hide rules that are off (added in Cloak Proxy 0.4.0) | Click the eye under the list. |

New rules start with an empty URL. (added in Cloak Proxy 0.4.0) They take their name from what they match, such as `POST api.example.com/v1/orders`, and the name follows your edits until you type one of your own.

## Rule order inside a tool

Rules are checked from the top of the list to the bottom. Whether one rule or all matching rules apply depends on the tool:

| Tool | Which rules apply |
|---|---|
| Breakpoint | The first enabled rule that matches. Its **Pause on** settings decide whether the request, the response, or both pause. |
| Map Local | The first matching rule. If it's a **Directory** rule with no file for the path, the request carries on as if Map Local hadn't matched; later Map Local rules aren't tried. |
| Map Remote | The first matching rule. |
| Rewrite | Every matching rule, top to bottom. Each rule's actions run in order, and each works on the result of the one before. |
| Scripting | Every matching script, top to bottom. Each script receives the output of the one before it. |
| Block List | The first matching rule. |
| Allow List | Any matching rule. The request is recorded if at least one matches. |
| Network Conditions | The first matching rule. |
| DNS Spoofing | One address per host. If the same host appears twice, the lower row wins. |
| Mock Sets | The first set (top to bottom) that has a recording for the request, or that answers it with an offline 404. |
| Alerts | Every matching rule fires. |

(added in Cloak Proxy 0.4.0) Folders don't change the order: rules run top to bottom as listed, and a rule in a folder that's off is skipped.

> **Tip:**
> Put specific rules above general ones. A Map Local rule for `api.example.com/v1/users/42` must sit above one for `api.example.com/v1/*`, or the general rule always wins.

## What happens when several tools match

One request can match rules in several tools. Cloak Proxy runs them in this order:

| Step | Tool | Effect on the rest |
|---|---|---|
| 1 | **Block List** | A match answers with 403 or drops the connection. Nothing after this runs. |
| 2 | **Rewrite**: request actions | Every matching rule's request header, query parameter, URL and request body actions, top to bottom. |
| 3 | **Failure scenarios** (added in Cloak Proxy 0.4.0) | A fault that fires can answer with a status, reset or time out the connection, or serve a kept stale response (nothing after this runs); delay the request; or change how the real response is delivered (truncate, drop mid-body, trickle). See [Failure scenarios](https://docs.subcloak.com/cloak-proxy/tools/failure-scenarios/). |
| 4 | **Network Conditions**: packet loss | If the request is chosen to be lost, the connection is dropped after the rule's latency. Nothing after this runs. |
| 5 | **Scripting**: `onRequest` | Every matching script with **Run onRequest** on, top to bottom. |
| 6 | **Breakpoint**: request | Pauses for you. **Abort** ends the request here. |
| 7 | **Map Local** | A match answers the request locally. Steps 8 to 12 are skipped. |
| 8 | **Mock Sets** | A recorded response (or an offline 404) answers the request. Steps 9 to 12 are skipped. |
| 9 | **Map Remote** | Rewrites the URL and, unless you keep it, the `Host` header. |
| 10 | **No Caching**: request | Removes conditional headers and adds `Cache-Control: no-cache` and `Pragma: no-cache`. |
| 11 | **Network Conditions**: upload | Waits half the latency plus the upload time for the body. |
| 12 | **DNS Spoofing** | Connects to the spoofed IP address for the host, and the request goes to the server. |
| 13 | **No Caching**: response | Removes `ETag`, `Last-Modified` and `Expires`, and sets `Cache-Control: no-store, no-cache, must-revalidate`. |
| 14 | **Rewrite**: response actions | Every matching rule's response header, response body and status actions, top to bottom. |
| 15 | **Scripting**: `onResponse` | Every matching script with **Run onResponse** on, top to bottom. |
| 16 | **Breakpoint**: response | Pauses for you. **Abort** closes the app's connection. |
| 17 | **Network Conditions**: download | Waits half the latency plus the download time for the body, then sends the response to the app. |
| 18 | **Allow List** and **Alerts** | The request is recorded if the Allow List lets it through, and alert rules check the finished request. |

Steps 13 to 17 run for every response, including those from Map Local and Mock Sets. So you can rewrite, pause or script a mocked response, and it is still slowed by Network Conditions. A Block List 403 skips them.

### Which URL each step sees

Rewrite, scripts and breakpoints can change a request's URL. Later steps see the change only where it matters:

| Steps | Match against |
|---|---|
| Block List, Rewrite (request and response actions), Allow List | The request as the app sent it. |
| Network Conditions, request scripts, request breakpoint | The request after Rewrite. |
| Map Local, Mock Sets, Map Remote | The request after Rewrite, request scripts and the request breakpoint. |
| Response scripts, response breakpoint | The request as the app sent it, so editing the URL earlier doesn't skip them. |
| Alerts | The request as it was finally sent, after Map Remote. |

> **Note:**
> Requests you send with [Repeat, Edit and Repeat or Compose](https://docs.subcloak.com/cloak-proxy/tools/repeat-and-compose/) go through the same steps as live traffic.

## Create a rule from a request

Right-click a captured request in the traffic list, choose **Tools**, then a tool. The new rule matches that request and opens in the Tools window. With several requests selected, Mock Sets records all of them.

You can also search for **New … Rule from Selection** or **Mock Selected Responses** in [Search Everything](https://docs.subcloak.com/cloak-proxy/inspect/search-and-command-palette/). The **Tools** submenu isn't available for encrypted tunnels, and No Caching isn't in it because it has no rules.

| Menu item | The new rule | Tool switched on |
|---|---|---|
| **Breakpoint…** | Matches the request's method and URL without its query string, subpaths off. Pauses request and response. | Yes |
| **Map Local…** | Same exact match. Status code, body (decoded, JSON pretty-printed) and useful headers are copied from the captured response. See [Map Local](https://docs.subcloak.com/cloak-proxy/tools/map-local/#start-from-a-captured-response). | Yes |
| **Map Remote…** | Matches the URL without its query, any method, subpaths on. **Host** is prefilled with the current host for you to change. | Yes |
| **Rewrite…** (added in Cloak Proxy 0.2.0) | Exact match (method and URL without its query, subpaths off), with no actions yet. See [Rewrite](https://docs.subcloak.com/cloak-proxy/tools/rewrite/). | Yes |
| **Scripting…** | Exact match, with the starter script. | Yes |
| **Block List…** | Matches the URL without its query, any method, subpaths on. Returns 403. | Yes |
| **Allow List…** | Matches the whole host (`https://api.example.com/`), any method, subpaths on. Named after the host. | No: switch the Allow List on yourself. |
| **Network Conditions…** | Matches the whole host. Uses the **3G** profile. Named after the host. | Yes |
| **DNS Spoofing…** | A row for the request's host pointing at `127.0.0.1`. | No change |
| **Mock This Response** / **Mock N Responses** | A mock set with the response of each selected request. | Yes |
| **Alerts…** | Exact match with the request's method, condition **Any error (4xx, 5xx or failure)**. Named "… fails". | Yes, and macOS asks for notification permission |

Rules made this way are named after the request, for example `GET api.example.com/v1/users`. (added in Cloak Proxy 0.4.0) A GraphQL request's rule is named after its operation, such as `mutation CreateOrder`, and gets a **GraphQL operation is CreateOrder** condition, so it doesn't catch the other operations sent to the same URL.

## Export and import rules

Rules are saved on your Mac. To share them with a teammate, keep them in a repository or use them in CI, export them to JSON.

1. Choose **Tools › Export Rules…**.

2. Pick where to save. The suggested name is `Cloak Proxy Rules.json`.

3. To load rules, choose **Tools › Import Rules…** and pick a JSON file. Cloak Proxy reports **Imported N rules from …**. The same command reads Charles settings: see [Import Charles settings](#import-charles-settings).

To share one scenario rather than everything, use **Export Folder…** or **Export Set…**; see [Share folders and sets](https://docs.subcloak.com/cloak-proxy/tools/folders-and-sets/#share-folders-and-sets).

What's in the file and what import reads:

| Part | Exported | Imported |
|---|---|---|
| Breakpoint, Map Local, Map Remote, Rewrite, Scripting, Block List, Allow List, Network Conditions and DNS Spoofing rules | Yes | Yes. They are added to your current rules; a rule with the same `id` as an existing one replaces it. |
| Mock Sets, including recorded response bodies, and Alerts | Yes | Yes, the same way. |
| On/off state of each tool, and No Caching | Yes | No. Your current switches stay as they are. |
New rules are named after the tool (**New Breakpoint**, **New Map Local**, **New Map Remote**, **New Rewrite**, **New Script**, **New Block Rule**, **New Allow Rule**, **New Condition**, **New Alert**) and start with an empty URL.
| Failure scenarios (added in Cloak Proxy 0.4.0) | Yes | Yes, with the switch each had in the file. See [Failure scenarios](https://docs.subcloak.com/cloak-proxy/tools/failure-scenarios/). |

The file is pretty-printed JSON with sorted keys. Each rule has an `id`, `name`, `isEnabled` and `matcher`, plus the tool's own fields. An excerpt:

```json title="Cloak Proxy Rules.json (excerpt)"
{
  "blockList" : [
    {
      "action" : "forbidden",
      "id" : "6F1C2A3B-0000-4000-8000-00000000AB12",
      "isEnabled" : true,
      "matcher" : {
        "includeSubpaths" : true,
        "method" : "ANY",
        "mode" : "wildcard",
        "url" : "ads.example.com/"
      },
      "name" : "Block ads"
    }
  ],
  "blockListEnabled" : true
}
```

> **Tip:**
> Rules need every field their tool uses. Instead of writing a file by hand, create the rules in the app, export them, and edit the export. If a file can't be read, Cloak Proxy says **That file isn't a Cloak Proxy rules export** with the reason.

> **Exports can contain secrets:**
> An export holds everything in your rules: Map Local bodies and headers, Rewrite values, scripts, and every response recorded in your mock sets. These can include tokens, cookies and personal data. Read the file before you share or commit it.

The same file works with [`cloakctl run --tools`](https://docs.subcloak.com/cloak-proxy/automation/headless-and-ci/) for headless runs.

## Import Charles settings

(added in Cloak Proxy 0.2.2)

If you're moving from Charles Proxy, you can bring its rules with you. **Tools › Import Rules…** reads a Charles settings export and turns each Charles tool's rules into Cloak Proxy rules. You see what will be added, and what can't be, before anything changes.

1. In Charles, choose **Tools › Import/Export Settings**, open the **Export** tab, tick the tools you use and click **Export**. Charles saves an `.xml` file.

   A file from a single tool's own **Export** button, such as a Rewrite export, works too. So does Charles's preferences file, `~/Library/Preferences/com.xk72.charles.config`. In the open panel, press <kbd>⌘</kbd> <kbd>⇧</kbd> <kbd>G</kbd> and paste the path to reach it.

2. In Cloak Proxy, choose **Tools › Import Rules…** and pick the file.

3. Read the **Import from Charles** sheet. **To import** lists the number of rules for each tool. **Works a little differently** lists rules that come in with a change, and **Not imported** lists what has no equivalent. Each row says why.

4. Click **Import**, or **Cancel** to leave everything as it is.

If the file isn't a Charles export, Cloak Proxy says **Couldn't import** with the file name and the reason, and nothing changes.

Imported rules are added after your current ones and never replace them. Importing the same file twice adds its rules twice. Each rule keeps the on/off state it had in Charles, and a rule whose Charles tool was off comes in turned off. A tool that was on in Charles, with at least one rule on, is turned on here too.

What each Charles tool becomes:

| In Charles | In Cloak Proxy | Differences |
|---|---|---|
| Breakpoints | [Breakpoint](https://docs.subcloak.com/cloak-proxy/tools/breakpoint/) rules | Request, response and method carry over. |
| Map Local | [Map Local](https://docs.subcloak.com/cloak-proxy/tools/map-local/) rules with a **File** or **Directory** source | A folder becomes **Directory**. Windows paths are skipped. A file or folder that isn't on this Mac is listed so you can copy it over. |
| Map Remote | [Map Remote](https://docs.subcloak.com/cloak-proxy/tools/map-remote/) rules | **Keep the original Host header** carries over. A destination with a wildcard is skipped. When the source matches many paths and the destination sets a path, every request goes to that one path. |
| Rewrite | [Rewrite](https://docs.subcloak.com/cloak-proxy/tools/rewrite/) rules: one for each set and location, with an action for each Charles rule | See the next table. A set with no locations matches every request. |
| Block List | [Block List](https://docs.subcloak.com/cloak-proxy/tools/block-list/) rules | **Return 403 Forbidden** or **Drop the connection**, as chosen in Charles. |
| Allow List | [Allow List](https://docs.subcloak.com/cloak-proxy/tools/allow-list/) rules | Charles blocks requests that aren't on the list. Cloak Proxy lets them through and doesn't record them. |
| No Caching | [No Caching](https://docs.subcloak.com/cloak-proxy/tools/no-caching/) turned on | Applies to every request, even when Charles limited it to some hosts. |
| Block Cookies | A Rewrite rule named **Block Cookies** that removes `Cookie` and `Set-Cookie` | |
| DNS Spoofing | [DNS Spoofing](https://docs.subcloak.com/cloak-proxy/tools/dns-spoofing/) entries | Host names with a wildcard are skipped. |
| Throttle settings | A [Network Conditions](https://docs.subcloak.com/cloak-proxy/tools/network-conditions/) rule named **Charles throttle** | Bandwidth times utilization, latency, and reliability as packet loss. Imported when throttling was on, or for the hosts it was limited to. Custom presets and the unstable connection settings aren't imported. |
| SSL Proxying locations | Hosts on the [SSL Proxying](https://docs.subcloak.com/cloak-proxy/capture/ssl-proxying/) list | Hosts already on the list aren't added twice. The exclude list isn't imported: Cloak Proxy decrypts only the hosts on its list. |
| Mirror, Auto Save, Port Forwarding, Reverse Proxies | Not imported | Listed under **Not imported** when they were on. |

How Charles rewrite rules become Rewrite actions:

| Charles rule | Rewrite action | Not imported when |
|---|---|---|
| Add Header | **Request header** or **Response header**, **Add** | |
| Modify Header | Header **Find and replace**. A blank match value replaces the whole value of an existing header. | It renames the header. |
| Remove Header | Header **Remove** | It removes the header only when its value matches, or the name is a regular expression. |
| Host, Path | **URL** **Find and replace** with a regular expression that only touches the host or the path | |
| URL | **URL** **Find and replace** | |
| Body | **Request body** or **Response body** **Find and replace** | |
| Add Query Param | **Query parameter** **Set** | |
| Modify Query Param | **Query parameter** **Find and replace** | It renames the parameter. |
| Remove Query Param | **Query parameter** **Remove** | It removes the parameter only when its value matches. |
| Response Status | **Response status** **Set** | The new value has no status code. When the Charles rule only changed one status, such as `200`, the action changes every status; the sheet says so. |

Regex, **Match whole value**, **Replace first** and case sensitivity carry over, so some actions use a regular expression where Charles showed a checkbox. Inactive Charles rules become actions that are turned off.

A Charles location (protocol, host, port, path and query) becomes the rule's matcher:

| Charles location | Matcher |
|---|---|
| Host `api.example.com` | `api.example.com/` with subpaths on: any protocol, path and query. |
| Protocol `https`, host `api.example.com`, port `443`, path `/v1/users` | `https://api.example.com/v1/users` with subpaths off. A path without a wildcard matches exactly, with any query. |
| Path `/api/*`, everything else blank or `*` | `*/api/*` |
| Host `localhost`, port `3000`, path `/report`, query `id=*` | `localhost:3000/report?id=*`. A query in the location must match. |
| Host `api?.example.com` | A regular expression, since `?` stands for one character in Charles. |

Port `443` and `80` are left out of the pattern because they're the defaults, and they set the protocol when Charles had none. A blank port, or `*`, matches only the default ports 80 and 443; Charles matched any port. If you used rules on other ports without naming the port, add `:port` to the pattern after importing.

## Related

  - [Debugging tools](https://docs.subcloak.com/cloak-proxy/tools/overview/): Every tool, the Tools window and the tools popover.
  - [Scripting](https://docs.subcloak.com/cloak-proxy/tools/scripting/): Change requests and responses with JavaScript.
  - [Headless and CI](https://docs.subcloak.com/cloak-proxy/automation/headless-and-ci/): Run tests through Cloak Proxy with exported rules.
  - [Search and command palette](https://docs.subcloak.com/cloak-proxy/inspect/search-and-command-palette/): Create rules and toggle tools from the keyboard.
