Repository navigation
fix(auth-cursor): stop reporting the run's usage total on replies - #4
Open
eric-x-liu wants to merge 1 commit into
Open
eric-x-liu wants to merge 1 commit into
eric-x-liu wants to merge 1 commit into
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.
Problem
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 when the tool result arrives. The plugin puts that run total on the final reply as if it were this request's usage (
convertUsage(result.usage)inbuildCompletion/buildStreamChunk). Tool-call replies carry no usage, so the last reply of a turn shows the whole turn's context counted again for every round.To reproduce, send a ~1.3K-token prompt through CLIProxyAPI, answer three client tool calls, then get a text answer. The tool-call replies carry no
usage, and the final reply carriesprompt_tokens: 13490.In an agent client on
cursor/grok-4.7(500K window), one 17-call turn whose prompts were about 40–58K each ended with:Clients that size their context from
prompt_tokensread that as overflow. This one compressed its context at the start of every message, even though the real context was about 35K.Change
usage, the same as tool-call replies already did. OpenAI-compatible callers such as LiteLLM estimate usage per request when it is missing.cursor request completedlog line (request_log.gois unchanged).chatCompletion.Usageis removed. Tests assert that no reply has ausagefield.Testing
go vet ./...,gofmt -l .(clean),go test ./...pass onmain.Trade-offs
convertUsageaddscache_read_tokenstoinput_tokensfor the log line. I haven't checked whether Cursor'sinput_tokensalready includes the cache reads.🤖 Generated with Claude Code