Skip to content

Cursor

Cursor support is in beta. Hooks are observed at runtime rather than version-gated, and the doctor reports readiness and observed events; a synthetic probe validates installed command execution, not live host firing. The installer writes native-Windows hook commands for PowerShell and cmd.exe (the Windows note below has the details); Windows execution has not been validated on a live host. The install path depends on whether you already have Token Optimizer on this machine.

  • Cursor, either the IDE or the agent CLI.
  • Python 3.x on your PATH.
  • For the fresh clone path: git.

Run from any folder. The clone creates a token-optimizer/ folder, then you move into it and install.

Terminal window
git clone --depth 1 https://github.com/alexgreensh/token-optimizer.git
cd token-optimizer
bash install.sh --cursor

The install is idempotent. It read-merges user-level hooks into ~/.cursor/hooks.json (Cursor has one shared hooks file, so foreign entries are preserved verbatim) and copies the adapter to ~/.cursor/token-optimizer/plugin/. It never writes repo-level hooks.

Because the adapter lives in your user-level hooks file, it covers the Cursor IDE and the local agent CLI only. Cursor cloud agents and self-hosted background workers do not load ~/.cursor/hooks.json; they run project-level .cursor/hooks.json and Enterprise team or managed hooks instead, so Token Optimizer does not observe those runs.

Terminal window
TOKEN_OPTIMIZER_RUNTIME=cursor python3 skills/token-optimizer/scripts/measure.py cursor-doctor --probe

cursor-doctor --probe replays the documented payloads through the installed hook command, checking how the eleven installed commands handle synthetic payloads, not proving the host fires them, and names the active token source. To preview the install without writing anything:

Terminal window
bash install.sh --cursor --dry-run

All require the TOKEN_OPTIMIZER_RUNTIME=cursor prefix.

Terminal window
measure.py cursor-install # read-merge hooks.json + copy the payload
measure.py cursor-doctor # readiness + hook-firing probe
measure.py cursor-summary # token/quality session summary
measure.py cursor-coach # coach data: sessions, quality, patterns (--json --days N --focus X)
measure.py cursor-audit # rules + hooks.json health audit (read-only)
measure.py cursor-rollup # ingest sessions into trends.db (auto on stop/sessionEnd)
measure.py cursor-uninstall # remove only what was installed

The merged hooks file carries eleven events. Everything the adapter does on each, and the output shape, is on the Cursor platform reference.

sessionStart preToolUse(Shell|Read) postToolUse preCompact stop sessionEnd
afterAgentResponse postToolUseFailure afterShellExecution subagentStart subagentStop

preToolUse carries a Shell|Read matcher so every other tool stays off the bridge’s hot path; Shell calls get output compression and Read calls get the opt-in read-cache interception.

Cursor exposes no billing figure, so there is no rate to configure. Token accounting uses Cursor’s own stored fields with a strict trust ordering (cursor_state_vscdb → cursor_transcript_estimate → cursor_tally_only), surfaced per session rather than summed.

Re-run the install after a git pull:

Terminal window
bash install.sh --cursor
Terminal window
TOKEN_OPTIMIZER_RUNTIME=cursor python3 skills/token-optimizer/scripts/measure.py cursor-uninstall

cursor-uninstall removes only the entries the installer added to ~/.cursor/hooks.json and the payload directory. Session data is left in place by design.