@agenttrail/cli 0.2.8 → 0.2.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,340 +1,602 @@
1
- # @agenttrail/cli
2
-
3
- The `agenttrail` command connects an AI coding agent to agenttrail. Every command
4
- names the agent with `--agent claude`, `--agent cursor` or `--agent codex`; a command without one
5
- prints `choose --agent claude, --agent cursor or --agent codex`, exits 1 and changes nothing.
6
-
7
- **Codex is not yet available.** `--agent codex` is recognised so that no Codex run is ever
8
- mistaken for Claude Code's, but every command refuses it: it prints
9
- ``error: `<command> --agent codex` is not yet available.``, exits 1, and reads and writes
10
- nothing.
11
-
12
- Claude Code and Cursor are connected by different means, because they expose different
13
- things:
14
-
15
- - **Claude Code** is connected per project, opt-in — not an MCP server, not an in-process
16
- SDK, and not a long-running process. Claude Code ignores the OpenTelemetry exporter
17
- variables in a repository's `.claude/settings.json` and `.claude/settings.local.json`, so a
18
- per-project `setup` registers `Stop` and `SessionEnd` hooks in `.claude/settings.json`
19
- instead. After each turn they run `agenttrail capture --agent claude` in the background,
20
- which uploads the session from its local transcript (the same mapping, ids and edge scrub
21
- as `backfill --import`; a turn already sent is not sent again). `setup --global` keeps
22
- pointing Claude Code's own OpenTelemetry exporter at AgentTrail from
23
- `~/.claude/settings.json`, and a project-only install on such a machine leaves delivery to
24
- it. The upload logs each run to `~/.agenttrail/session-upload.log`; `status` says which path
25
- delivers this project's sessions and when the last upload succeeded.
26
- A project connected by an earlier `setup` (device login or `--key`) gets the hooks by itself at
27
- its next Claude Code session start, through the SessionStart refresh hook, as long as the repo
28
- does not track `.claude/settings.json`. A `--team` install, a repo that tracks that file, and a
29
- session start where `npx` can't reach the registry don't heal: re-run
30
- `npx -y @agenttrail/cli@latest setup --agent claude` there. `status` says `NOT SENT` until then.
31
- The upload sends prompt and tool content only when no scope Claude Code honours (managed,
32
- user or local settings, or the environment) switches it off.
33
- - **Cursor** exports no traces you can redirect, so this package supplies the
34
- runtime instead: `setup --agent cursor` registers **Cursor hook entries** in the
35
- project's `.cursor/hooks.json` that run a small capture hook, which answers `{}`,
36
- queues one file per step and exits, while a detached sender posts finished steps
37
- to ingest. See [`docs/integrations/cursor.md`](../../docs/integrations/cursor.md).
38
-
39
- Most of this README is the Claude Code path; the Cursor section below says exactly
40
- where it differs.
41
-
42
- ## Install / run (Claude Code)
43
-
44
- ### One command (recommended) — browser device login, no API key
45
-
46
- ```bash
47
- npx -y @agenttrail/cli@latest setup --agent claude # opens the browser; approve, done
48
- npx -y @agenttrail/cli@latest status --agent claude # → ACTIVE
1
+ <!-- cspell:words agenttrailhq jsonl unregister reimport freshens -->
2
+
3
+ <div align="center">
4
+
5
+ <a href="https://www.agenttrail.sh">
6
+ <picture>
7
+ <source media="(prefers-color-scheme: dark)" srcset="https://www.agenttrail.sh/brand/agenttrail_logo_white.svg" />
8
+ <img src="https://www.agenttrail.sh/brand/agenttrail_logo.svg" alt="AgentTrail" width="220" />
9
+ </picture>
10
+ </a>
11
+
12
+ # AgentTrail CLI: connect your coding agent to AgentTrail OS
13
+
14
+ **One command records your AI coding agent's sessions and enforces your team's policies.**<br />
15
+ Works with **Claude Code** and **Cursor**. Signs in through your browser, with no API key to copy.
16
+
17
+ [![npm version](https://img.shields.io/npm/v/@agenttrail/cli?color=0748FE&label=npm)](https://www.npmjs.com/package/@agenttrail/cli)
18
+ [![License: Apache-2.0](https://img.shields.io/badge/license-Apache--2.0-0748FE)](https://www.apache.org/licenses/LICENSE-2.0)
19
+ [![Node.js 18+](https://img.shields.io/badge/node-%3E%3D18-0748FE)](https://nodejs.org/)
20
+
21
+ [Quick start](#quick-start) ·
22
+ [How it works](#how-the-cli-works) ·
23
+ [Privacy](#privacy-at-a-glance) ·
24
+ [Reference](#reference)
25
+
26
+ </div>
27
+
28
+ `agenttrail` is the command-line tool for
29
+ [AgentTrail OS](https://www.agenttrail.sh/agenttrail-os). Run it once in a project and it signs
30
+ the device in, sends each agent session to AgentTrail after every turn, and installs real-time
31
+ enforcement: before your agent runs a command or edits a file, the call is checked against your
32
+ organization's policies and can be allowed, held for a person to approve, or blocked.
33
+
34
+ ![Terminal recording, abridged: npx @agenttrail/cli setup --agent claude prints a device code, signs the device in through the browser, connects the project and turns real-time enforcement on; status --agent claude then reports the exporter ACTIVE and enforcement ON](https://www.agenttrail.sh/readme/agenttrail-cli-demo.svg)
35
+
36
+ <sub>Abridged: setup's content-capture warning is shortened, and the ids are examples.</sub>
37
+
38
+ ## Quick start
39
+
40
+ **You need:** Node.js 18 or newer, an [AgentTrail account](https://www.agenttrail.sh/signup)
41
+ (the Free plan works), and Claude Code 2.1.211 or newer, or Cursor.
42
+
43
+ ### 1. Connect a project
44
+
45
+ Run this in the project folder, in an interactive terminal:
46
+
47
+ ```sh
48
+ npx -y @agenttrail/cli@latest setup --agent claude # Claude Code
49
+ npx -y @agenttrail/cli@latest setup --agent cursor # Cursor
49
50
  ```
50
51
 
51
- Run `setup` with **no API key**: it runs the OAuth-2.0 device-authorization flow
52
- (RFC 8628, the `gh auth login` pattern) when you don't already have a valid
53
- credential — printing a short code, opening the browser to the agenttrail web app
54
- where your existing session approves it — then writes the project config. It
55
- receives a **short-lived, refreshable, ingest-scoped** credential bound to your
56
- user + active org; no API key to generate, copy, or paste. The credential lives
57
- in `~/.agenttrail/credentials.json` (mode 0600) and its ingest token is mirrored
58
- into `.claude/settings.local.json`; a registered `SessionStart` hook
59
- transparently refreshes it between sessions. Re-running `setup` with a valid
60
- credential reuses it (no browser) and just (re)writes this project's config.
52
+ `setup` opens a sign-in link (`https://www.agenttrail.sh/device?code=…`) in your browser and
53
+ prints the same link with a short code. If the browser doesn't open, paste the printed link into
54
+ one. Check that the page shows the same code, approve it while signed in to AgentTrail, and setup
55
+ finishes on its own. It then names the device, connects this project, and installs real-time
56
+ enforcement.
61
57
 
62
- (`login` / `logout` remain available as explicit session verbs — `login` does
63
- the device-auth + config write; `setup` is the credential-aware install that
64
- device-auths for you when needed.)
58
+ Each project is connected separately. Run `setup` again in every repository you want recorded.
59
+ A second project on the same machine reuses the sign-in, with no browser.
65
60
 
