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, compresses Bash output, intercepts redundant reads (shadow-first), and captures compact checkpoints for a bounded restore. It is honest about what Cursor does not hand a companion, such as a billing figure.

Cursor also has coaching, rules audits and fleet analysis. Read blocking remains off by default and needs positive native evidence before it is armed. The synthetic doctor probe does not establish that Cursor delivered a hook in a real session.

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

Cursor cloud agents and self-hosted background workers are not covered: they load only project-level .cursor/hooks.json and Enterprise team or managed hooks, never the user-level ~/.cursor/hooks.json this adapter installs into (see Cursor’s hook docs). Token Optimizer does not observe those runs.

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 eleven events into ~/.cursor/hooks.json and every fired event appends a line to observed-events.jsonl.

EventTO feature
sessionStartper-workspace continuity restore (additional_context)
preToolUse (Shell|Read matcher)Shell: Bash output compression via updated_input; Read: read-cache interception (structure map / unchanged note, shadow by default)
postToolUsetally update, rewrite evidence, context nudge, compact-checkpoint restore
preCompactrecord real context numbers + capture a redacted checkpoint (emits user_message)
stopper-turn tally, throttled rollup + dashboard
sessionEndfinalise tally, unthrottled rollup + dashboard
afterAgentResponserecords hook-reported token fields for offline correlation, not counted in session totals
postToolUseFailureper-tool failure counts for the burn signal
afterShellExecutionrecords shell completion; rewrite evidence pairs on postToolUse
subagentStart / subagentStopsubagent fan-out counts

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 only when the executed command pairs byte-for-byte with the rewrite staged under the same tool_use_id; an unpaired execution records nothing rather than presuming. On native Windows the rewrite is disabled (record-only): its quoting is POSIX shlex and the host shell there is unverified. The Read interception emits a deny plus user_message only under an explicit per-install mode (soft_block/block in read-cache.json); the default shadow mode records what would be injected and emits nothing.

Some Cursor internals are never exposed to a companion.

GapReason
Per-session costno billing figure on hooks or in state files
Compaction steeringcheckpoint capture + one bounded restore shipped; the compaction decision itself stays host-side, and restore delivery is claimed only with positive native evidence
Status line fillan opt-in Cursor CLI statusLine command exists (cursor_statusline.py), but current context fill is unproven on Cursor, so it renders ctx ? until the payload’s occupancy is verified
Native hook deliverythe doctor replays documented payloads through the installed commands; whether Cursor itself fires every event on a given build is what the observed-events ledger reports

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.

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 for all eleven wired events — command replay, not proof Cursor itself fires them — plus 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.