Long-Context AI Coding in Practice: Real-World Experience and Stable Workflows

    This article explains what makes long-context AI coding tools reliable on multi-hour tasks. It argues that context compaction is a normal part of long tasks, so stability depends on recovering correctly after compaction. The article covers criteria for judging long-context performance, persistent process files, harness design for compaction and recovery, evaluation metrics, and a practical workflow for long-running tasks.

    In practical use of long-context AI coding tools, many people first ask how many tokens the tool can hold. The factor that most affects the experience, however, is usually not the theoretical limit. It is whether the system can keep the goal in view, understand the current state, and keep working after context compaction, once a task has run for hours or longer.

    From an engineering perspective, a long context does not mean unlimited memory. As a task grows more complex, inputs, tool call results, code changes, test logs, and intermediate reasoning keep accumulating until they trigger context compaction. For truly long-running tasks, compaction is not an exception. It is a normal mechanism that will happen. Stability should therefore not rest on the assumption that compaction never occurs. It should rest on a design that can still recover the work correctly after compaction.

    1. Core Criteria for Judging Long-Context Experience

    To evaluate long-context capability, look beyond how much content fits into a single conversation. Focus on the following dimensions:

    1. Information retention

    Does the system keep the task goal, key constraints, completed work, and pending items, rather than only the most recent few turns?

    1. State recovery

    After context compaction or a task pause, can the system resume from existing files, logs, and summaries, instead of guessing the project state?

    1. Consistency over time

    As a task runs longer, does the system still follow the original technical requirements, such as directory conventions, interface specifications, test standards, and security limits?

    1. Error correction

    When an earlier decision turns out to be wrong, can the system detect and fix it, rather than repeating the same mistake because the history has grown too long?

    1. Tool coordination

    For tasks that involve reading code, editing files, running tests, and analyzing logs, can the system order its steps correctly and adjust its plan based on actual execution results?

    In practice, the long-context experience is the combined result of context management and task execution framework design.

    2. Why Context Compaction Is Inevitable in Long Tasks

    Suppose a task requires ongoing analysis of a large codebase, changes to several modules, and repeated test runs. The context will usually contain:

    • The initial requirements and business constraints;
    • The project directory structure;
    • The contents of multiple source files;
    • Records of tool calls;
    • Compilation and test output;
    • Failure causes and fix attempts;
    • Design decisions and change notes;
    • New requirements added by the user.

    This information keeps growing. Even when a system offers a large context window, the accumulation is never unlimited. Once a threshold is reached, the system usually has to compress, summarize, or reorganize the earlier history.

    Compaction does not necessarily mean a drop in capability. Good compaction keeps the information most important for the rest of the task, such as:

    • What the overall goal is;
    • What work has been completed;
    • Which files have changed;
    • What the current test results are;
    • Which problems remain unresolved;
    • What steps should come next;
    • What must not be changed or violated.

    The real risk is that compaction loses critical state. For example, the system may forget that an interface must stay compatible, or forget that a test failure was temporary. That can lead to repeated edits, wrong rollbacks, or breakage of existing functionality.

    3. Process Files Are Key to Stable Long-Running Tasks

    For longer tasks, not all important information should live only in the conversation context. A more reliable approach is to keep a set of persistent process files that store the task state outside the context.

    A general set of process files can include the following:

    1. Task specification file

    This file records the goal, scope, constraints, and acceptance criteria. For example:

    1. Goal:
    2. - Refactor a specific module
    3. - Keep the existing interfaces compatible
    4. - Add tests for exception scenarios
    5. Constraints:
    6. - Do not modify external protocols
    7. - Do not introduce unapproved dependencies
    8. - Keep the existing configuration format
    9. Acceptance criteria:
    10. - The build succeeds
    11. - Automated tests pass
    12. - Key performance metrics do not noticeably regress

    This file should stay stable. Unless the user explicitly changes the requirements, it should not be overwritten casually.

    2. Work plan file

    This file tracks the planned phases and their status:

    1. [Done] Map the module's dependencies
    2. [Done] Add input validation
    3. [In progress] Fix the exception-path tests
    4. [Pending] Run the full regression suite

    The value of the plan file is that, after recovery, the system can quickly see the current progress and avoid repeating work that is already done.

    3. Decision record file

    For complex tasks, record important technical decisions and the reasons behind them:

    1. Decision: Keep the original data structure and do not replace it with a new one directly.
    2. Reason: External callers depend on the current field order.
    3. Impact: A conversion layer must be added. This adds some code, but lowers compatibility risk.

    Without this record, the system may reassess the same question in a later stage and overturn a plan that was already verified.

    4. Test and issue log file

    Keep failing tests, error logs, and verified conclusions separate:

    1. Issue: An exception occurs when the boundary input is empty.
    2. Cause: Validation runs after data access.
    3. Fix: Move the parameter check earlier.
    4. Verification: Unit tests pass. Integration tests are pending.

    This keeps the system from mistaking an old problem for a new one. It also helps the system continue locating faults after context compaction.

    4. Designing a Harness That Handles Compaction

    Here, the harness can be understood as the task control framework built around the AI coding model. It does more than send prompts. It also handles state storage, tool calls, checkpoints, and recovery.

    A reliable harness usually has the following capabilities:

    1. Write state at key points

    Do not wait until the context is nearly full to save information. Write state proactively at points such as:

    • After completing a functional module;
    • Before and after modifying a file;
    • After a test run finishes;
    • When a new constraint is discovered;
    • After an error has been located;
    • Just before context compaction is triggered.

    Use structured formats where possible. Avoid saving state only as natural-language paragraphs that are hard to parse.

    2. Generate a recoverable summary before compaction

    A compaction summary should not simply recap the chat. It should focus on how to continue the work. For example:

    1. Current goal: Complete the refactor of the authentication module
    2. Completed:
    3. 1. Modified the token parsing logic
    4. 2. Added expiration time validation
    5. 3. Passed the basic unit tests
    6. Current state:
    7. - File A has been modified
    8. - File B has not been modified yet
    9. - Integration tests have not run because test data is missing
    10. Key constraints:
    11. - Do not change external return fields
    12. - Error codes must remain compatible
    13. Next steps:
    14. 1. Add test data
    15. 2. Run the integration tests
    16. 3. Check the exception logs

    A summary like this is more useful for recovery than “A lot of changes were made earlier. Next, continue testing.”

    3. Verify state after recovery

    After compaction, the first action should not be to edit code. The system should first check the real environment:

    • Has the current branch or working tree changed?
    • Do the target files exist?
    • Were the previously recorded changes actually saved to disk?
    • Are the test results still valid?
    • Have the external configurations changed?

    In other words, the summary serves as navigation and cannot replace the actual state. Files, logs, and test results are the final source of truth.

    4. Avoid repeating destructive operations

    The recovery mechanism should record whether each tool call completed successfully. For example, if a migration has already run, it must not run again just because the summary is incomplete. For deletions, overwrites, and bulk replacements, add confirmation steps and design the operations to be idempotent.

    5. Does a 100K to 200K Context Noticeably Reduce Quality?

    For many common tasks, a 100K to 200K context is usually enough to cover a long code analysis and several rounds of changes. However, a large context does not mean every piece of content is equally useful.

    Several factors affect the results:

    1. Information density

    Repeated logs, full files pasted over and over, and irrelevant discussion all lower the share of useful information.

    1. Content position

    Some systems may pay less attention to earlier content than to recent content. Key constraints should therefore not appear only once. They should also be written to persistent state files.

    1. Task structure

    Tasks with a clear goal and clear steps stay stable more easily than tasks with several mixed goals or frequent changes of direction.

    1. Tool output quality

    If tools return large amounts of noisy logs, the model has to filter out the key information. The advantage of a long context can then be cancelled out by useless content.

    1. Compaction strategy

    If compaction keeps only a surface-level summary, quality can drop noticeably. If it keeps decisions, state, and pending items, the task can usually continue stably.

    So the problem cannot be reduced to “quality drops once the context passes a certain length.” A more accurate statement is that the longer the context, the more important information organization and state management become.

    6. How to Evaluate Ultra-Long Tasks

    For long-running tasks that claim to handle millions or even hundreds of millions of tokens, theoretical figures alone are not a good guide. More useful are repeatable evaluation metrics:

    • Task completion rate;
    • Recovery success rate after compaction;
    • Number of repeated operations;
    • Success rate of error fixes;
    • Number of times key constraints are forgotten;
    • Test pass rate;
    • Number of human interventions;
    • Effective context volume needed per unit of work.

    It is especially important to distinguish the total number of tokens processed from the number of tokens kept in the context at the same time. The first can be very large, but that does not mean the system keeps all of that history in its current context. What matters is whether, after repeated compaction and recovery, the system still follows the correct path to finish the task.

    7. A Practical Workflow for Long Tasks

    A reasonably safe workflow for long-running tasks looks like this:

    1. Read the task specification and the current state files first.
    2. Check the workspace, code version, and test baseline.
    3. Split the task into small phases that can each be verified.
    4. After each phase, write the state and decisions to files.
    5. Run targeted tests instead of only one final validation.
    6. When an error occurs, record its cause, the fix applied, and the verification result.
    7. Before compaction, generate a structured summary focused on recovery.
    8. After compaction, reread the process files and check the real environment first.
    9. Continue the unfinished work from the previous phase.
    10. Finally, run a full regression and produce a summary of the changes.

    The core idea is simple: the model handles understanding and execution, while the file system, test system, and logging system store the facts.

    Conclusion

    Overall, the long-context experience can be reliable. That reliability does not come from simply enlarging the context window. It comes from a complete engineering design for the task. For short Q&A, the window size may be the main metric. For complex development tasks that run for hours or longer, what determines the outcome is whether work can be recovered after compaction, whether process state is persisted, whether tool calls can be verified, and whether test feedback forms a closed loop.

    So the most useful question for judging a long-context AI coding solution is not “How much can it hold?” It is this: when history is compacted, the task is interrupted, or a tool returns an error, can the system accurately tell what it has already completed, what the real current state is, and what to do next? If the harness and process files are designed around that question, a long task can move from a one-off conversation to a sustainable, recoverable, and verifiable engineering workflow.