66
- ### API key (CI / headless / `--team`)
61
+ Using [AgentTrail Guard](https://github.com/agenttrailhq/guard)? Keep it installed: setup
62
+ checks it first and can stand it down in this project. See
63
+ [Moving from AgentTrail Guard](#moving-from-agenttrail-guard).
67
64
 
68
- Device login needs a browser, so non-interactive environments use an API key:
65
+ ### 2. Check that it worked
69
66
 
70
- ```bash
71
- export AGENTTRAIL_API_KEY="dlv_live_..."
72
- npx -y @agenttrail/cli@latest setup --agent claude --org <your-org-uuid>
73
- npx -y @agenttrail/cli@latest status --agent claude
67
+ ```sh
68
+ npx -y @agenttrail/cli@latest status --agent claude # AgentTrail exporter: ACTIVE
69
+ npx -y @agenttrail/cli@latest status --agent cursor # Capture: ON for <folder>
74
70
  ```
75
71
 
76
- ### What `setup --agent claude` writes in your repo
77
-
78
- The default setup keeps everything about **this machine** out of git, so a trial run does
79
- not leave a change for you to commit or a flag for your teammates to inherit:
80
-
81
- - **Real-time enforcement** (the policy endpoints, the token and the
82
- `AGENTTRAIL_PEP_ENFORCE` switch) and the ingest token go into
83
- `.claude/settings.local.json`.
84
- - `.claude/settings.local.json` and `.agenttrail.json` (and the temporary copies a write
85
- leaves for a moment) are kept out of git with lines in the repo's own `.git/info/exclude`,
86
- which git reads like `.gitignore` but never tracks. Setup checks with git that they are
87
- ignored, and never edits `.gitignore`.
88
- - The **telemetry settings** (`CLAUDE_CODE_*`, `OTEL_*` and the `SessionStart` refresh hook)
89
- still go into `.claude/settings.json`, which is usually committed. Apart from moving an
90
- older install's enforcement keys out of that file (below), that is the only tracked change
91
- setup makes today. A `.agenttrail.json` the repo already tracks is left as it is.
92
-
93
- If the repo **already tracks** `.claude/settings.local.json` (or a `.gitignore` rule
94
- re-includes it), that file would carry your credential into git, so setup **writes nothing**
95
- and stops with the reason and the fix: `git rm --cached .claude/settings.local.json` and
96
- commit (or remove the re-including rule), then run setup again. AgentTrail is not connected in
97
- that repo until then. The same applies to `.agenttrail.json` when it would hold an API key.
98
-
99
- `--team` is the explicit "write committable config" path: key-free settings meant to be
100
- committed, and never the `AGENTTRAIL_PEP_ENFORCE` switch or a token.
101
-
102
- An older version wrote the enforcement settings into `.claude/settings.json` and appended
103
- lines to `.gitignore`. Running `setup` again moves the settings to
104
- `.claude/settings.local.json` once enforcement is verified again (if `settings.json` is
105
- committed, commit that change), and removes the `.gitignore` lines it added if they were never
106
- committed. `logout` removes the enforcement settings from both files; the
107
- `.git/info/exclude` lines stay, because the files they hide can still hold your own settings.
108
-
109
- ## Already using AgentTrail Guard?
110
-
111
- You don't need to uninstall it. Run `setup --agent claude` in each project you want AgentTrail OS
112
- to decide in; AgentTrail Guard keeps protecting every other project.
113
-
114
- 1. **Setup checks your AgentTrail Guard first, before writing anything.** If your version can't
115
- stand down for AgentTrail OS, setup stops and prints how to update it (or to uninstall it, or to
116
- use `--global`, which offers to remove it).
117
- 2. **It shows what AgentTrail OS won't enforce yet**, after enforcement is verified: your own rules,
118
- library rules your organization turned off, and stricter actions. With nothing missing, AgentTrail
119
- Guard stands down in this project. Otherwise setup asks (default no); without a terminal, pass
120
- `--accept-guard-gap`. An organization with no enabled policies never gets AgentTrail Guard stood
121
- down. After you apply the import, `setup --stand-down-guard` stands it down.
122
- 3. **Standing down is recorded only on this machine**, in `~/.agenttrail/os/enforced-projects.json`
123
- (mode 0600). AgentTrail Guard steps aside in a project only when that record, the enforcement
124
- settings, the credential and the enabled plugin all agree, so a repository's own settings can't
125
- make it stand down. When anything disagrees, both run: two prompts, never none.
126
- 4. **Your settings come with you through a file.** Setup writes `~/.agenttrail/os/guard-import.json`
127
- (mode 0600, no token in it) and prints its SHA-256. In the app, **Governance → Import from Guard**
128
- reads it in your browser, shows every change in full, and applies the ones you tick. Your
129
- allowlist and any action you made weaker don't carry over.
130
- 5. **What changes:** setup prints it, computed from your settings: what happens when AgentTrail can't
131
- be reached, `ask` rules becoming holds in the approval queue, and that your `permissions.allow`
132
- rules can't skip an approval while a reviewer can still answer it.
133
-
134
- `status` says whether AgentTrail Guard stands down in the current project, and lists what isn't
135
- enforced until your import is applied. `logout` takes the project out of the record, and AgentTrail
136
- Guard enforces there again from the next tool call.
137
-
138
- For Cursor, setup stops while AgentTrail Guard's Cursor hooks are installed: remove them with
139
- `npx -y @agenttrail/guard@latest uninstall --agent cursor` first.
140
-
141
- ## Cursor (`--agent cursor`)
142
-
143
- ```bash
144
- npx -y @agenttrail/cli@latest setup --agent cursor # in the folder you open in Cursor
145
- npx -y @agenttrail/cli@latest status --agent cursor # → Capture: ON for <folder>
72
+ `status` reads only local files and makes no network call.
73
+
74
+ ### 3. Finish agent setup
75
+
76
+ - **Claude Code:** start a new session in the project. The first upload happens after your
77
+ first turn, and `status` then shows when it succeeded.
78
+ - **Cursor:** open the same folder in Cursor, trust the workspace when Cursor asks, and use
79
+ the agent in an editor window. Cursor runs a project's hooks only in a trusted workspace.
80
+
81
+ ### Sign out
82
+
83
+ ```sh
84
+ npx -y @agenttrail/cli@latest logout --agent claude # or: --agent cursor
146
85
  ```
147
86
 
148
- Run it in the folder you open in Cursor, and trust the workspace when Cursor asks:
149
- Cursor loads hooks from the folder it opens, and runs a project's hooks only in a
150
- trusted workspace.
87
+ `logout` revokes this device's sign-in and removes enforcement. What it keeps and removes is
88
+ in [Disconnecting](#disconnecting).
89
+
90
+ Prefer a guided walkthrough? See [Get started](https://www.agenttrail.sh/get-started).
91
+
92
+ ## Why the AgentTrail CLI?
93
+
94
+ Your coding agent runs commands and edits files faster than anyone can review each one, and
95
+ most of what it does is never recorded anywhere you can search later. The CLI connects that
96
+ work to AgentTrail OS, so you and your team can:
151
97
 
152
- What differs from `--agent claude`:
98
+ - **See every session.** Prompts, commands, file changes, tokens and cost for each turn, in
99
+ one searchable history per project.
100
+ - **Enforce policies before a call runs.** Your organization's policies are checked on every
101
+ tool call, with approvals routed to a person when a policy asks for one.
102
+ - **Start with history.** `backfill` imports the sessions already on your disk, so the
103
+ dashboard has data on day one.
104
+ - **Keep secrets out.** Content is scrubbed for secret-shaped values before it leaves the
105
+ machine, and again when AgentTrail receives it. You can turn content capture off entirely.
106
+ - **No key handling.** Device sign-in issues a short-lived, refreshable credential for this
107
+ device alone, kept in your home folder rather than the repository. Revoke a device from the
108
+ AgentTrail app at any time.
153
109
 
154
- | | Claude Code | Cursor |
155
- |---|---|---|
156
- | How spans are produced | per project: our `Stop` / `SessionEnd` hooks upload each session from its transcript; `--global`: Claude Code's own exporter, configured by us | our capture hook + a detached sender, both under `~/.agenttrail/cursor/runtime/` |
157
- | What is written in the repo | the capture hooks and resource attributes in `.claude/settings.json`; everything per-machine in `.claude/settings.local.json`, kept out of git via `.git/info/exclude` | `.cursor/hooks.json`, kept out of git via `.git/info/exclude` |
158
- | State | `~/.agenttrail/credentials.json` | `~/.agenttrail/cursor/` (its own credential, registry, queue and checkpoint) |
159
- | Auth | device login, or `--key` / `--team` for CI | device login only — `--key`, `--team` and `--global` are refused |
160
- | Content capture | **on by default** (`--no-capture-content` opts out); scrubbed at ingest | off by default (`--capture-content` turns it on); scrubbed **on this machine** before it is queued, then server-side as well |
161
- | Cost | tokens × the provider's list price | not computed: Cursor sessions read "Not reported by Cursor" |
162
- | Real-time blocking | the enforcement plugin | from Cursor 3.21.16, installed by `setup`; an older Cursor is captured only |
110
+ ## How the CLI works
163
111
 
164
- Two behaviours have no Claude Code counterpart:
112
+ **Claude Code**
165
113
 
166
- - **A repo that already tracks `.cursor/hooks.json`** gets its entries in
167
- `~/.cursor/hooks.json` instead, each behind a `/bin/sh` gate that compares
168
- `$CURSOR_PROJECT_DIR` against your connected folders and answers `{}` without
169
- reading stdin anywhere else. A laptop-wide file still behaves per project.
170
- - **A workspace opened on a subfolder** loads only that subfolder's hooks, so setup
171
- run there writes its entries too, under the same project.
114
+ 1. **`setup` registers hooks in the project's `.claude/settings.json`.** At the end of each
115
+ turn, a `Stop` hook runs `agenttrail capture` in the background.
116
+ 2. **`capture` reads the session from Claude Code's local transcript**, scrubs it, and sends
117
+ the new turns to AgentTrail. A turn already sent is not sent again.
118
+ 3. **An enforcement plugin checks each tool call.** Before Claude Code runs a command, an
119
+ edit, a read or an MCP call, the plugin's `PreToolUse` hook asks AgentTrail for a
120
+ decision. A policy can block the call or hold it until a person approves it in the app.
121
+ 4. **A `SessionStart` hook keeps the sign-in fresh.** It refreshes the credential only when
122
+ it is about to expire, so a normal session start does nothing.
172
123
 
173
- `setup --agent cursor --unregister` disconnects one project; `logout --agent cursor`
174
- removes this machine's Cursor state and revokes the device.
124
+ **Cursor**
175
125
 
176
- ## Commands
126
+ 1. **`setup` writes hook entries into the project's `.cursor/hooks.json`.** They run a small
127
+ capture hook that queues each step on disk and exits at once.
128
+ 2. **A detached sender uploads finished steps**, so the agent never waits on the network.
129
+ 3. **On Cursor 3.21.16 or later, enforcement entries are added** next to the capture ones and
130
+ check each tool call against your policies.
177
131
 
178
- Each runs as `npx -y @agenttrail/cli@latest <command> --agent <claude|cursor|codex>`. With
179
- `--agent codex`, every command below refuses: Codex is not yet available.
132
+ When enforcement is on and AgentTrail cannot be reached, the call is checked against the
133
+ last policy snapshot cached on your machine. With no snapshot, the call is **blocked**:
134
+ enforcement fails closed, unlike [AgentTrail Guard](#agenttrail-cli-and-agenttrail-guard).
135
+ Read [what the CLI does not do](#what-the-cli-does-not-do) before relying on it.
136
+
137
+ ## The commands
138
+
139
+ Every command runs as `npx -y @agenttrail/cli@latest <command> --agent <claude|cursor>`.
180
140
 
181
141
  | Command | What it does |
182
- |---|---|
183
- | `login` | Browser device-auth (RFC 8628); writes `~/.agenttrail/credentials.json` (0600) + the OTLP header + a `SessionStart` refresh hook. No API key. With `--agent cursor`: the Cursor device session only, written to `~/.agenttrail/cursor/credentials.json` — no project files and no hook. |
184
- | `login --refresh` | Refresh the ingest token **only when it's near expiry** (the `SessionStart` hook path; a no-op on a normal day). Inside Cursor, the Claude Code hook that calls this recognises Cursor's payload and exits 0 having done nothing. |
185
- | `logout` | Revoke the device session and clear the local credential + header. Also tears down enforcement: removes the agenttrail enforcement plugin **and** its `agenttrail` marketplace declaration from your user settings (best-effort — never fails the logout). With `--agent cursor`: flushes what is queued, removes our hook entries from every connected folder and from `~/.cursor/hooks.json`, deletes everything under `~/.agenttrail/cursor/` bar the folder and the credential the revoke clears — the import checkpoint included, since it names every conversation this machine imported — and revokes the Cursor device. |
186
- | `setup` | One-command install. No key → browser device-auth (reuses a valid credential, else runs the flow), then writes config. `--key`/`--team` → the API-key/CI path. With `--agent cursor`: device-auth only, and it connects **this one project** — `--unregister` disconnects it again. |
187
- | `status` | Report whether the exporter is active in the current directory (incl. the on-disk OTLP endpoint). With `--agent cursor`: whether capture is ON, BROKEN or NOT INSTALLED here, the entries in each connected folder, the backlog, the newest Cursor version seen, and what the sender last uploaded or dropped. |
188
-
189
- ## Flags
190
-
191
- | Flag | Effect |
192
- |---|---|
193
- | `--agent <claude\|cursor\|codex>` | Required on every command: the agent to connect. `codex` is refused by every command until its support ships (not yet available); anything else is refused before any change is made. |
194
- | `--org <uuid>` | Org UUID the API key belongs to (required). |
195
- | `--project <slug>` | Override the derived project slug. |
196
- | `--developer <uuid>` | Per-machine developer id (optional). |
197
- | `--key <dlv_...>` | API key for the CI/headless path (default: `$AGENTTRAIL_API_KEY`). When omitted (and not `--team`), `setup` uses browser device-auth. Refused by `setup --agent cursor`. |
198
- | `--endpoint <url>` | OTLP ingest base URL. Precedence: flag → `$AGENTTRAIL_INGEST_ENDPOINT` → prod default (`https://ingest.agenttrail.sh`). Point at a self-hosted ingest, e.g. `--endpoint http://localhost:4318`. |
199
- | `--api-endpoint <url>` | API base URL for the device-auth flow (`setup`/`login`/`--refresh`/`logout`). Accepts a **bare origin** (e.g. `https://api.agenttrail.sh` or `http://localhost:3000`); the CLI derives the `/api/v1` base internally (idempotent if you pass `…/api/v1`). Precedence: flag → `$AGENTTRAIL_API_ENDPOINT` → prod default (`https://api.agenttrail.sh`). Distinct from `--endpoint` (ingest). |
200
- | `--team` | Write committable, **key-free** config (key supplied per-dev via env). Refused by `setup --agent cursor`. |
201
- | `--global` | Configure `~/.claude` + `~/.agenttrail/config.json` (per-user; prints a privacy warning). Refused by `setup --agent cursor` — Cursor is per project only. |
202
- | `--no-capture-content` | `--agent claude`: turn OFF prompt/tool-content capture, which is **on by default** (prompts, commands, file paths and tool output). Setup writes the three content flags as `"0"`, and a later rerun without a flag keeps that opt-out. |
203
- | `--capture-content` | `--agent claude`: turn capture back on after `--no-capture-content` (on is already the default). `--agent cursor`: turn ON prompt/tool-content capture. Ingest scrubs it server-side under your org's config; with `--agent cursor` it is also scrubbed **on this machine** before it is queued — the scrubber reads the whole value, and the 8192-character cap applies to what is kept afterwards. Scrubbing is shape-based, so it reduces exposure rather than guaranteeing none; the cap is a size limit on what is stored, not a safety measure. |
204
- | `--accept-guard-gap` | `setup --agent claude` with AgentTrail Guard installed: stand AgentTrail Guard down in this project even though it enforces rules your organization doesn't (setup lists them). Without it, a run with no terminal leaves both running. |
205
- | `--stand-down-guard` | `setup --agent claude`: stand AgentTrail Guard down here now, after you have applied your import in the app. Never with an organization that has no enabled policies. |
206
- | `--unregister` | `setup --agent cursor` only: disconnect this project — remove its entries and its registry record, leaving every other project connected and this device signed in. |
207
-
208
- ## Key facts
209
-
210
- - **Device login is the no-key path**. The ingest token (7-day TTL,
211
- `traces:write` only) is refreshed transparently by `login --refresh`, wired to
212
- a `SessionStart` hook that refreshes **only when the token is near expiry** —
213
- so a normal session start is a no-op (no rotation, no race). Concurrent
214
- refreshes on one machine are serialized by a `credentials.json` file lock, so
215
- two Claude windows never self-revoke. `logout` revokes the session server-side
216
- (ingestion stops within ~60s). Manage devices under Settings → Connected
217
- Devices in the web app.
218
- - **Per-project, inactive when unconfigured** — no silent global fall-through;
219
- nested repos do not inherit a parent's config (resolution stops at the git root).
220
- - **`CLAUDE_CODE_ENHANCED_TELEMETRY_BETA=1` is required** — span emission is a
221
- Claude Code beta feature, OFF by default; the writer always sets it.
222
- - **Claude Code content capture is ON by default**: `setup` writes the three
223
- `OTEL_LOG_*` content flags, so prompts, commands, file paths and tool output reach
224
- AgentTrail. `--no-capture-content` opts out (metadata + tokens only), and `setup`
225
- and `status` both print which mode is on. Cursor stays off unless you pass
226
- `--capture-content`. A committed `.claude/settings.json` (under `--team`, or in a
227
- repo that tracks it) carries the flags to every teammate; a teammate opts out for
228
- themselves by setting the three flags to `"0"` in their own
229
- `.claude/settings.local.json`. Claude Code's own exporter sends the content, so nothing
230
- scrubs it on your machine; ingest scrubs captured content under your org's configured mode, falling
231
- back to the deployment-wide `SCRUB_MODE` — never to no scrubbing. The one
232
- passthrough is an org explicitly setting `mode: "off"`, which opts out by choice.
233
- Scrubbing is shape-based, so a structureless secret can still get through; the
234
- residual-risk section of the Claude Code guide spells out what that means.
235
- - **Endpoint is configurable** but defaults to the hosted ingest. Precedence is
236
- `--endpoint` → `$AGENTTRAIL_INGEST_ENDPOINT` → `https://ingest.agenttrail.sh`. An
237
- explicitly-provided value (flag or env) is validated as an absolute `http(s)`
238
- URL and its trailing slash stripped (Claude Code appends `/v1/traces`). The
239
- endpoint is non-secret, so it is written to the committable
240
- `.claude/settings.json`; `status` reports the value on disk.
241
- - **Project id** is a deterministic, cross-tenant collision-safe UUIDv5:
242
- `uuidv5(AGENTTRAIL_PROJECT_NS, "<orgId>:<projectSlug>")` with a frozen namespace
243
- (`18a5d968-0fa2-5c8a-88da-0b29d80105d4`). With **no git remote** the slug falls
244
- back to the directory name and the CLI warns that the identity may be unstable
245
- across machines — add an `origin` remote for a stable identity.
246
- - **Agent id** (`agenttrail.agent.id`) identifies the **agent tool** — a separate
247
- dimension from the repo. `uuidv5(AGENTTRAIL_AGENT_NS, "<orgId>:<vendor>")` in its
248
- own frozen namespace (`7f050af4-796e-5b05-94c2-dba78bcdc7c2`), so an agent id can
249
- never equal a project id. Stamped on both live capture and backfill; one agent per
250
- vendor per org, so a repo used from both Claude Code and Cursor is **one project
251
- with two agents**, not two projects.
252
-
253
- ## Backfill — import past sessions
254
-
255
- ### Claude Code history
256
-
257
- Claude Code capture is forward-only, but Claude Code persists full session
258
- transcripts locally at `~/.claude/projects/<project>/<session>.jsonl`. `backfill`
259
- reads those transcripts, maps each session to an OTLP trace, and replays them
260
- through the same `POST /v1/traces` pipeline live capture uses — so a new user's
261
- dashboard + pattern detector have real history on day one.
262
-
263
- ```bash
264
- npx -y @agenttrail/cli@latest backfill --scan --agent claude # JSON inventory; uploads nothing
265
- npx -y @agenttrail/cli@latest backfill --import --agent claude [--dry-run] # parse + upload
266
- npx -y @agenttrail/cli@latest backfill --import --agent claude --since 7d
267
- npx -y @agenttrail/cli@latest backfill --status --agent claude # show the checkpoint
268
- npx -y @agenttrail/cli@latest backfill --resume --agent claude # continue (skip done, retry failed)
142
+ | --- | --- |
143
+ | `setup` | Sign in through the browser if needed, connect this project, and install enforcement. Safe to re-run. |
144
+ | `status` | Show what is connected here, the last upload, and the enforcement state. Local only. `doctor` is the same command. |
145
+ | `backfill` | Import the sessions already on your disk for this project. See [Backfill](#backfill). |
146
+ | `device rename "<name>"` | Change the name your organization's admins see for this device. |
147
+ | `login` | Sign the device in without connecting a project. `login --refresh` is what the `SessionStart` hook runs. |
148
+ | `logout` | Revoke this device's sign-in and remove enforcement. |
149
+
150
+ `--agent` is required on every command. Without it, the command prints
151
+ `error: choose --agent claude, --agent cursor or --agent codex`, exits 1, and changes nothing.
152
+ Run `npx -y @agenttrail/cli@latest --help` for every option.
153
+
154
+ ## Agent support
155
+
156
+ | Agent | Status |
157
+ | --- | --- |
158
+ | Claude Code | Supported. Session upload, enforcement (Claude Code 2.1.211 or newer), backfill. Per project, or machine-wide with `--global`. |
159
+ | Cursor | Supported. Session upload and backfill per project. Enforcement needs Cursor 3.21.16 or later; see [Cursor's limits](#cursors-limits). Cursor's cloud agents are not covered. |
160
+ | Codex CLI | Not yet available. Every command refuses `--agent codex`, prints ``error: `<command> --agent codex` is not yet available.``, and changes nothing. |
161
+
162
+ ## Privacy at a glance
163
+
164
+ - **Reads:** the agent's local session files (Claude Code's transcripts, or Cursor's hook
165
+ events), and the tool call your agent is about to make when enforcement is on.
166
+ - **Sends:** to `ingest.agenttrail.sh`, each session's turns: timings, tool names, models,
167
+ token counts, and, when content capture is on, prompts, commands, file paths and tool
168
+ output. To `api.agenttrail.sh`, sign-in, policy checks, and whether enforcement is on for
169
+ this device. Nothing is sent before you sign in.
170
+ - **Keeps:** a credential and small state files under `~/.agenttrail/`, written at mode `0600`.
171
+ See [Files it keeps](#files-it-keeps).
172
+
173
+ **Content capture is on by default for Claude Code and Cursor.** Pass `--no-capture-content`
174
+ to `setup` to send metadata and token counts only, and a later `setup` keeps that choice. For
175
+ Claude Code, a content setting of off in its own managed, user or local settings, or in the
176
+ environment, turns it off for the CLI too. For Cursor, a project `.agenttrail.json` that sets
177
+ `captureContent` to `false` keeps it off.
178
+
179
+ **Scrubbing is shape-based and not exhaustive.** Values that look like secrets (API keys,
180
+ tokens, connection strings, JWTs, private keys, `.env`-style assignments) and the output of
181
+ known secret-manager commands such as `op read` are replaced before content leaves your
182
+ machine, then scrubbed again at ingest under your organization's settings. A secret with no
183
+ recognizable shape, or one printed by a command the scrubber does not know, can still be
184
+ stored. If that is a risk for a project, turn content capture off there. The AgentTrail
185
+ website describes [how data is handled](https://www.agenttrail.sh/security).
186
+
187
+ ## What the CLI does not do
188
+
189
+ - **It cannot check what never reaches a hook.** Enforcement sees the tool calls each agent
190
+ sends to its hooks, and nothing the agent does outside them.
191
+ - **Some failures let a call through.** Enforcement fails closed on a network or policy
192
+ error, but if `node` is not on your `PATH`, or the plugin is uninstalled or disabled, the
193
+ hook cannot run and Claude Code's normal permission flow decides on its own.
194
+ - **It does not inspect file contents.** A policy on an edit decides by the file's path and
195
+ the tool, not by what the edit writes.
196
+ - **It is not real-time for history.** Sessions are uploaded after each turn, not while the
197
+ turn runs, and `backfill` imports only the project you run it in.
198
+ - **Hooks fetch the latest release.** The hooks run `npx -y @agenttrail/cli@latest`, so each
199
+ session start and turn end contacts the npm registry and uses the newest published
200
+ version. When the registry cannot be reached, that run is skipped, and a later run sends
201
+ the turns it missed.
202
+
203
+ ### Cursor's limits
204
+
205
+ - **Enforcement turns on only when the CLI can read Cursor's version.** Today it reads it
206
+ from `/Applications/Cursor.app` on macOS. Elsewhere, `status` reports `Enforcement: OFF`
207
+ and asks for Cursor 3.21.16 or later even when it is installed; capture keeps working.
208
+ - **An older Cursor is captured only.** Below 3.21.16, no enforcement entries are written.
209
+ - **Cursor's Agent Window can skip hooks** on versions older than 3.21.16. Use the agent in
210
+ an editor window.
211
+ - **Workspace trust cannot be checked from the CLI.** If capture shows nothing, confirm that
212
+ Cursor trusts the folder.
213
+ - **No model, tokens or cost.** Cursor's hook events and session files do not carry them, so
214
+ Cursor sessions show none.
215
+ - **Only the opened folder's hooks load.** If you open a subfolder in Cursor, run `setup` in
216
+ that subfolder too; it joins the same project.
217
+
218
+ ## AgentTrail CLI and AgentTrail Guard
219
+
220
+ [AgentTrail Guard](https://github.com/agenttrailhq/guard) is AgentTrail's free, open-source,
221
+ local-only guardrail tool. It needs no account and sends nothing. The CLI is for teams who also
222
+ want a searchable record of every session and policies managed in one place. Both use the same
223
+ open rule library, [agenttrailhq/guardrails](https://github.com/agenttrailhq/guardrails).
224
+
225
+ | | [AgentTrail Guard](https://www.agenttrail.sh/agenttrail-guard) | AgentTrail CLI, with [AgentTrail OS](https://www.agenttrail.sh/agenttrail-os) |
226
+ | --- | --- | --- |
227
+ | Where decisions are made | On your machine, from the bundled library | On AgentTrail's servers, from your organization's policies |
228
+ | Account | None | Required |
229
+ | Agents | Claude Code, Cursor, Codex CLI | Claude Code, Cursor |
230
+ | History | A capped local log, plus on-demand scan reports | Searchable session history |
231
+ | For teams | One developer, one machine | Shared policies, approvals and an audit trail, depending on plan |
232
+ | When something breaks | Fails open: your agent's normal permission flow continues | Fails closed: the action does not proceed |
233
+
234
+ **Already using AgentTrail Guard?** You don't need to uninstall it. In Claude Code, `setup`
235
+ can stand Guard down in each project you connect, so AgentTrail OS decides there and Guard
236
+ keeps protecting every other project. Guard 0.4.14 or newer is needed. See
237
+ [Moving from AgentTrail Guard](#moving-from-agenttrail-guard), and the step-by-step guide in
238
+ [AgentTrail Guard vs AgentTrail OS](https://www.agenttrail.sh/guard-vs-os#moving).
239
+
240
+ ## Troubleshooting
241
+
242
+ | What you see | What to check |
243
+ | --- | --- |
244
+ | `device login needs a browser to authorize` | Run `setup` in an interactive terminal. For CI, see [API keys](#api-keys-for-ci-and-headless-machines). |
245
+ | `AgentTrail exporter: INACTIVE` | This folder has not been set up. Run `setup` in the project root. |
246
+ | `Last session upload: none yet` | Take one turn in Claude Code in this project. The upload runs when the turn ends. |
247
+ | Setup says enforcement stayed off | Read the reason it prints. Capture keeps working; re-run `setup` once it is fixed. A `401` means the sign-in was rejected: run `logout`, then `setup`. |
248
+ | `Claude Code (claude) was not found on your PATH` | Install Claude Code, or open a terminal where `claude` runs, then re-run `setup`. |
249
+ | `Upgrade Claude Code to 2.1.211 or newer` | The enforcement plugin needs it. Update Claude Code and re-run `setup`. |
250
+ | Setup refuses because the repo tracks `.claude/settings.local.json` | That file would carry your credential into git. Run `git rm --cached .claude/settings.local.json`, commit, and run `setup` again. |
251
+ | Cursor shows `Capture: BROKEN` | Read the listed problem and re-run `setup --agent cursor` in that folder. |
252
+ | `status` says `API key: MISSING` after a browser sign-in | Expected: device sign-in uses no API key. |
253
+ | Setup stops because AgentTrail Guard can't stand down | Update Guard to 0.4.14 or newer with `npx -y @agenttrail/guard@latest init --agent claude`, then re-run `setup`. |
254
+ | Cursor setup stops because Guard's Cursor hooks are installed | Remove them with `npx -y @agenttrail/guard@latest uninstall --agent cursor`; your Guard settings stay. Then re-run `setup --agent cursor`. |
255
+
256
+ Security issue? Email [security@agenttrail.sh](mailto:security@agenttrail.sh) rather than
257
+ posting it publicly.
258
+
259
+ ## Reference
260
+
261
+ The sections below are collapsed so you can open just the one you need.
262
+
263
+ - **Setting up:** [what setup changes](#what-setup-changes), [API keys](#api-keys-for-ci-and-headless-machines),
264
+ [machine-wide and team installs](#machine-wide-and-team-installs),
265
+ [moving from AgentTrail Guard](#moving-from-agenttrail-guard), and [disconnecting](#disconnecting).
266
+ - **Day to day:** [backfill](#backfill), [device names](#device-names), and [options](#options).
267
+ - **Under the hood:** [enforcement](#enforcement), [network](#network), and [files it keeps](#files-it-keeps).
268
+
269
+ ## What setup changes
270
+
271
+ <details>
272
+ <summary>Claude Code (<code>setup --agent claude</code>)</summary>
273
+
274
+ <br />
275
+
276
+ Setup keeps everything about **this machine** out of git, so a trial run leaves no change for
277
+ you to commit:
278
+
279
+ - **`.claude/settings.json`**, usually committed, gets the capture hooks (`SessionStart`,
280
+ `Stop`, `SessionEnd`) and `OTEL_RESOURCE_ATTRIBUTES`, which names your organization, project
281
+ and agent by id. These are the only tracked changes setup makes.
282
+ - **`.claude/settings.local.json`**, never committed, gets the enforcement settings: the policy
283
+ endpoints, this device's token, a 3-second policy timeout and the `AGENTTRAIL_PEP_ENFORCE`
284
+ switch, written last and only once enforcement has been verified.
285
+ - **`.agenttrail.json`** records the organization, project, agent and the content-capture
286
+ choice. With device sign-in it holds no key.
287
+ - **`.git/info/exclude`** gets lines that keep `.claude/settings.local.json` and
288
+ `.agenttrail.json` out of git. Git reads it like `.gitignore` but never tracks it; setup
289
+ checks with git that the files are ignored, and never edits `.gitignore`.
290
+ - **The enforcement plugin** is installed for your user with Claude Code's own
291
+ `claude plugin` commands, from a local marketplace shipped inside this package.
292
+
293
+ If the repository **already tracks** `.claude/settings.local.json`, setup writes nothing and
294
+ stops with the fix. An `.agenttrail.json` the repository tracks is left as it is.
295
+
296
+ The project's identity comes from its `origin` git remote. With no remote, setup falls back to
297
+ the folder name and warns that the same repository at another path would become a different
298
+ project.
299
+
300
+ </details>
301
+
302
+ <details>
303
+ <summary>Cursor (<code>setup --agent cursor</code>)</summary>
304
+
305
+ <br />
306
+
307
+ - **`.cursor/hooks.json`** in the project gets nine capture entries, each with a short timeout,
308
+ and on Cursor 3.21.16 or later three fail-closed enforcement entries. Every other entry is
309
+ kept. The file is kept out of git with a line in `.git/info/exclude`.
310
+ - **A repository that already tracks `.cursor/hooks.json`** gets its entries in your user-level
311
+ `~/.cursor/hooks.json` instead, behind a small shell gate that answers only for your connected
312
+ folders. This needs `/bin/sh`, so it is not available on Windows.
313
+ - **`~/.agenttrail/cursor/`** holds the hook runtime, the queue, the list of connected
314
+ projects, and this machine's Cursor credential.
315
+
316
+ Cursor setup always signs in through the browser and connects one project at a time.
317
+ `--key`, `--team` and `--global` are refused. Setup also refuses a folder that contains your
318
+ home folder.
319
+
320
+ </details>
321
+
322
+ ## API keys for CI and headless machines
323
+
324
+ <details>
325
+ <summary>Set up Claude Code without a browser</summary>
326
+
327
+ <br />
328
+
329
+ Device sign-in needs a browser. On a machine without one, use an API key from the AgentTrail
330
+ app with your organization's id:
331
+
332
+ ```sh
333
+ export AGENTTRAIL_API_KEY="<your API key>"
334
+ npx -y @agenttrail/cli@latest setup --agent claude --org <your-org-uuid>
335
+ ```
336
+
337
+ `--key` passes the key on the command line instead of the environment, and
338
+ `$AGENTTRAIL_ORG_ID` can stand in for `--org`. With an API key, `.agenttrail.json` holds the
339
+ key, so it is written at mode `0600` and kept out of git like the other per-machine files.
340
+ API keys work with Claude Code only.
341
+
342
+ </details>
343
+
344
+ ## Machine-wide and team installs
345
+
346
+ <details>
347
+ <summary><code>--global</code> and <code>--team</code> (Claude Code only)</summary>
348
+
349
+ <br />
350
+
351
+ - **`--global`** connects every Claude Code session on this machine, in every folder, by
352
+ pointing Claude Code's own OpenTelemetry exporter at AgentTrail from `~/.claude/settings.json`.
353
+ It prints a warning first. Setup refuses if that file is inside a git or dotfiles repository,
354
+ because it would hold your credential. In this mode Claude Code sends the content itself, so
355
+ it is scrubbed at ingest only, not on your machine.
356
+ - **`--team`** writes key-free settings to `.claude/settings.json` that are meant to be
357
+ committed. Each developer supplies their own key through the environment. It never writes
358
+ the enforcement switch or a token.
359
+
360
+ On a machine with a `--global` install, a project connected afterwards leaves session upload
361
+ to the global exporter.
362
+
363
+ </details>
364
+
365
+ ## Moving from AgentTrail Guard
366
+
367
+ <details>
368
+ <summary>How setup stands AgentTrail Guard down, project by project</summary>
369
+
370
+ <br />
371
+
372
+ You don't need to uninstall [AgentTrail Guard](https://github.com/agenttrailhq/guard). Run
373
+ `setup --agent claude` in each project you want AgentTrail OS to decide in; Guard keeps
374
+ protecting every other project.
375
+
376
+ 1. **Setup checks Guard first, before writing anything.** If your Guard is older than 0.4.14
377
+ and can't stand down, setup stops and prints how to update it, or to uninstall it. With
378
+ `--global`, setup offers to remove Guard instead.
379
+ 2. **After enforcement is verified, it shows what AgentTrail OS won't enforce yet:** your own
380
+ Guard rules, library rules your organization turned off, and actions you made stricter.
381
+ With nothing missing, Guard stands down in this project. Otherwise setup asks, and the
382
+ default is no; without a terminal, pass `--accept-guard-gap`. An organization with no
383
+ enabled policies never gets Guard stood down.
384
+ 3. **Standing down is recorded only on this machine**, in
385
+ `~/.agenttrail/os/enforced-projects.json`. Guard steps aside in a project only when that
386
+ record, the enforcement settings, the credential and the enabled plugin all agree, so a
387
+ repository's own settings can't make it stand down. When anything disagrees, both run: two
388
+ prompts, never none.
389
+ 4. **Your settings come with you through a file.** Setup writes
390
+ `~/.agenttrail/os/guard-import.json`, with no token in it, and prints its SHA-256. In the
391
+ app, **Governance ▸ Import from Guard** reads it in your browser, shows every change, and
392
+ applies the ones you tick. Your allowlist and any action you made weaker don't carry over.
393
+ Once the import is applied, `setup --stand-down-guard` stands Guard down.
394
+ 5. **Setup prints what changes**, computed from your settings: what happens when AgentTrail
395
+ can't be reached, `ask` rules becoming holds in the approval queue, and that your
396
+ `permissions.allow` rules can't skip an approval while a reviewer can still answer it.
397
+
398
+ `status` says whether Guard stands down in the current project, and lists what isn't enforced
399
+ until your import is applied. `logout` takes the project out of the record, and Guard
400
+ enforces there again from the next tool call.
401
+
402
+ For Cursor, setup stops while Guard's Cursor hooks are installed, because Guard can't yet
403
+ stand down in Cursor. Remove them with
404
+ `npx -y @agenttrail/guard@latest uninstall --agent cursor` first; your Guard settings stay.
405
+
406
+ </details>
407
+
408
+ ## Disconnecting
409
+
410
+ <details>
411
+ <summary>What <code>logout</code> and <code>--unregister</code> remove</summary>
412
+
413
+ <br />
414
+
415
+ **Claude Code: `logout --agent claude`** revokes this device's sign-in, deletes
416
+ `~/.agenttrail/credentials.json`, removes the enforcement plugin and its marketplace, and
417
+ strips the enforcement settings from your settings files. It keeps the capture hooks in
418
+ `.claude/settings.json`, `.agenttrail.json`, and the `.git/info/exclude` lines. With no
419
+ credential the hooks upload nothing; delete them from `.claude/settings.json` to remove them
420
+ completely.
421
+
422
+ **Cursor: `logout --agent cursor`** sends what is still queued, removes the CLI's entries from
423
+ every connected folder and from `~/.cursor/hooks.json`, deletes this machine's Cursor state,
424
+ including the import checkpoint, and revokes the device.
425
+
426
+ **Cursor: `setup --agent cursor --unregister`** disconnects just this project and keeps the
427
+ device signed in.
428
+
429
+ You can also revoke a device from the AgentTrail app, under Governance ▸ Devices.
430
+
431
+ </details>
432
+
433
+ ## Backfill
434
+
435
+ <details>
436
+ <summary>Import the sessions already on your disk</summary>
437
+
438
+ <br />
439
+
440
+ ```sh
441
+ npx -y @agenttrail/cli@latest backfill --agent claude --scan # list; uploads nothing
442
+ npx -y @agenttrail/cli@latest backfill --agent claude --import --dry-run # preview
443
+ npx -y @agenttrail/cli@latest backfill --agent claude --import --since 7d # import the last week
444
+ npx -y @agenttrail/cli@latest backfill --agent claude --status # the checkpoint
445
+ npx -y @agenttrail/cli@latest backfill --agent claude --resume # skip done, retry failed
269
446
  ```
270
447
 
271
- Key properties:
272
-
273
- - **Scoped to the current project.** `--scan` / `--import` / `--resume`
274
- cover ONLY the project you run them in — matched on each session's recorded
275
- working directory, mirroring per-project `setup`. Sessions from other projects
276
- on the machine are not imported (their count is reported, never their names), and
277
- there is no flag to widen it: `cd` into another project and re-run. `--status` is
278
- the exception — it reports the machine-wide import checkpoint.
279
-
280
- - **Metadata + tokens by default.** `--content` is an explicit opt-in that also
281
- uploads prompt/tool content; that content is **scrubbed server-side** by
282
- agenttrail's ingest scrubber under your org's content-capture setting (secrets
283
- redacted; stripped entirely when the org does not capture content). No content
284
- ever leaves the machine un-gated.
285
- - **Idempotent re-import.** IDs are deterministic —
286
- `trace_id = uuidv5(sessionId, AGENTTRAIL_BACKFILL_NS)`,
287
- `span_id = sha256(sessionId+messageUuid+toolUseId)[:8B]` — and timestamps are
288
- taken verbatim from the transcript, so a second run de-dups against ClickHouse's
289
- `(org_id, trace_id)` ReplacingMergeTree instead of double-counting.
290
- - **Streaming + resilient.** Transcripts are parsed line-by-line (never whole-file);
291
- parsing discriminates on line **structure** (the transcript `version` is
292
- recorded for reporting, never used to reject); a corrupt session is quarantined
293
- and reported without aborting the run.
294
- - **Resumable.** Progress is checkpointed at `~/.agenttrail/backfill-state.json`;
295
- `--resume` skips already-imported sessions (by content hash) and retries the rest.
296
- - **Bounded + polite.** Uploads run in a bounded worker pool with exponential
297
- backoff on 429/5xx (honoring `Retry-After`), reusing your device-login token or
298
- API key.
299
-
300
- ### Cursor history
301
-
302
- ```bash
303
- npx -y @agenttrail/cli@latest backfill --agent cursor --scan # list, upload nothing
304
- npx -y @agenttrail/cli@latest backfill --agent cursor --import # first import of this project
305
- npx -y @agenttrail/cli@latest backfill --agent cursor --status # the import checkpoint
306
- npx -y @agenttrail/cli@latest backfill --agent cursor --resume # top up — skips unchanged files
448
+ - **One project at a time.** `--scan` and `--import` cover only the project you run them in,
449
+ matched on each session's recorded working directory. Other projects' sessions are counted,
450
+ never named. To import another project, run it there. `--status` is machine-wide.
451
+ - **Metadata and tokens by default.** `--content` adds prompts and tool content, scrubbed on
452
+ your machine before upload and again at ingest. `--dry-run --content` shows what would be
453
+ redacted before anything leaves the machine.
454
+ - **Safe to re-run.** Ids are derived from each session, so an import never double-counts.
455
+ Sessions AgentTrail already holds, captured live or imported before, are skipped; pass
456
+ `--reimport` to send them again.
457
+ - **Resumable.** Progress is kept in `~/.agenttrail/backfill-state.json`.
458
+
459
+ **Cursor** (`--agent cursor`) takes the same verbs, with these differences, each because of
460
+ what Cursor's session files record:
461
+
462
+ - No prompt or reply text, even with `--content`; content mode adds commands and paths only.
463
+ - Content follows the project's `setup` choice: a project with content capture on imports
464
+ commands and paths without `--content`, and one set up with `--no-capture-content` does not.
465
+ - No model, tokens or cost.
466
+ - Times are approximate, taken from the file's timestamps, and marked as such.
467
+ - `--since` is refused, because a Cursor session file has no time of its own.
468
+ - A conversation that records a path outside the project is skipped whole.
469
+
470
+ Run `setup --agent cursor` in the project first.
471
+
472
+ </details>
473
+
474
+ ## Device names
475
+
476
+ <details>
477
+ <summary>How a device is named</summary>
478
+
479
+ <br />
480
+
481
+ Claude Code setup suggests a name built from your first name and the computer's model, such as
482
+ "Sam's MacBook Pro", and you can press Enter to keep it or type your own. With `--yes`, in CI,
483
+ or without a terminal, the suggestion is used. Your organization's admins see the name beside
484
+ yours. Rename it at any time:
485
+
486
+ ```sh
487
+ npx -y @agenttrail/cli@latest device rename --agent claude "Work laptop"
307
488
  ```
308
489
 
309
- Same per-project rule, reading Cursor's own session files under
310
- `~/.cursor/projects/<encoded path>/agent-transcripts/` — this project's encoded folder,
311
- and the encoded folder of every subfolder setup has run in. Five differences from the
312
- Claude Code import, each of them a property of what Cursor records:
313
-
314
- - **it never includes what you or the agent said** — not with `--content` either. The
315
- transcript reader drops message text by design, so what content mode adds to a Cursor
316
- import is tool input: commands and paths, edge-scrubbed before they leave the machine;
317
- - **no model, no tokens, no cost and no tool-call id** — the session files hold none, so
318
- every imported span carries `agenttrail.usage.reported=false`;
319
- - **times come from the file, not the session**: each conversation's turns are spread
320
- between its file's birth and modification times (one second per turn where the file
321
- system keeps no birth time), and every span is marked
322
- `agenttrail.time.approximate=true`. **A transcript that has GROWN moves its times and
323
- re-imports as new rows** — an unchanged one reproduces them exactly and replaces its
324
- rows. `--resume` compares the source hash and skips it; a plain `--import` re-sends;
325
- - **one recorded path outside the project root drops the whole conversation**, counted
326
- `outside-root`. The encoded folder name is lossy, so that path is the only evidence we
327
- get that the wrong project was opened; a partial import would file another repo's
328
- commands here. A conversation recording no absolute path is kept;
329
- - **`--since` is Claude Code only**, and a Cursor import refuses it rather than ignoring
330
- it. A session file carries no time of its own, so a window could only come from the
331
- file's timestamps — "last touched", not "happened" — which is a different question from
332
- the one the flag asks. A Cursor import is bounded by the project, not by a date.
333
-
334
- Conversations already captured live, already imported, or still waiting in the local queue
335
- are skipped. The checkpoint is its own file,
336
- `~/.agenttrail/cursor/backfill-state.json`, and `logout --agent cursor` deletes it with the
337
- rest of this machine's Cursor state.
338
-
339
- Full guides: [`docs/integrations/claude-code.md`](../../docs/integrations/claude-code.md)
340
- and [`docs/integrations/cursor.md`](../../docs/integrations/cursor.md).
490
+ A name can be up to 64 characters. One that starts with `-` goes after `--`.
491
+
492
+ </details>
493
+
494
+ ## Options
495
+
496
+ <details>
497
+ <summary>Every option</summary>
498
+
499
+ <br />
500
+
501
+ | Option | Effect |
502
+ | --- | --- |
503
+ | `--agent <claude\|cursor\|codex>` | Required on every command. `codex` is refused for now. |
504
+ | `--no-capture-content` | Claude Code and Cursor: send metadata and token counts only. A later `setup` keeps this choice. |
505
+ | `--capture-content` | Claude Code and Cursor: turn content capture back on. |
506
+ | `--project <slug>` | Override the project name, which defaults to the git remote, then the folder name. |
507
+ | `-y`, `--yes` | Accept the suggested device name without asking. |
508
+ | `--key <key>` | Claude Code: API key for CI. Defaults to `$AGENTTRAIL_API_KEY`. |
509
+ | `--org <uuid>` | The organization the API key belongs to. Defaults to `$AGENTTRAIL_ORG_ID`. Device sign-in takes it from your account. |
510
+ | `--team` | Claude Code: write key-free settings meant to be committed. |
511
+ | `--global` | Claude Code: connect every session on this machine. |
512
+ | `--accept-guard-gap` | `setup --agent claude` with AgentTrail Guard installed: stand Guard down here even though it enforces rules your organization doesn't. Setup lists them. |
513
+ | `--stand-down-guard` | `setup --agent claude`: stand Guard down here now, after you have applied your import in the app. |
514
+ | `--unregister` | `setup --agent cursor` only: disconnect this project. |
515
+ | `--endpoint <url>` | Session upload address. Defaults to `$AGENTTRAIL_INGEST_ENDPOINT`, then `https://ingest.agenttrail.sh`. |
516
+ | `--api-endpoint <url>` | Sign-in and policy address. Defaults to `$AGENTTRAIL_API_ENDPOINT`, then `https://api.agenttrail.sh`. |
517
+ | `--refresh` | `login` only: refresh the credential if it expires within a day; otherwise do nothing. |
518
+
519
+ Backfill options are in [Backfill](#backfill), and `--help` lists them all.
520
+
521
+ </details>
522
+
523
+ ## Enforcement
524
+
525
+ <details>
526
+ <summary>How decisions are made, and what happens when something fails</summary>
527
+
528
+ <br />
529
+
530
+ Enforcement is on by default on every plan, Free included. Setup turns it on only after it
531
+ has written the settings, confirmed that AgentTrail accepts this device's credential, and
532
+ confirmed that the plugin is installed. If any step fails, setup says why, enforcement stays
533
+ off, and session upload keeps working.
534
+
535
+ On each tool call the hook asks AgentTrail for a decision, with a 3-second timeout.
536
+
537
+ - **Allowed:** the hook says nothing, and Claude Code's normal permission flow continues.
538
+ The hook never pre-approves a call.
539
+ - **Blocked:** the call does not run, and the agent is told which policy stopped it.
540
+ - **Held:** the call waits for a person to approve or deny it in the AgentTrail app, for up to
541
+ about ten minutes. Approved, it goes on to Claude Code's normal permission flow; denied, it
542
+ is blocked. If nobody answers in time, Claude Code asks you itself, and a session with no
543
+ one at the terminal cannot proceed. In Cursor, an unanswered shell command is handed back
544
+ to Cursor to ask you, and any other tool is refused.
545
+ - **AgentTrail unreachable:** the call is checked against the policy snapshot cached on your
546
+ machine. With no snapshot, it is blocked.
547
+ - **Credential rejected:** the call is blocked. At the next session start, enforcement turns
548
+ itself off until you run `setup` again, and capture continues.
549
+
550
+ Inside Cursor, the Claude Code plugin stays silent and leaves decisions to Cursor's own
551
+ entries.
552
+
553
+ </details>
554
+
555
+ ## Network
556
+
557
+ <details>
558
+ <summary>Every address the CLI contacts</summary>
559
+
560
+ <br />
561
+
562
+ | Address | When |
563
+ | --- | --- |
564
+ | `https://api.agenttrail.sh` | Sign-in and refresh; fetching the policy snapshot at setup and session start; each policy check when enforcement is on; reporting at session start whether enforcement is on for this device. |
565
+ | `https://ingest.agenttrail.sh` | Uploading sessions after each turn, from the Cursor sender, and from `backfill`; checking which sessions AgentTrail already holds before an import. |
566
+ | The npm registry | The hooks run `npx -y @agenttrail/cli@latest`. |
567
+ | `https://www.agenttrail.sh/device` | Opened in your browser during sign-in. |
568
+
569
+ `status`, `backfill --scan` and `backfill --status` make no network calls, and nothing is sent
570
+ before you sign in. Point the CLI at your own deployment with `--endpoint` and
571
+ `--api-endpoint`.
572
+
573
+ </details>
574
+
575
+ ## Files it keeps
576
+
577
+ <details>
578
+ <summary>Everything under <code>~/.agenttrail/</code></summary>
579
+
580
+ <br />
581
+
582
+ Folders are created at mode `0700` and files at `0600`.
583
+
584
+ | File | What it is |
585
+ | --- | --- |
586
+ | `credentials.json` | Claude Code's device credential. Deleted by `logout`. |
587
+ | `cursor/` | Cursor's credential, hook runtime, queue, connected projects and import checkpoint. Cleared by `logout --agent cursor`. |
588
+ | `device.json` | This device's model and name. Never your computer's hostname. |
589
+ | `machine-id`, `installs.json` | Random ids, so the app can show which devices have enforcement on. |
590
+ | `pep-snapshot.json` | The cached policy snapshot used when AgentTrail is unreachable. |
591
+ | `session-upload/` | Which turns of each session were sent, so none is sent twice. Pruned after 30 days. |
592
+ | `session-upload.log` | One line per upload, with no content or secrets. Rotated past 512 KiB. |
593
+ | `backfill-state.json` | The Claude Code import checkpoint. |
594
+ | `config.json` | Settings for a `--global` install. |
595
+ | `os/enforced-projects.json` | The projects where AgentTrail Guard stands down for AgentTrail OS. |
596
+ | `os/guard-import.json` | Your Guard settings, for **Import from Guard** in the app. Holds no token. |
597
+
598
+ </details>
599
+
600
+ ## License
601
+
602
+ Apache-2.0. See [LICENSE](https://www.apache.org/licenses/LICENSE-2.0).