> For the complete documentation index, see [llms.txt](https://docs.loci-dev.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.loci-dev.net/loci-plugin-for-ai-coding-assistants/loci-plugin/cli-reference-for-loci-plugin.md).

# CLI Reference for LOCI Plugin

This is the `loci` command — the analysis engine the plugin's skills call (PyPI package `loci-tools`). **This is not the same tool as the site's general "CLI" section** (that documents `loci_api`, a separate, older manual-upload tool with commands like `list-projects` and `upload`). If you're using the Claude Code plugin, this page is the one that applies.

### Installation

Installed automatically by the plugin at session start. To install or verify manually:

```
uv tool install loci-tools
loci --version
loci doctor
```

### Global behavior

Every `loci` command prints one self-describing JSON document to stdout: `{"ok": true, "data": {...}}` on success, `{"ok": false, "error": {"message": "...", "code": "..."}}` on failure. Diagnostic/progress logs go to stderr, never stdout. The `-f`/`--format` flag controls the envelope's serialization: `json` (default), `yaml`, `csv`, `tsv`, `md`, or `toon`.

**Login gate:** every command below requires a signed-in session *except* `login`, `logout`, `auth status`, and `doctor`. Two stable error codes to branch on: `auth_required` (exit 3 — not signed in / token expired) and `quota_exceeded` (exit 4 — plan limit reached).

### auth

| Command            | Flags                                                                   | Notes                                            |
| ------------------ | ----------------------------------------------------------------------- | ------------------------------------------------ |
| `loci login`       | `--auth-server URL`, `--scope SCOPE`, `--timeout SECONDS` (default 120) | Browser PKCE sign-in. Public (works signed out). |
| `loci logout`      | —                                                                       | Removes stored credential. Public.               |
| `loci auth status` | —                                                                       | Shows `signed_in`/expiry. Public.                |

### init - record how the project builds

`/loci:init` runs this for you. Use it directly to script setup, for example in CI.

| Command                    | Key flags                                                                                                                                                                                                  | What it does                                                                                                                                                                                                                                                                                                                                                                                                                      |
| -------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `loci init`                | `--project-root`, `--target` (`aarch64`, `neoverse-v2`, `armv7e-m`, `armv6-m`, `tc399`, an alias such as `cortex-m4`, or `auto`), `--compdb PATH`, `--python`, `--refresh`, `--clock VALUE`, `--confirmed` | Records how the project builds for one target in `.loci/build.yaml` (machine-local, gitignored). Never prompts: at a decision point it exits with `init_needs_user` and the candidates, so a script can answer with flags. `--refresh` re-derives the recipe; pair it with `--target` to switch target. `--clock` records the board clock, as `loci frequency set` does. `--confirmed` records that a person approved the recipe. |
| `loci init probe`          | `--project-root`, `--compdb`, `--with-make`                                                                                                                                                                | Shows what init would detect, as JSON, without writing anything. Public.                                                                                                                                                                                                                                                                                                                                                          |
| `loci init set KEY=VALUE`  | `--project-root`                                                                                                                                                                                           | Records one recipe setting, for example `rust.features=max-pure`.                                                                                                                                                                                                                                                                                                                                                                 |
| `loci init add-file <src>` | `--project-root`                                                                                                                                                                                           | Adds a compile-database entry for a new source file, derived from a neighbouring file's entry.                                                                                                                                                                                                                                                                                                                                    |

#### project

| Command        | Key flags                             | What it does                                                                          |
| -------------- | ------------------------------------- | ------------------------------------------------------------------------------------- |
| `loci project` | `--project-root`, `--source`, `--elf` | Shows which project a file or binary belongs to, and what its recipe records. Public. |

### elf - local binary analysis (no model call)

All subcommands take `--arch` except `memmap`, which auto-detects from the ELF. `--arch` accepts the 4 canonical targets (`aarch64`, `armv7e-m`, `armv6-m`, `tc399`) plus common aliases (e.g. `cortex-m4`, `cortex-m0+`, `arm64`, `armv8-a`).

| Command            | Key flags                                                                                                                                                                                           | What it returns                                                                                                                            |
| ------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
| `loci elf asm`     | `--elf` (required), `--arch`, `--functions f1,f2`, `--out-dir`, `--blocks`                                                                                                                          | Assembly, control-flow graph, and timing CSV for named functions (or all, if omitted). Bulky output goes to files; envelope carries paths. |
| `loci elf cfg`     | `--elf` (required), `--arch`, `--functions`                                                                                                                                                         | Annotated control-flow graph, written to `control-flow.txt`.                                                                               |
| `loci elf symbols` | `--elf` (required), `--arch`, `--inline-threshold N` (default 200), `--payload-format`                                                                                                              | Symbol table — inline in the response when ≤ N symbols, else spilled to a file.                                                            |
| `loci elf diff`    | `--elf`, `--comparing-elf` (both required), `--arch`                                                                                                                                                | Which functions were added/modified/removed between two binaries.                                                                          |
| `loci elf stack`   | `--elf` or `--asm` (one required), `--arch`, `--entry-functions`, `--stack-budget BYTES`, `--threshold PCT` (default 50), `--max-recursion-depth` (default 1), `--unknown-callee-size` (default 64) | Worst-case stack depth via call-graph traversal; pass/fail verdict when `--stack-budget` is given.                                         |
| `loci elf memmap`  | `--elf` (required, **no `--arch`**), `--comparing-elf`, `--map-file`, `--top-n` (default 10), `--with-heap`, `--allocators-file`                                                                    | ROM/RAM section breakdown, top consumers, optional region budgets and heap-allocation analysis.                                            |
| `loci elf slice`   | `--elf` (required), `--arch`, `--output-types` (default `asm,symbols`), `--filter-functions`                                                                                                        | Lower-level extraction primitive underlying `asm`/`symbols` — asm, symbols, blocks, segments, callgraph, or elfinfo.                       |

### build - compile sources and track how they were built

| Command               | Key flags                                                                                                                                                                                         | What it does                                                                                                                                                                                    |
| --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `loci build compile`  | `--source` (required), `--loci-target` (required; one of the 4 targets), `--context`, `--compiler-path`, `--project-root`, `--output`, `--meta-prev`, `--phase preflight\|post-edit`, `--verbose` | Compiles a C/C++/Rust source, auto-discovering compiler + flags (from `compile_commands.json`, a Makefile dry-run, DWARF in nearby objects, or defaults). Writes a `.o` + `.meta.json` sidecar. |
| `loci build diff`     | `--prev`, `--curr` (both required), `--verbose`                                                                                                                                                   | Compares two `.meta.json` records — informational only; a mismatch is a finding (`data.match: false`), never an error.                                                                          |
| `loci build print`    | `--meta` (required), `--verbose`                                                                                                                                                                  | Shows the build settings recorded for a compiled source.                                                                                                                                        |
| `loci build snapshot` | `--source` (required), `--project-root`                                                                                                                                                           | Freezes a source's `.o` + `.meta.json` as `.o.prev` before an edit, so `post-edit` can diff against it.                                                                                         |
| `loci build fresh`    | `--elf` (required), `--source-root`                                                                                                                                                               | Checks whether a binary is older than the sources it was built from, judged by file content. Public.                                                                                            |
| `loci build affected` | `--source` (required), `--project-root`, `--limit`                                                                                                                                                | Lists the translation units a header reaches. Public.                                                                                                                                           |
| `loci build python`   | `--project-root`, `--only MODULE`, `--full`, `--phase`                                                                                                                                            | Builds every module of a Python (Cython) recipe and writes the compile database. Public.                                                                                                        |
| \| `loci build clean` | `--project-root`, `--keep-turns N`, `--deep`, `--dry-run`                                                                                                                                         | Removes old LOCI build state under `.loci/build`. `--deep` also removes objects whose source is gone and stale files under `~/.loci/state`. Public.                                             |

### frequency - board clock

Timing and energy are predicted at the model's trained clock unless you set your board's clock. In a session you can just say "my board runs at 100 MHz".

| Command                      | Key flags                                             | What it does                                                                                 |
| ---------------------------- | ----------------------------------------------------- | -------------------------------------------------------------------------------------------- |
| `loci frequency show`        | `--project-root`                                      | The clock this project's timings are given at.                                               |
| `loci frequency set <value>` | `168MHz`, `'168 MHz'`, `1.2GHz`; a bare number is MHz | Sets the board clock for the whole project. Reports then say which clock the figures are at. |
| `loci frequency clear`       | `--project-root`                                      | Goes back to the model's trained clock.                                                      |
| `loci frequency models`      |                                                       | Each model's target, core and trained clock. Public.                                         |

### analyse - the analysis the skills run

Plan Guard, Save Guard and the on-demand skills run these for you. You rarely need them by hand.

| Command                        | Key flags                                                                                                    | What it does                                                                                                                            |
| ------------------------------ | ------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------- |
| `loci analyse prepare`         | `--source`, `--elf`, `--functions`, `--signals`, `--turn`, `--loci-target`, `--phase preflight\|post-edit`   | Compiles the changed translation units and writes a manifest of exactly what to measure. Free: nothing is billed.                       |
| `loci analyse measure`         | `--prepared ID\|PATH`, `--select`, `--trips LOOP=N`, `--energy`                                              | Runs a prepared manifest and judges it. Metered: billed per token measured. `--trips` sets a loop count to assume, for what-if timings. |
| `loci analyse stack`           | `--elf`, `--source`, `--entry-functions`, `--stack-budget`, `--max-recursion-depth`, `--unknown-callee-size` | Worst-case stack depth, frame sizes and structural hazards, judged against the contract. Free.                                          |
| `loci analyse memory`          | `--elf`, `--source`, `--map-file`, `--comparing-elf`                                                         | ROM/RAM footprint, judged against the contract. Free.                                                                                   |
| `loci analyse cfg`             | `--functions`, `--source`, `--elf`, `--out-dir`                                                              | Annotated control-flow graph for the named functions, compiling first if the binary is stale. Free.                                     |
| `loci analyse status`          | `--turn`                                                                                                     | This turn's manifests that are still prepared, failed, or measured with entries pending.                                                |
| `loci analyse show [ID\|PATH]` |                                                                                                              | Reprints a manifest, with its verdict if measured. Free.                                                                                |

### scratch

| Command            | Key flags | What it does                                                                                              |
| ------------------ | --------- | --------------------------------------------------------------------------------------------------------- |
| `loci scratch dir` |           | Prints a disposable working folder outside the project, created on demand and cleared after 24 h. Public. |

### contract - author and inspect the Contract Envelope

| Command                                       | Key flags                                                | What it does                                                                                                                                |
| --------------------------------------------- | -------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
| `loci contract show`                          | `--enabled-only`, `--signal` , `--function`              | Prints the current contract: entries, indices, enabled/disabled counts. Public.                                                             |
| `loci contract lint`                          | `--draft`                                                | Validates the (draft) contract for structural problems. Public.                                                                             |
| `loci contract draft add`                     | reads entry JSON from stdin                              | Stages one or more new entries as a draft. Public.                                                                                          |
| `loci contract draft show` / `clear`          | —                                                        | Views or discards the pending draft. Public.                                                                                                |
| `loci contract draft edit / disable / enable` | `--index N`                                              | Modifies one drafted entry by index. Public.                                                                                                |
| `loci contract accept`                        | —                                                        | Writes the accepted draft to `.loci/contract.yaml`, unstaged. **User-run only** — the plugin's hooks block Claude from calling this itself. |
| `loci contract escalations`                   | `--function`                                             | Which extra skills a run must invoke to satisfy the contract for the functions it touched. Public.                                          |
| `loci contract check`                         | `--measurement JSON`, `--measurements-file`, `--verbose` | Judges measurements against the contract (JSONL on stdin). Public.                                                                          |
| `loci contract suggested`                     | /                                                        | Lists the suggested entries, marked where the contract or its draft already covers them. Public.                                            |
| `loci contract init`                          | `--force`                                                | Writes starter entries into an empty contract. **User-run only.** Public                                                                    |
| `loci contract edit` / `disable` / `enable`   | `--index N`                                              | Changes one entry directly, without a draft. **User-run only.** Public.                                                                     |

All `contract` commands work signed out. `accept`, `init`, and a bare `edit`/`disable`/`enable` outside a draft are denied to Claude by a hook - authorship of a requirement belongs to the repo owner, not the agent.

### timing

| Command       | Key flags                                                                | Notes                                                                                                                                                                        |
| ------------- | ------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `loci timing` | `--csv-text` or `--csv-file` (one required), `--architecture` (required) | Sends a per-block timing CSV (produced by `loci elf asm`) to the LOCI backend; returns predicted `execution_time_ns`, `std_dev_ns`, `energy_ws` per block. Requires sign-in. |

### usage

| Command      | What it does                                                          |
| ------------ | --------------------------------------------------------------------- |
| `loci usage` | Your plan, daily/weekly quota, and usage dashboard. Requires sign-in. |

### stats / trends

| Command                     | Key flags                                                                                                                                                                              | What it does                                                                                              |
| --------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- |
| `loci trends`               | `--context-file`, `--function NAME`                                                                                                                                                    | Alias for `loci stats trend`. Measurement history for one or all tracked functions on the current branch. |
| `loci stats trend-line`     | `--function f1,f2` (required), `--context-file`                                                                                                                                        | Compact recent-values line per function.                                                                  |
| `loci stats summary`        | `--context-file`                                                                                                                                                                       | One-line summary of this branch's recorded activity.                                                      |
| `loci stats global-summary` | —                                                                                                                                                                                      | Summary across all your projects since first use.                                                         |
| `loci stats record`         | `--skill` (required), `--functions N`, `--mcp-calls N`, `--co-reasoning N`, `--verdict TEXT`, `--gates JSON`, `--commit SHA`, `--context-file`                                         | Records a completed skill run (called by the skills themselves, not typically by hand).                   |
| `loci stats measure`        | `--skill` (required), `--function` or `--stdin`, `--worst-ns`, `--happy-ns`, `--energy-uws`, `--stack-bytes`, `--rom-bytes`, `--heap-sites`, `--heap-static-b`, `--commit`, `--source` | Records per-function measurements (called by the skills themselves).                                      |

### doctor

| Command       | What it does                                                                                                                                                                                     |
| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `loci doctor` | Read-only environment diagnostics — Python version, analysis-stack imports, `c++filt`, credential store, sign-in state, state-directory writability. Public (works signed out); mutates nothing. |

### cockpit - live local dashboard

`loci cockpit` is a live terminal view of this machine's LOCI data - no browser, no sign-in required. It reads the same measurement store the skills write to, so what it shows is what your sessions have actually reported.

| Flag                     | Effect                                                                |
| ------------------------ | --------------------------------------------------------------------- |
| *(none)*                 | Opens the live TUI                                                    |
| `--once`                 | Emits one snapshot as a JSON envelope instead of the interactive view |
| `--altitude contract`    | Opens directly on the contract panel                                  |
| `--catches-only`         | Filters the event feed to non-OK verdicts only                        |
| `--project` / `--branch` | Select what to look at; both default to the most recent               |

| View         | Shows                                                                             |
| ------------ | --------------------------------------------------------------------------------- |
| `hotspots`   | Functions costing the most time, energy, and stack on this branch                 |
| `prevented`  | Regressions caught before they merged                                             |
| `time-saved` | Analysis time LOCI spent vs. the runtime measurement it replaced                  |
| `contract`   | Every bound in `.loci/contract.yaml` and the latest measurement judged against it |

Public - works fully signed out, same as `doctor`.

### Exit codes

| Exit code | Meaning                                                                                 |
| --------- | --------------------------------------------------------------------------------------- |
| 0         | Success                                                                                 |
| 1         | Unexpected error                                                                        |
| 2         | Usage error (wrong command or flag)                                                     |
| 3         | Not signed in, or the session expired (`auth_required`). Run `loci login`.              |
| 4         | The backend refused the request, including a reached plan limit (`quota_exceeded`)      |
| 5         | Command not implemented yet                                                             |
| 6         | The source tree changed since `analyse prepare` (`manifest_stale`). Nothing was billed. |
| 7         | The manifest is missing, malformed or edited (`invalid_manifest`)                       |

### Error codes

Error codes worth branching on: `auth_required` (sign in), `quota_exceeded` (plan limit; the message gives the reset time), `client_too_old` (the CLI is too old for the backend; run `/loci:setup`), `compiler_not_found` and `rust_target_missing` (the message names what to install, such as the exact `rustup target add` command).

### Internal verbs

`loci hook ...` and `loci scan` are used by the plugin's hooks. They are not meant to be run by hand.

{% hint style="info" %}
What stays on your machine: the build recipe (.loci/build.yaml) and LOCI's build output (.loci/build/) are local and never uploaded. Your source code is not uploaded either. What reaches the Portal is the measurement and what is needed to file it: the function name, the numbers, the verdict, the commit, the project and branch names, and the path of the source file each measured function came from.
{% endhint %}

{% hint style="info" %}
`loci hook …` and `loci scan` are internal verbs for the plugin's hooks and are not meant to be run by hand.
{% endhint %}

### Related pages

* [Authenticating](https://docs.loci-dev.net/loci-plugin-for-ai-coding-assistants/loci-plugin/authenticating-loci-plugin.md) — the login gate this reference assumes throughout
* [Skills Reference](https://docs.loci-dev.net/loci-plugin-for-ai-coding-assistants/loci-plugin/skills-reference-for-loci-plugin.md) — which skills call which of these commands
* [Troubleshooting](https://docs.loci-dev.net/loci-plugin-for-ai-coding-assistants/loci-plugin/troubleshooting.md)
