claude-code - 💡(How to fix) Fix [BUG] Random context usage at start of new sessions and on "/clear"

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Error Message

Error Messages/Logs

Root Cause

Because of context limits, I am forced to clear the context frequently while coding. At the same time, due to hourly rate limits, this repeated usage may be increasing the overall cost unnecessarily for the organisation.

RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • I am using the latest version of Claude Code

What's Wrong?

Hi Team,

From the recent versions and updates, I have been noticing the following issues in Claude Code:

Even after using /clear, the context always starts at around 22%. When I start new sessions, sometimes it begins at 5%, sometimes at 13%. It feels quite random. I tested this by opening multiple sessions without making any changes, and I still observed the same behaviour. Initially it doesn't show 0 or any level, as soon as I start the first message, it jumps to 22 or higher.

Ideally, when the context is cleared or a new session is started, it should begin close to 0%. But currently, it seems like some previous state or overhead is still being counted.

Because of context limits, I am forced to clear the context frequently while coding. At the same time, due to hourly rate limits, this repeated usage may be increasing the overall cost unnecessarily for the organisation.

It would be really helpful if you could look into this issue and fix it.

What Should Happen?

Claude Code should properly reset the context when using /clear or when starting a new session. The context usage should start close to 0% consistently, instead of showing random values like 5%, 13%, or 22%.

The system should not carry over any previous state or hidden usage after clearing. This will help ensure accurate context tracking and avoid unnecessary usage affecting rate limits and cost.

Error Messages/Logs

Steps to Reproduce

  1. Open Claude Code
  2. Start a new session
  3. Check the initial context usage percentage
  4. Use /clear to reset the context after reaching 100% or wait for 1-2 compact sessions to get over. That will give the accurate results. Then use "/clear" or start new sessions. Observe no percent is being shown now. Now enter any first message and click "Enter".
  5. Check the context usage again
  6. Repeat by opening multiple new sessions without making any changes Observed: The context usage starts at different values like 5%, 13%, or 22%, even after clearing or starting a new session.

Claude Model

Not sure / Multiple models

Is this a regression?

Yes, this worked in a previous version

Last Working Version

No response

Claude Code Version

2.1.114

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Warp

Additional Information

No response

extent analysis

TL;DR

The issue can be mitigated by investigating and adjusting the context reset mechanism in Claude Code to ensure it properly clears previous state and hidden usage.

Guidance

  • Investigate the /clear command's implementation to ensure it correctly resets the context and removes any previous state or hidden usage.
  • Verify that the context usage percentage is being calculated correctly and that there are no underlying issues with the Anthropic API or Claude Code's integration with it.
  • Test the context reset mechanism with different models and scenarios to identify any potential inconsistencies or edge cases.
  • Consider adding logging or debugging statements to track the context usage and reset process to gain more insight into the issue.

Example

No code snippet is provided as the issue does not contain sufficient technical details to create a relevant example.

Notes

The issue may be related to a regression in the Claude Code version 2.1.114, and investigating the changes made in this version may help identify the root cause. Additionally, the fact that the issue occurs with multiple models and on different sessions suggests that the problem may be more complex and require a thorough examination of the code and its interactions with the Anthropic API.

Recommendation

Apply workaround: The user can try to manually track and manage their context usage to minimize the impact of the issue until a fix is available. This can be done by regularly checking the context usage percentage and adjusting their usage patterns accordingly.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix [BUG] Random context usage at start of new sessions and on "/clear"