Why Million-Token Context Windows Should Not Be Enabled by Default

    Million-token context windows expand what AI coding agents can process, but larger is not always better. This article explains the difference between model capacity and product defaults, why coding agents need context management, how automatic compaction works, when large windows are useful, and which engineering practices help balance quality, latency, and cost.

    1. Model Capacity Is Not the Same as the Product Default

    When a model is described as supporting a million-token context window, this usually refers to the theoretical capability of the model or API. It means that a single request may accept a very large amount of input, including conversation history, tool results, and other context. It does not mean that every application should expose the full window to every session by default.

    AI coding agents typically use a more conservative context limit for three main reasons:

    1. Cost control: The more context a request contains, the more input tokens must be processed, increasing compute usage and invocation costs.
    2. Response latency: Larger inputs generally require more preprocessing and inference time. For agents that frequently run commands, read files, and modify code, this delay can compound across multiple calls.
    3. Information density: More context is not always more useful. Repeated logs, outdated code fragments, and obsolete decisions can make it harder for the model to identify the facts relevant to the current task.

    A smaller default limit should therefore not be interpreted as a lack of capability. It is more likely an engineering trade-off between quality, speed, and resource consumption.

    2. Why Coding Agents Need Context Governance

    In a conventional question-and-answer scenario, context mainly consists of the user’s request and previous replies. Coding agents receive information from many more sources, including:

    • The user’s goals and constraints;
    • Project directories and file summaries;
    • Source code that has been read;
    • Build, test, and static-analysis results;
    • Command history and standard output;
    • File diffs before and after changes;
    • Approaches already attempted by the agent;
    • Tool-call parameters and returned results;
    • Interim conclusions reached during the task.

    If an agent retains everything without distinguishing between high- and low-value information, even a seemingly simple task can quickly consume a large amount of context. For example, repeated test runs may produce long stack traces, repeatedly inspecting the same file may add identical code to the history, and changes made across several iterations may leave outdated diffs in the conversation.

    This growth can be described as context bloat. The problem is not limited to reaching the context-window maximum. Context bloat can also cause:

    • Important information to be buried under low-value content;
    • The model to spend more effort locating the current state;
    • Outdated conclusions to influence later decisions;
    • Every request to repeatedly process the same historical input;
    • A higher risk of accumulated errors and task drift as the session grows.

    For this reason, mature coding agents do not treat the context window as an infinitely expanding chat transcript. They treat it as working memory that must be managed continuously.

    3. What Automatic Compaction Actually Does

    When a session approaches a configured threshold, an agent will typically trigger automatic compaction, also known as context organization or state summarization. The goal is not simply to delete the oldest messages. Instead, the agent restructures the long history into a more compact task state that can support continued execution.

    A useful compaction result should normally preserve the following information.

    1. The Current Task Objective

    The summary should clearly state what must ultimately be achieved, which behaviors are required, and which areas are outside the scope of the task. Otherwise, after compaction the agent may remember only its latest modification and lose sight of the broader objective.

    2. The Current Code State

    The summary should identify which files have been modified, how the core logic has changed, and which modules remain unfinished. For complex tasks, it should also record the current state of important functions, interfaces, or data flows.

    3. Verified Facts

    Examples include a test that has passed, a configuration that has been confirmed to take effect, or an interface response format that has been verified. These facts provide the basis for future decisions and should not be discarded as ordinary conversation.

    4. Failed Approaches and Their Causes

    Failed attempts are also valuable, but their complete logs do not need to be retained. A better approach is to record what was attempted, why it failed, and whether it is still worth trying again. This reduces repeated work while removing irrelevant detail.

    5. Pending Work and Risks

    The compacted state should identify the next action, unresolved problems, potential compatibility risks, and validation that is still required. Without this information, the agent may resume by exploring paths it has already tried.

    The configuration concept can be represented as follows:

    1. # Use a model with a large context capability
    2. model = "large-context-model"
    3. # Set the context size allowed for this session
    4. context_window = 1000000
    5. # Trigger automatic compaction near the threshold
    6. auto_compact_limit = 900000

    These parameters are illustrative. Their actual names and supported ranges depend on the relevant runtime environment and documentation. The key principle is not to pursue a larger number mechanically, but to establish a mechanism that proactively organizes state before the context limit is reached.

    4. Why the Maximum Window Should Not Be Used for Every Task

    Million-token context windows are useful for certain types of work, but they are not appropriate for every scenario.

    For small fixes, single-file changes, and routine API development, a smaller context is often sufficient. Enabling an extremely large window in these cases may increase request costs and waiting time without producing a proportional improvement in quality.

    For large-scale codebase migrations, cross-module refactoring, extended debugging, and complex architectural analysis, a larger context can be valuable. The agent can reference more files, design documents, and historical decisions at the same time, reducing errors caused by missing information.

    A more practical strategy is to choose the context size based on the task:

    • Short tasks: Use a smaller window to prioritize fast feedback.
    • Medium-sized tasks: Retain the core files, test results, and design constraints.
    • Long tasks: Use a larger window together with automatic compaction.
    • Very long tasks: Work in stages and record state externally rather than allowing a single session to grow indefinitely.

    A large context window cannot replace good task decomposition. If a task has unclear boundaries, even a very large context may cause the agent to switch repeatedly between competing objectives.

    5. How to Evaluate Whether Automatic Compaction Works

    Automatic compaction should not be evaluated only by whether it was triggered. It should be assessed from both task quality and resource-consumption perspectives.

    1. Check State Completeness

    After compaction, can the agent accurately answer these questions?

    • What is the final objective?
    • Which files have been modified?
    • Which tests have passed?
    • Which approaches have failed?
    • What should happen next?

    If the answers are inaccurate, the summary is too brief or has failed to preserve important state.

    2. Observe Repeated Work

    If the agent repeatedly rereads the same files or reruns commands that have already failed after compaction, the history was not summarized effectively, or the external state records are insufficient.

    3. Measure Error Rates Rather Than One-Time Results

    Context compaction may not cause an obvious error immediately. Over a long task, however, it may increase the likelihood of missing edge cases, modifying the wrong files, or overlooking test results. Evaluation should therefore include test pass rates, rework frequency, and the number of times human intervention is required.

    4. Monitor Cost and Latency

    In enterprise environments, teams should also track input-token volume, the number of calls per task, average response time, and failed retries. A context strategy can be considered effective only when both quality and resource metrics are taken into account.

    1. Store Critical State in Structured Records

    Do not rely entirely on conversation history to preserve task state. Maintain task requirements, change records, validation results, and unresolved issues in the project so that the agent can reread them after context compaction.

    2. Control the Size of Tool Output

    Command results should prioritize summaries, error locations, and the necessary surrounding context. Very large logs can be stored in full while only filtered excerpts are provided to the model.

    3. Avoid Reinjecting Complete File Contents

    Once a file has been read, provide only the changed portions or relevant sections whenever possible instead of sending the entire file again on every turn.

    4. Execute Complex Tasks in Stages

    A task can be divided into analysis, implementation, testing, fixing, and acceptance. Defining the inputs, outputs, and completion criteria for each stage helps reduce historical noise.

    5. Leave a Safety Margin Before Compaction

    Do not wait until the context window is completely exhausted. Triggering compaction early helps prevent a single tool call or large log from exceeding the limit and leaves room for the compaction process itself.

    7. How to Interpret the Move Toward Larger Context Windows

    Raising context limits indicates that large language models are evolving from single-turn generation tools into agents capable of executing longer-running tasks. Larger windows provide more room for understanding large codebases, performing cross-file refactoring, and conducting continuous debugging.

    However, a larger context does not automatically make an agent more intelligent. The actual experience depends on how model capability, context selection, state compaction, tool use, and task orchestration work together. An agent that consistently preserves critical facts, removes noise, and transfers state reliably between stages can be more dependable than a system that merely offers an extremely large context window.

    The best practice is therefore not to pursue the maximum context size blindly. Use a layered strategy: keep short tasks lightweight, expand the window when longer tasks require it, compact the context before reaching the threshold, and persist critical state through structured records. This approach provides a better balance between information completeness, response speed, operating cost, and final quality.