fix: prevent token usage reset to 0 during /compact command#1723
Draft
reverb256 wants to merge 2 commits intoPostHog:mainfrom
Draft
fix: prevent token usage reset to 0 during /compact command#1723reverb256 wants to merge 2 commits intoPostHog:mainfrom
reverb256 wants to merge 2 commits intoPostHog:mainfrom
Conversation
The selectedSkill useMemo returned skills[0] as a fallback when selectedPath was null, meaning the sidebar never closed because !!selectedSkill was always true when skills existed. Changed both fallback returns to null so the sidebar correctly closes when the close button or card toggle sets selectedPath to null. Fixes PostHog#1649
When using the /compact command, the token usage UI was incorrectly showing 0 tokens used instead of preserving the actual token usage. This was caused by the Claude agent sending a usage_update with used: 0 when handling compact_boundary system messages. This fix removes the incorrect usage_update that was being sent during compaction, preserving actual token usage. Fixes PostHog#1714
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
Fixes #1714
When using the
/compactcommand, the token usage UI incorrectly showed 0 tokens used instead of preserving the actual token usage.Root Cause
ClaudeAcpAgentwas sendingusage_updatewithused: 0when handlingcompact_boundarysystem messages. This immediately reset the token count in the UI.Fix
Removed the
usage_updatecall duringcompact_boundaryevents. Token usage is already properly updated on the next result message (which naturally happens after compaction). Theused: 0call was a premature reset with no benefit.Changes
packages/agent/src/adapters/claude/claude-agent.ts— removed 7 lines that sentusage_updatewithused: 0during compact_boundaryTesting
/compact