Repository navigation
fix(auth-cursor): stop reporting the run's usage total on replies - #1
Merged
Merged
Conversation
Cursor reports token usage once per run, and one run spans every tool round of a client turn. The plugin put that run total on the final reply as if it were this request's usage, so it counted the turn's whole context again for each round. Clients that size their context from usage read it as overflow: Hermes logged in=1,746,716 for a ~58K request on a 500K-window model and compressed its context at the start of every turn. Replies now carry no usage, the same as tool-call replies already did. LiteLLM and other OpenAI-compatible callers estimate it per request. The run total stays on the `cursor request completed` log line. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was broken
Cursor reports token usage once per run, and one run spans every tool round of a client turn (the plugin parks the run on each client tool call and resumes it with the result). The plugin put that run total on the final reply as if it were this request's usage (
convertUsage(result.usage)inbuildCompletion/buildStreamChunk). So the last reply of a turn counted the turn's whole context again for every round.A Hermes agent on
cursor/grok-4.7(500K window) logged this on the final reply of a 17-call turn whose real prompts were about 40–58K each:Hermes sizes its context from
prompt_tokens, so the next message always started with a compression (context compression started … tokens=~3,680,991) even though the real context was about 35K. In one session, 13 such replies made up 39.9M of the 66.4M input tokens logged.Reproduced straight against CLIProxyAPI with three tool rounds and then a text answer on a ~1.3K prompt: the tool-call replies carried no
usage, and the final reply carriedprompt_tokens: 13490.What changed
usage, the same as tool-call replies already did. LiteLLM and other OpenAI-compatible callers estimate usage per request.cursor request completedlog line (request_log.gois unchanged).chatCompletion.Usageis removed. Tests now assert that no reply has ausagefield.Testing
go vet ./...,gofmt -l .(clean),go test ./...pass.Not covered
input_tokensalready includescache_read_tokens;convertUsageadds them for the log line.🤖 Generated with Claude Code