# Per-region obfuscation directives

Comments in your source that change AfterPack's protection for the code they mark.

Source: https://www.afterpack.dev/docs/directives

A directive is a comment that changes AfterPack's protection for the code it marks. Everything else in the build keeps the [configuration](https://www.afterpack.dev/docs/config) you set for the whole program. Directives are a [Pro](https://www.afterpack.dev/docs/pro) feature.

## Writing one

A directive is a block comment starting with `@afterpack`. Alone on its line, it applies to everything up to the matching `/* @afterpack end */`. Followed by code on the same line, it applies to the rest of that line.

```js
/* @afterpack preset=hard */
function checkLicense(token) {
  return verifySignature(token, PUBLIC_KEY);
}
/* @afterpack end */

const apiKey = /* @afterpack preset=extreme */ "YOUR_SECRET";
```

Keys are the dotted names from the [Configuration](https://www.afterpack.dev/docs/config) page, space-separated: `/* @afterpack preset=hard inflation.max=6 */`. A boolean key alone means `true`. Directives apply to the code they wrap and nothing else: not to functions called from it, and not to imports.

## What you can set

Any option that applies per region. Each one links to its definition, and the `directive` tab there shows the exact spelling.

- [`skip`](https://www.afterpack.dev/docs/config#skip) — directive only
- [`preset`](https://www.afterpack.dev/docs/config#preset)
- [`complexity`](https://www.afterpack.dev/docs/config#complexity)
- [`inflation.max`](https://www.afterpack.dev/docs/config#inflation-max)
- [`strings.encode`](https://www.afterpack.dev/docs/config#strings-encode)

Any other option in a directive is ignored and reported as info. An unknown key or a malformed directive is an error.

## When to use one

- Mark the code that matters most, such as license checks, anti-tamper logic or a bundled secret, with `preset=extreme`. The rest of the program stays lighter and smaller.
- Mark code that must stay readable or fast, such as a hot loop or a third-party snippet, with `skip` or a lower `preset`.

## What to mark

| Asset | Directive | Why |
| --- | --- | --- |
| License / entitlement checks | [`preset=hard`](https://www.afterpack.dev/docs/config#preset) | A single patched bit gives away your software. Pair with [`transforms.comparisonHardening.enabled`](https://www.afterpack.dev/docs/best-practices#the-two-anti-tamper-transforms). |
| Payment validators | `preset=hard` | Tampering is the threat, not just reading. |
| Anti-cheat / anti-bot logic | `preset=hard` or `preset=extreme` | Raises the cost and cadence of cheat development. Opponents have time and motive, so pair with server-authoritative validation. |
| Hardcoded secrets you can't move server-side | [`/* @afterpack preset=extreme */`](https://www.afterpack.dev/docs/config#preset) inline, before the literal | Best removed entirely, but some always slip through. `preset=extreme` makes recovery expensive, and the literal still exists in the output. Keep a literal your code compares against out of the output entirely with [`transforms.comparisonHardening.enabled`](https://www.afterpack.dev/docs/config#transforms-kind-enabled). For one that already shipped, see [If you shipped a secret by accident](https://www.afterpack.dev/docs/best-practices#if-you-shipped-a-secret-by-accident). |
| Proprietary algorithms (pricing, routing, ML glue) | `/* @afterpack preset=extreme */ … /* @afterpack end */` around the core function | This is your most valuable code. Maximum complexity target and the constants floor on. |

Apply the directive at the smallest scope that covers the asset. Marking a 500-line file `preset=extreme` inflates the whole bundle for little gain.

## Checking what was applied

The [Protection Map](https://www.afterpack.dev/docs/protection-map) shows every region a directive produced and what was applied inside it. A directive that was read but had no effect appears in the build's [diagnostics](https://www.afterpack.dev/docs/diagnostics).

## Free builds

A Free engine applies one configuration to the whole program. A directive in a Free build stops the build with a message explaining how to sign in.
