Unexpected Token Usage in AI Coding Tools: How to Troubleshoot Automatic Context Compaction

    A practical guide to investigating sudden usage spikes in AI coding tools. It explains how repeated context compaction, ineffective token reduction, cache invalidation, and multi-agent workflows can multiply consumption, and provides a systematic process for distinguishing service-side bugs from changes in user behavior or platform strategy.

    1. The Symptom: Usage Rises “Right Before Your Eyes”

    Many developers using subscription-based AI coding tools have recently reported a common issue: even when their daily workload has not changed significantly, their usage is being consumed much faster than before. Some users compared data from two consecutive weeks and found that consumption increased from roughly 20% of their total allocation to around 50%. Others reported that an allowance that previously supported several hours of work was exhausted within 20 minutes.

    These reports generally point to three possible causes:

    1. A service-side bug: The platform may have a problem with usage tracking, context compaction, or request routing.
    2. A policy or strategy change: The provider may have silently changed its billing rules, model routing, or risk-control logic.
    3. A change in the user’s workflow: The project may have grown, sessions may have become longer, or Subagents may be used more frequently.

    Determining which explanation is correct requires more than relying on subjective impressions. The symptoms should be broken down into measurable indicators and verified one by one.

    2. The Key Clue: Frequent Automatic Context Compaction

    Among the reported cases, the most important clue comes from an anomaly that was recorded in detail. One heavy user observed as many as 72 automatic context compaction events in a single day:

    • The primary Agent compacted 17 times.
    • Three parallel Subagents compacted 21, 17, and 17 times respectively.

    The token counts before and after compaction were even more revealing:

    • The context contained approximately 240K–250K tokens before compaction.
    • It still contained 140K–160K tokens after compaction.
    • The automatic compaction threshold appeared to be around 244,800 tokens.

    These figures raise a critical question: Was the compaction actually releasing enough usable space?

    After three compaction events, the user recorded the following input sizes for the next normal requests:

    • 241,860 tokens
    • 241,604 tokens
    • 242,041 tokens

    All three values were extremely close to the compaction threshold. This suggests that the next request could quickly trigger compaction again, creating a loop of “compaction → request → compaction.”

    The failure pattern can be represented with the following pseudocode:

    1. while true:
    2. input_tokens = build_context() # Still close to 242K after compaction
    3. if input_tokens >= COMPACTION_THRESHOLD: # Threshold: ~244.8K
    4. run_compaction() # Reduced to ~150K, then rebuilt to ~242K
    5. send_request(input_tokens)

    Each compaction is itself an additional model call with its own cost. When these calls are added to normal requests, total consumption can increase dramatically.

    3. The Ripple Effect: Cache Invalidation Makes the Problem Worse

    Automatic compaction has another hidden cost: a sharp drop in cache hit rates.

    In a normal multi-turn conversation, prefix caching can significantly reduce the effective cost of repeated context. Because the session prefix remains unchanged, much of the input can be served from cache. Once compaction rewrites the context, however, the prefix changes completely and the existing cache entries may no longer be usable. The entire context then has to be processed again at the non-cached rate.

    This creates a multiplying effect:

    1. The compaction process consumes an additional inference call.
    2. The rewritten context invalidates the cache, causing the next request to be charged at the full rate.
    3. Because the compaction does not free enough space, another compaction is triggered soon afterward, returning to step one.

    Together, these effects explain why the allowance can appear to disappear almost instantly.

    4. How to Determine Whether It Is a Bug or a Strategy Change

    Developers can use the following process to investigate the issue systematically.

    Step 1: Control the Variables

    For one or two days, use the same projects and task types as usual. Record the following for each session:

    • Input tokens
    • Output tokens
    • Number of compaction events
    • Cache hit rate

    If usage remains abnormal under comparable conditions, a change in the user’s workflow becomes less likely.

    Step 2: Check the Compaction Logs

    Most AI coding tools record automatic compaction events in session logs or notifications. Pay particular attention to two values:

    • The proportion of context retained after compaction
    • The input size of the next request after compaction

    If the post-compaction input continues to remain close to the threshold, the compaction strategy may not be working as intended. This is a strong indication of a service-side issue.

    Step 3: Manage Context Manually

    While waiting for the provider to investigate or fix the problem, several mitigation measures can help:

    • Keep individual sessions shorter. Start a new session after completing a task instead of allowing context to accumulate indefinitely.
    • Reduce the number of unnecessary parallel Subagents. Each Subagent has its own context container and can trigger compaction independently.
    • For long-running tasks, create stage summaries and use them instead of retaining the full history.
    • For very large files, provide only the relevant sections rather than the entire file, reducing context size at the source.

    Step 4: Submit Reproducible Feedback

    When reporting the issue, include specific token counts, the number of compaction events, and timestamps. Quantitative evidence is much easier for an engineering team to investigate than a general statement such as “usage has become faster.”

    5. Broader Implications: The Trade-Offs of Automatic Context Management

    This incident highlights a broader engineering challenge in long-context systems: balancing the compaction threshold, compaction ratio, and cache friendliness.

    An effective automatic compaction mechanism should meet three conditions:

    1. It should release enough space after compaction—for example, reducing the context to below 50% of the threshold.
    2. It should preserve as much of the original prefix as possible to support cache reuse.
    3. It should prevent repeated triggering near the threshold.

    If any of these conditions fails, the user experience can deteriorate quickly.

    For developers building Agent systems, this is also an important design consideration. Each Agent should have an independent context budget, and the application layer should implement its own summarization and trimming strategies instead of relying entirely on platform-level automatic mechanisms.

    Whether excessive usage can be reimbursed usually depends on the provider’s support process. Regardless of the outcome, keeping usage records and preserving session logs gives users stronger evidence and more control when similar disputes arise.