---
url: https://docs.sunlicense.com/cli/commands.md
description: >-
  Every sunlicense command (licenses, products, product analytics, API keys, the
  Trash), JSON output for scripts and CI, testing an integration, exit codes and
  environment variables.
---

# Commands and scripting

Everything the app does is also a command. In a terminal, a command that's missing something
asks for it (a policy to pick, a customer's email); in a script it never prompts, and says which
flag is missing instead.

![sunlicense --help](/images/cli/cmd-help.png)

## Naming a license

Anywhere a license is expected, give whichever you have:

| You type | Matches |
|---|---|
| `7QF2-EDRF-CJ78-RBRT` | The full key |
| `7QF2` | A license whose key starts with this (if only one does) |
| `olivia@brightside.co` | The customer's email (if they have one license) |
| `1dac7798-d6db-…` | The license id |

With nothing, in a terminal, you get a list to pick from.

## Licenses

```bash
sunlicense licenses                              # all, newest first; keys masked
sunlicense licenses --status active -s acme      # filter by status and text
sunlicense licenses --product "Acme Paint" --reveal
```

![sunlicense licenses --status active](/images/cli/cmd-licenses.png)

```bash
sunlicense licenses show yuki.tanaka@kumo.jp     # details, machines and recent checks
sunlicense licenses issue                        # asks for policy and customer; copies the key
sunlicense licenses issue --policy Studio --product "Acme Paint" --email olivia@brightside.co --name "Olivia Chen"
sunlicense licenses revoke 7QF2                  # asks first; --yes to skip
sunlicense licenses suspend 7QF2 --yes
sunlicense licenses reinstate 7QF2
sunlicense licenses download 7QF2 -o olivia.lic  # signed offline file (- for stdout)
sunlicense licenses delete 7QF2                  # to the Trash; asks first, --yes to skip
```

![sunlicense licenses show](/images/cli/cmd-show.png)

## Products and policies

```bash
sunlicense products
sunlicense products create "Acme Paint" --description "Raster image editor"
sunlicense policies --product "Acme Paint"
sunlicense policies create --product "Acme Paint" --name Studio --type subscription --machines 3 --days 365
sunlicense policies create --product "Acme Paint" --name Lifetime --type perpetual --machines 0   # 0 = unlimited
```

A product is the app you sell; a policy is the terms its licenses get. Policies can be named the
same in different products, so add `--product` when a name repeats.

## Product analytics

```bash
sunlicense analytics                                   # active installs of every product
sunlicense analytics "Acme Paint"                      # installs now, today and in 30 days
sunlicense analytics acme-paint --days 30              # plus installs per day
sunlicense analytics acme-paint --metric os            # by operating system, in the last complete hour
sunlicense analytics acme-paint -m runtimeVersion --parent java --days 7   # Java versions, per day on average
sunlicense analytics acme-paint -m features -d 30      # feature usage (Lite and Standard)
```

Metrics: `installs`, `licensed`, `productVersion`, `os`, `osVersion`, `arch`, `cores`, `locale`, `runtime`,
`runtimeVersion`, `platform`, `platformVersion`, `country`, `sdk`, `features`, or `chart:<id>` for a custom chart.
`--source licensed|unlicensed` filters, `--limit` shows more values, `--json` prints the API's answer. The same
numbers are on the product's **Analytics** tab ([product analytics](/guide/product-analytics)); `sunlicense init`
prints the product analytics id and the snippet that starts reporting.

On Standard, `sunlicense analytics page create` builds one [analytics page](/guide/product-analytics) for a product:
active installs, licensed vs unlicensed, product version, platform and OS, feature usage (with `--features`) and the
custom charts named with `--charts` (their ids in your code). A chart your app reported a moment ago can take a little
while to show up, so it waits for it (`--wait`, default 60 s); running it again updates the page with the same title.

```bash
sunlicense analytics page create --product acme-paint --charts brush_type,canvas_size --features export,layers
sunlicense analytics page create --product acme-paint --title "Acme Paint at a glance" --json
```

## Product setup

Each product has a **Setup** tab: the parts of a full setup (license check, analytics, core unlock, ownership
notice, tamper reports, protected files…) that tick by themselves once your app shows them working. The setup
prompt does all of it; these commands are what it runs, and work by hand too.

```bash
sunlicense setup status acme-paint                       # which parts are done
sunlicense setup report --product acme-paint notice portal-link   # parts only your code knows about
sunlicense seal core.bin --product acme-paint > core.sealed       # core unlock: seal part of the app
sunlicense seal core.bin --product acme-paint -o core.sealed --digest "build/libs/*.jar"
sunlicense files push data/rules.dat --product acme-paint         # protected files (Standard)
sunlicense files list acme-paint
```

* **`seal`** encrypts a file (or stdin, `-`) under the product's unlock key on SunLicense's servers and prints
  the sealed text (`SLS1.…`, at most 512 KB in). Ship it in your app: the SDK unseals it after a valid license check, so
  a copy with the check removed can't run that part. `--digest <glob>` (repeatable, `**` works) puts the SHA-256 of
  those files inside, so the SDK can report a modified copy. Each file is named by its path below the pattern's
  folders (`--digest "build/classes/java/main/**/*.class"` names `com/example/Foo.class`, its entry in the jar). Members never see the key.
* **`setup report`** marks the parts SunLicense can't see from outside done: `notice` and `portal-link`.
* **`files push`** uploads [protected files](/guide/protected-files) (a file with the same name is replaced); licensed copies download them
  at run time with their license key, and a suspended, expired or revoked license gets nothing.

## Releases

Publish a version buyers [download](/guide/downloads), from a release script or CI (Standard). It uploads the files,
waits for SunLicense's check and publishes; a draft of the same version gets the files instead. See
[Publish releases](/guide/releases).

```bash
sunlicense releases create build/libs/acme-1.4.0.jar --product acme-paint --version 1.4.0 --notes @CHANGELOG.md
sunlicense releases create dist/pack.mcpack --product acme-paint --version 1.5.0-beta.1 --draft   # upload, don't publish
sunlicense releases list acme-paint                     # versions, status, files, storage used
sunlicense releases delete --product acme-paint --version 1.5.0-beta.1   # drafts only
```

## Deleting and the Trash

```bash
sunlicense products delete "Acme Paint"          # with its policies and licenses; says how many first
sunlicense policies delete Studio --product "Acme Paint"
sunlicense trash                                 # what's there, what went with it, days left
sunlicense trash restore "Acme Paint"            # by name, id or a license's key start
```

Deleted items stay in the [Trash](/guide/concepts#deleting-and-the-trash) for 30 days; their licenses stop working at
once. Deleting for good is in the dashboard only.

## API keys

```bash
sunlicense keys
sunlicense keys create --name "Acme Editor 2.x"   # shown once
sunlicense keys revoke "Acme Editor 2.x" --yes    # by name, prefix or id
```

## Obfuscate

Obfuscate a built file on SunLicense's servers and download the result (the obfuscated file, its mapping and a report). The language is detected from the file; the exit code is non-zero if the run fails, so it fits a build or CI step. See [Obfuscation](/guide/obfuscation).

```bash
sunlicense obfuscate build/libs/app.jar                 # detect the language, use defaults, write next to the file
sunlicense obfuscate build/libs/app.jar --profile release -o dist/
sunlicense obfuscate app.jar --config proguard.pro      # a raw engine config (advanced)
sunlicense obfuscate app.jar --engine proguard --json   # pick the engine; JSON for scripts
sunlicense obfuscate build/libs/app.jar --product acme-paint   # counts toward the product's setup
sunlicense obfuscate profiles                            # list your saved profiles
```

| Flag | What it does |
|---|---|
| `--profile <name\|id>` | Use a saved profile |
| `--product <code\|name\|id>` | The product this build is for: its linked profile, and the run ticks **Obfuscated release builds** on its Setup tab |
| `--engine <id>` | Override the language's default engine |
| `--config <file>` | Run a raw engine config (checked first) |
| `-o, --output-dir <dir>` | Where to write the outputs (default: the input file's folder) |
| `--title <text>` | A title for the task (shown under Tasks) |

## AI assistants

```bash
claude mcp add sunlicense --env SUNLICENSE_TOKEN=slp_... -- sunlicense mcp
```

`sunlicense mcp` is an MCP server on stdio for Claude Code, Codex, Cursor and other assistants (every plan; Free has 50 tool calls a day). Setup and tools: [AI assistants (MCP)](/cli/mcp).

## Account

| Command | |
|---|---|
| `sunlicense login [--email E] [--with-token] [--local \| --server URL]` | Sign in with your password or a [personal access token](/cli/#with-a-personal-access-token) ([details](/cli/#sign-in)) |
| `sunlicense signup` | Create an organization and sign in as its Owner |
| `sunlicense whoami` | Organization, role, plan, server, session time left |
| `sunlicense switch [account]` | List saved accounts, or switch to one |
| `sunlicense logout [account] [--all]` | Sign out |
| `sunlicense open` | Open the web dashboard |
| `sunlicense update [--check] [--auto-check on\|off]` | Install the latest version after checking its signature, only look, or turn the daily check on or off ([details](/cli/#updating)) |

## Scripts and CI

Add `--json` to any command for machine-readable output. It's the API's data as-is, so license
keys are **not** masked in JSON.

```bash
KEY=$(sunlicense licenses issue --policy Pro --product "Acme Editor" \
        --email jane@example.com --json | jq -r .key)
sunlicense licenses revoke "$KEY" --yes
sunlicense licenses --status active --json | jq length
```

For CI, create a [personal access token](/api/overview#personal-access-tokens) (dashboard →
**Settings → Personal access tokens**) with only the scopes the job needs, store it as a secret
and pass it in `SUNLICENSE_TOKEN` (with `SUNLICENSE_SERVER` for a server other than production);
nothing is written to disk then:

```bash
SUNLICENSE_TOKEN=$SUNLICENSE_CI_TOKEN sunlicense licenses --status active --json | jq length
```

Or sign in once with it (`echo "$TOKEN" | sunlicense login --with-token`), or with a password:

```bash
echo "$SUNLICENSE_PASSWORD" | sunlicense login --email ci@acme.com --password-stdin
```

A password session lasts 12 hours. Use a member with the [smallest role](/guide/team-and-roles)
that can do the job.

## Test an integration

These use an [API key](/cli/app#api-keys), exactly like your app, not your session:

```bash
export SUNLICENSE_API_KEY=slk_...
sunlicense validate                                                 # after sunlicense init: the test license from .env
sunlicense validate --key 7QF2-EDRF-CJ78-RBRT                       # ✓ VALID, and activates this machine
sunlicense validate --key 7QF2-EDRF-CJ78-RBRT --release             # ✓ VALID, then frees this machine's slot again
sunlicense validate --key 7QF2-EDRF-CJ78-RBRT --fingerprint machine-b
sunlicense deactivate --key 7QF2-EDRF-CJ78-RBRT                     # free this machine's slot
sunlicense verify-offline --file license-7QF2.lic                    # no network; uses your org's key when signed in
sunlicense verify-offline --file license-7QF2.lic --public-key public-key.txt
sunlicense fingerprint                                              # this machine's id
```

The fingerprint is the CLI's own machine id. Each SDK computes its own, so pass `--fingerprint`
to act on a machine your app registered.

## Exit codes

| Code | Meaning |
|---|---|
| `0` | Done (for `validate` and `verify-offline`: valid) |
| `1` | Failed, or the license is not valid |
| `2` | `validate` / `deactivate` could not reach SunLicense (your app should fall back to its offline license) |
| `130` | You cancelled a prompt |

## Environment variables

| Variable | |
|---|---|
| `SUNLICENSE_SERVER` | API server for `login` and `signup` (default `https://api.sunlicense.com`) |
| `SUNLICENSE_TOKEN` | Use this personal access token (`slp_…`) or session token instead of a saved account |
| `SUNLICENSE_CONFIG` | Where sessions are saved |
| `SUNLICENSE_API_KEY` | API key for `validate` and `deactivate` (else read from the project's `.env.local` or `.env`) |
| `SUNLICENSE_LICENSE_KEY` | License key `validate` and `deactivate` use without `--key` (else read from the project's `.env.local` or `.env`) |
| `SUNLICENSE_PUBLIC_KEY` | Public key for `verify-offline` |
| `SUNLICENSE_NO_UPDATE_CHECK` | Set to `1` to turn off the daily update check |
| `SUNLICENSE_DOWNLOAD_URL` | Where `sunlicense update` downloads from (default `https://sunlicense.com/download`) |
| `NO_COLOR` | Plain output, no colours |
