Skip to content

Cursor

Token Optimizer supports Cursor through an adapter that reads Cursor’s own stored token fields, scores session quality, restores per-workspace continuity, and compresses Bash output. It is honest about the two things Cursor does not hand a companion: a billing figure and native Windows hook quoting.

Cursor IDE (Composer) and Cursor CLI (agent) share one adapter. They are one session population keyed by conversation_id.

Install from the Cursor page. The cross-platform grid is at /reference/capability-matrix/.

Cursor persists token fields across several places, so the adapter reads the most trustworthy source it can and names it, instead of summing everything.

SourceRole
state.vscdb → cursorDiskKVauthoritative per-request token fields (primary)
transcript_pathtranscript-derived estimate (fallback)
<cursor_home>/token-optimizer/sessions/<id>.jsonour durable in-flight tally (crash recovery)

Sessions are flagged by active source: cursor_state_vscdb, cursor_transcript_estimate, or cursor_tally_only.

Cost is a genuine gap, not an approximation

Section titled “Cost is a genuine gap, not an approximation”

Cursor exposes no billing figure to hooks or to the state files we read. There is no number to pass through, so the adapter surfaces cursor_no_cost_data and renders no savings headline. It is better to show no number than to show a wrong one. See the capability matrix for the red cost cell.

The installer merges six events into ~/.cursor/hooks.json and every fired event appends a line to observed-events.jsonl.

EventTO feature
sessionStartper-workspace continuity restore
preToolUse (Shell)Bash output compression via updated_input
postToolUsetally update, rewrite evidence, context nudge
preCompactrecord real context numbers (observational)
stopper-turn tally, throttled rollup + dashboard
sessionEndfinalise tally, unthrottled rollup + dashboard

The Shell rewrite inherits the existing whitelist and dangerous-character exclusions and fails closed on uncertainty. postToolUse writes rewrite: honoured or rewrite: ignored to the ledger, so compression is measured rather than presumed.

Some Cursor internals are never exposed to a companion.

GapReason
Per-session costno billing figure on hooks or in state files
Native Windows hookspersisted command is POSIX-shell quoted; cmd.exe would not parse it
Compaction steeringpreCompact is observational, not an injection point
Status line quality barno terminal hook surface for a status line

A composer killed without a clean sessionEnd never finalises its tally. The postToolUse hook keeps an in-flight tally, and rollup recovers that partial data flagged as ~est. — never silently dropped, never silently exact.

Every Cursor command needs the runtime prefix.

Terminal window
cd ~/.claude/skills/token-optimizer/scripts
TOKEN_OPTIMIZER_RUNTIME=cursor python3 measure.py cursor-summary

On Windows use python, not python3 (and install from WSL or a POSIX shell).

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

cursor-doctor names the active token source and replays the documented payloads through the installed hook command, proving which of the six events fire and whether Shell rewrites are being honoured.

The Cursor daemon port is 24846. The shared engine assigns the port, so a Cursor session’s dashboard serves on http://localhost:24846/token-optimizer.