Skip to content

fix: prevent token usage reset to 0 during /compact command#1723

Draft
reverb256 wants to merge 2 commits intoPostHog:mainfrom
reverb256:fix/1714-compact-token-usage
Draft

fix: prevent token usage reset to 0 during /compact command#1723
reverb256 wants to merge 2 commits intoPostHog:mainfrom
reverb256:fix/1714-compact-token-usage

Conversation

@reverb256
Copy link
Copy Markdown
Contributor

Problem

Fixes #1714

When using the /compact command, the token usage UI incorrectly showed 0 tokens used instead of preserving the actual token usage.

Root Cause

ClaudeAcpAgent was sending usage_update with used: 0 when handling compact_boundary system messages. This immediately reset the token count in the UI.

Fix

Removed the usage_update call during compact_boundary events. Token usage is already properly updated on the next result message (which naturally happens after compaction). The used: 0 call was a premature reset with no benefit.

Changes

  • packages/agent/src/adapters/claude/claude-agent.ts — removed 7 lines that sent usage_update with used: 0 during compact_boundary

Testing

  • Existing test suite passes (3,539 tests)
  • Manual verification: token usage persists correctly after /compact

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
@charlesvien charlesvien marked this pull request as draft April 17, 2026 21:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

/compact breaks token usage ui

1 participant