Why AI Coding Assistants Forget Your Instructions in Long Conversations: A Look at Context Management

    Long conversations with AI coding assistants can cause them to silently drop your earlier instructions. This article explains how the context window works, what happens when it fills up, and practical techniques—such as project rule files and compression directives—to keep important conventions in effect throughout a long task.

    Background: Context Defines the Assistant’s Behavior

    An AI coding assistant doesn’t actually “remember” every interaction. Before generating each reply, the system feeds a set of text into the model, and the model can only reason based on that text. This set of text is called the context window, and its capacity is limited. The longer the conversation, the more the system must decide what to keep and what to discard.

    Understanding this mechanism helps developers answer two practical questions: why an assistant forgets earlier agreements during long tasks, and where those agreements should be written so they remain effective over time.

    What Makes Up the Context Window

    A typical coding assistant’s context window usually contains the following types of content:

    • Conversation history: questions, answers, and revision requests exchanged between the user and the assistant.
    • Tool call results: file contents, command output, search results, and so on. These tend to be large, and their relevance drops quickly as the task progresses.
    • Persistent memory: project background or user preferences the assistant saves across sessions.
    • Loaded skill instructions: the full operational instructions injected into the context when a particular skill is triggered.
    • System instructions: the runtime framework’s own rules, output format requirements, and available tool definitions.

    Conversation history is only one part of this. Many developers focus solely on their own typed input, overlooking the fact that tool output and system instructions also consume window space. The more cluttered the window, the less room remains for your key conventions.

    What Happens When the Window Approaches Its Limit

    When the window nears its limit, most tools handle it in two steps:

    Step 1: Remove older tool call outputs. File contents and command results take up a lot of space but offer limited value for subsequent decisions, so they are removed first.

    Step 2: Summarize and compress the entire conversation history. The system condenses specific wording, values, and code snippets into a summary in exchange for freed-up space.

    The cost of this process is information loss. A clearly stated requirement before compression may become a vague phrase like “the user wants consistent code style” in the summary. The summary isn’t wrong, but it has lost the actionable details.

    Why Instructions Get Forgotten

    Consider a concrete scenario. In the third round of a conversation, a developer emphasizes that “API responses must use a unified error structure.” In the fifth round, they settle on an architecture that “separates the data access layer from the business layer.” By round forty, the window triggers compression, and both earlier agreements are merged into something like “API and architecture design were discussed.” The assistant then generates code that doesn’t follow the error structure, and the developer perceives that the assistant has “forgotten” the instructions.

    Mechanically speaking, the assistant isn’t deliberately ignoring the instructions—the original text simply no longer exists in its input. The key to solving this problem, therefore, is to keep important conventions out of the conversation history and store them somewhere the summarization process won’t rewrite.

    Solutions

    1. Put Cross-Turn Rules in a Project Rules File

    Most coding assistants support placing an instruction file in the project root directory, though the file name varies by tool. This file is loaded at the start of a session and re-injected into the context after compression, so it isn’t affected by the summarization process. Suitable contents include:

    • Coding standards and naming conventions
    • Technology stack and dependency version constraints
    • Directories or files that must not be modified
    • Check commands to run before committing

    Example:

    1. # Project Rules
    2. ## Technical Conventions
    3. - All APIs return a unified structure: { code: number, message: string, data: any }
    4. - Separate the data access layer from the business layer; business code must not call database drivers directly
    5. - New dependencies must list their version numbers in the change description
    6. ## Prohibited Actions
    7. - Do not modify historical files under the migrations/ directory

    2. Add a Compression Directive Section to the Rules File

    The rules file can also specify which information must be preserved during compression. In tools that support this mechanism, this section guides the summarization process.

    1. ## Compression Directives
    2. When compressing the context, the following must be preserved in full:
    3. - All API error response structure definitions
    4. - Confirmed architecture decisions and their rationale
    5. - Operations explicitly prohibited by the user

    The benefit is that the summary retains the information the developer specified, rather than what the model chose to keep based on its own judgment.

    3. Other Best Practices

    • Write long-term conventions into documentation, not just the conversation. Conversations are good for discussing approaches; final conclusions should end up in files.
    • Start a new session after completing a major phase. A new session carries only the necessary background, reducing historical baggage and preventing old tool output from interfering with new tasks.
    • Restate key conventions and verify the results. For important requirements, briefly restate them in later prompts and check whether the generated code complies.
    • Limit file reading scope. When reading large files, explicitly tell the assistant which part you need, reducing the accumulation of irrelevant output in the window.