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:
- Information retention
Does the system keep the task goal, key constraints, completed work, and pending items, rather than only the most recent few turns?
- 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?
- 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?
- 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?
- 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:
Goal:- Refactor a specific module- Keep the existing interfaces compatible- Add tests for exception scenariosConstraints:- Do not modify external protocols- Do not introduce unapproved dependencies- Keep the existing configuration formatAcceptance criteria:- The build succeeds- Automated tests pass- 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:
[Done] Map the module's dependencies[Done] Add input validation[In progress] Fix the exception-path tests[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:
Decision: Keep the original data structure and do not replace it with a new one directly.Reason: External callers depend on the current field order.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:
Issue: An exception occurs when the boundary input is empty.Cause: Validation runs after data access.Fix: Move the parameter check earlier.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:
Current goal: Complete the refactor of the authentication moduleCompleted:1. Modified the token parsing logic2. Added expiration time validation3. Passed the basic unit testsCurrent state:- File A has been modified- File B has not been modified yet- Integration tests have not run because test data is missingKey constraints:- Do not change external return fields- Error codes must remain compatibleNext steps:1. Add test data2. Run the integration tests3. 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:
- Information density
Repeated logs, full files pasted over and over, and irrelevant discussion all lower the share of useful information.
- 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.
- 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.
- 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.
- 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:
- Read the task specification and the current state files first.
- Check the workspace, code version, and test baseline.
- Split the task into small phases that can each be verified.
- After each phase, write the state and decisions to files.
- Run targeted tests instead of only one final validation.
- When an error occurs, record its cause, the fix applied, and the verification result.
- Before compaction, generate a structured summary focused on recovery.
- After compaction, reread the process files and check the real environment first.
- Continue the unfinished work from the previous phase.
- 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.
