Skip to content

Fix HUD context percentage to match /context across window sizes#49

Closed
StephenJoshii wants to merge 1 commit intojarrodwatts:mainfrom
StephenJoshii:fix-context-percentage-mismatch
Closed

Fix HUD context percentage to match /context across window sizes#49
StephenJoshii wants to merge 1 commit intojarrodwatts:mainfrom
StephenJoshii:fix-context-percentage-mismatch

Conversation

@StephenJoshii
Copy link

Summary

Fixes #48

Fix context percentage mismatch between HUD and /context command for context windows larger than 200k tokens.

The autocompact buffer was hardcoded as 45000 tokens, which only worked correctly for 200k windows (45k = 22.5% of 200k). For larger windows (500k, 1M), the HUD showed significantly lower percentages than /context.

Changed the buffer from a fixed value to a dynamic 22.5% of the context window size:

// Before
export const AUTOCOMPACT_BUFFER = 45000;

// After
export const AUTOCOMPACT_BUFFER_PERCENT = 0.225;
const autocompactBuffer = size * AUTOCOMPACT_BUFFER_PERCENT;

Window | Before | After | /context
200k | 45% | 45% | 45%
500k | 23% | 36% | 36%
1M | 9% | 27% | 27%

Testing

  • npm test
  • npm run test:coverage

Checklist

  • Tests updated or not needed
  • Docs updated if behavior changed

@StephenJoshii
Copy link
Author

simply changed the hardcoded 45000 buffer to a dynamic: windowSize * 0.225.

@jarrodwatts
Copy link
Owner

Thanks @StephenJoshii - but what claude models have context windows that are not 200k?

saw this issue raised once before but wasn't sure how people run into it

@StephenJoshii
Copy link
Author

Larger enterprise/ preview models, or any setup where the context size is set differently. In those cases the hardcoded value stops matching the intended behavior.

jarrodwatts added a commit that referenced this pull request Jan 9, 2026
- Change hardcoded 45k buffer to 22.5% of context window
- Scales correctly for enterprise windows (>200k)
- Add `display.autocompactBuffer` config option ('enabled' | 'disabled')
- Default 'enabled' preserves current behavior (buffered %)
- 'disabled' shows raw % for users with autocompact off

Fixes #48, #16
Related: #4, #30, #43, #49

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
jarrodwatts added a commit that referenced this pull request Jan 9, 2026
- Change hardcoded 45k buffer to 22.5% of context window
- Scales correctly for enterprise windows (>200k)
- Add `display.autocompactBuffer` config option ('enabled' | 'disabled')
- Default 'enabled' preserves current behavior (buffered %)
- 'disabled' shows raw % for users with autocompact off

Fixes #48, #16
Related: #4, #30, #43, #49

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
jarrodwatts added a commit that referenced this pull request Jan 9, 2026
* fix: use percentage-based autocompact buffer with config toggle

- Change hardcoded 45k buffer to 22.5% of context window
- Scales correctly for enterprise windows (>200k)
- Add `display.autocompactBuffer` config option ('enabled' | 'disabled')
- Default 'enabled' preserves current behavior (buffered %)
- 'disabled' shows raw % for users with autocompact off

Fixes #48, #16
Related: #4, #30, #43, #49

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* test: add autocompactBuffer tests for renderSessionLine

Address review feedback:
- Add tests verifying autocompactBuffer: 'enabled' uses buffered %
- Add tests verifying autocompactBuffer: 'disabled' uses raw %
- Add autocompactBuffer check to loadConfig test
- Update baseContext() to include autocompactBuffer

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* docs: add clickable GitHub URLs to CHANGELOG credits

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* feat: add debug log for autocompactBuffer mode

When DEBUG=claude-hud is set and autocompactBuffer='disabled',
logs both raw and buffered percentages to help troubleshoot mismatches.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
@jarrodwatts
Copy link
Owner

Thank you for the percentage-based approach! This was incorporated into #55 - the buffer is now 22.5% of context window size instead of hardcoded 45k, so it scales correctly for enterprise windows.

Credit: Your idea of using a percentage instead of fixed tokens was key to the solution. 🙏

@jarrodwatts jarrodwatts closed this Jan 9, 2026
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.

AUTOCOMPACT_BUFFER causes percentage mismatch with /context command

2 participants