basforge

Search titles, text and the “If it doesn’t work” cases.

    RU
    ManualAIPrompts

    Long conversations: how not to hit the context limit and not lose what you agreed on

    Every turn of a chat stays in the context to the end: old file versions, rejected ideas, wrong answers. By the hundredth message the model holds early agreements worse, and every turn costs more. Move the permanent stuff out of the chat, keep one task per chat, and when switching, carry over a summary, not the history.

    What happens to the context as a conversation goes on

    turn 1    [system][question]                                  →   3,000 tokens
    turn 10   [system][10 question–answer pairs][file v1]         →  40,000
    turn 40   [system][40 pairs][file v1][file v2][log][file v3]  → 180,000
                        ↑ rejected ideas, mistakes, old versions — all of it here
    • Quality. The model’s attention spreads over the whole context. The more clutter in it, the less weight each early agreement carries. On long contexts models recall the middle worse than the beginning and the end.
    • Mistakes are contagious. A wrong answer left in the history is a template for the next ones: the model tries to be consistent with itself (Edit, don’t argue).
    • Cost and speed. Each turn’s input is the whole history. In the example above, turn forty costs 60 times as much as turn one.
    • The window limit. Claude 5.5 has a 1M-token window. Chat apps and agents start compacting earlier: the old part of the history is replaced with a summary. In the API, compaction is turned on separately and by default kicks in around 150,000 tokens. Whatever didn’t make it into the summary no longer exists for the model.

    What to do

    1. Permanent things live outside the chat

      Rules, project facts and style you need in every conversation don’t go in the first message; put them where they’re read every time and won’t get compacted:

      Where you work Where it goes
      claude.ai, ChatGPT project instructions and project files
      Claude Code and other agents in the editor CLAUDE.md at the repository root (AGENTS.md and the like for other agents)
      your own code on the API system, under the cache (Prompt cache)

      This is for what doesn’t change from task to task: versions, paths, conventions, prohibitions. Not the progress of a specific task — that will be stale by the next one.

    2. One task, one chat

      A new topic means a new chat (New task, new chat). If a task grows, split it: “figure out why the 502”, then separately “rewrite the Traefik config”. Each gets a short context without leftovers from the other.

    3. Watch the size

      In Claude Code, /context shows how much of the window is used and by what: system prompt, tools, files, conversation. A chat has no counter — go by length: dozens of long answers and a few pasted files mean it’s time to move.

      Signs the context is overloaded: the model repeats what was rejected, mixes up file versions, answers longer and vaguer, asks again about things already said.

    4. Before moving — a summary

      Ask the model to put the handover together itself — it sees the whole history:

      Put together a summary for continuing this work in a new chat. Sections:
      1. Goal — in one sentence.
      2. What we decided — and why, one item per decision.
      3. What we rejected — and why, so it isn't suggested again.
      4. Current state: which files changed, what works, what doesn't.
      5. Open questions.
      6. Next step.
      No retelling of the conversation, only what's needed to continue.

      Read the summary yourself: the model skips what it considered obvious, and that can be the main thing.

      In Claude Code, /compact does the same, and you can tell it what to keep: /compact keep the Traefik decisions and the list of changed files. /clear wipes the context entirely.

    5. The new chat: the summary and fresh files

      The first message gets the summary and the current versions of the files you need, in full. Don’t carry over pieces from the old chat: they hold old versions. Don’t paste files to an agent in the editor; it reads them from disk.

    6. A large document doesn’t go in the history

      Don’t keep a 300-page book or 50 log files in the conversation, where they ride along every turn. Options: one section at a time in a separate chat; project files with caching; search over the documents — RAG (Your own data in a model).

    How to check

    In the new chat with the summary, ask a test question about something from the “rejected” section: “maybe do it with X?”. The model should answer that X was rejected and give the reason. If it doesn’t remember, the summary is incomplete — add to that section.

    If it doesn’t work

    The model brought back an option you dropped an hour ago

    Cause
    The rejected option is still in the context, along with the arguments for it. The reason for dropping it is one turn among a hundred.
    Fix
    A new chat with a summary whose “rejected” section records what and why (step 4).

    It edits an old version of a file, not the one on disk now

    Cause
    The history holds three versions of the file, and the model picked an early one.
    Fix
    Give the file again in full and write “this is the current version”; in an agent, ask it to reread the file from disk.

    Mid-task the agent “forgot” a rule from the start of the session

    Cause
    Automatic compaction kicked in: early history was replaced with a summary, and the rule didn’t make it in.
    Fix
    Standing rules go in CLAUDE.md or the system prompt, which survive compaction (step 1). Compact yourself with /compact, saying what to keep.

    Answers got slower, and the subscription limit runs out in an hour

    Cause
    Every turn sends the whole history: by turn one hundred that’s hundreds of thousands of input tokens.
    Fix
    Split the work into tasks, each in its own chat (New task, new chat).