Context Windows

Managing Claude’s working memory

What Is the Context Window?

Everything in your current session — your prompts, Claude’s responses, file contents Claude read, code it wrote, output it saw — lives in a single “context window.”

Think of it as Claude’s short-term memory for this session. Claude can only “see” what’s in the context window. It cannot reach back to a previous session. It cannot remember last week’s regression results unless you put them back in front of it.

When the session ends, the context window is gone. This is why the save-to-files pattern matters so much.


Concrete Sizes

The context window size depends on your plan. Claude Pro gives you 200,000 tokens. Claude Max with Opus can go up to 1,000,000 tokens. Most participants will be on Pro, so we’ll use 200K as the reference.

That sounds enormous. Here is what it actually means in practice:

Content Approximate tokens
200K tokens total ≈ 500 pages of dense text
One BACI CSV (Germany, 2022) 50,000–100,000 tokens
One working paper (20 pages) 10,000–20,000 tokens
One R script (200 lines) 1,000–2,000 tokens
One long conversation turn 500–2,000 tokens
This entire guide ~3,000 tokens

A single large dataset can consume a quarter to half your context window on its own. Add a paper, three scripts, and 20 turns of conversation, and you’re getting close to the limit — or past it.

Note

A “token” is roughly 3/4 of a word in English and slightly less for code. You don’t need to count tokens manually — the point is to develop intuition about what’s large.

TipBest external resources

What Accumulates in Your Context Window

As a session progresses, context fills up from multiple sources simultaneously:

[Diagram: stacked bar chart showing how context fills up over a session. Layers from bottom: system prompt (small), conversation history (grows), file contents read (can be large chunks), code written (moderate), output and error messages (variable)]

Conversation history — every exchange you’ve had. This grows turn by turn and never shrinks unless you use /compact or /clear.

File contents — when Claude reads a file to answer a question, the full file content enters the context. A 200-line R script stays in context for the rest of the session.

Code generated — each code block Claude writes occupies context. Over a long session with many iterations, this adds up.

Terminal output — error messages, test results, data summaries that Claude sees. A stack trace or a long summary() output can be surprisingly large.

The system prompt — Claude Code adds its own instructions at the start of every session. This is invisible to you but takes a few thousand tokens.


Performance Degradation

Here is the uncomfortable truth: Claude gets measurably worse as the context window fills.

Turn 30 of a conversation is not the same quality as turn 3, even if you ask the identical question. This is not imaginary — users report it consistently, and it’s consistent with known limitations of large language models at long sequence lengths.

What you might notice:

  • Claude starts repeating earlier parts of the conversation unnecessarily
  • Code suggestions become less precise
  • Claude “forgets” a convention you established early in the session
  • Responses become longer and more hedged
  • Claude contradicts something it said 20 turns ago

This is not Claude becoming tired. It’s a mechanical property of the architecture. The signal-to-noise ratio of the context degrades as it fills.

Warning

If Claude starts giving worse answers mid-session, the most effective intervention is /compact or starting a fresh session — not rephrasing your question.


/compact — When and How

/compact compresses the conversation history into a summary, freeing up context space without losing all continuity.

Type it at the prompt:

/compact

Or with a hint about what to preserve:

/compact Focus on: the regression results for the main specification,
the variable names and their coding, and the current state of 03_gravity.R

The hint matters. Without one, Claude summarizes everything at equal weight. With one, it preserves what you need and compresses what you don’t.

Use /compact when:

  • You’re about 1/3 into a long session and want to keep going
  • You’ve just finished one task and are about to start another
  • Claude’s responses are starting to feel slower or less precise

Use /clear (full reset) when:

  • The session’s task is complete and you’re starting something new
  • Context has become noisy from many dead ends and failed experiments
  • You want to begin fresh with no accumulated assumptions

Use Escape (Ctrl+C) to:

  • Stop Claude mid-response when it’s heading in the wrong direction
  • Interrupt a long file read you didn’t intend

Save Progress to Files

The most important habit for long projects: save work to files, not to the conversation.

The context window disappears when the session ends. Your file system does not.

Before ending any significant session:

“Write a summary of what we’ve accomplished today — the key decisions, the regression results, and what to do next — and save it to progress.md”

“Save the final version of all modified scripts before we finish”

“Write the main regression output table to output/tables/table1.tex”

Next session, Claude reads those files and picks up exactly where you left off:

“Read progress.md and the current state of 03_gravity.R. We’re continuing from yesterday.”

This is not a workaround — it’s the intended workflow. Claude Code is designed around the assumption that your project’s state lives in files, not in conversation memory.


The Multi-Session Workflow

For a substantial research project, structure your work as a pipeline of focused sessions:

Session 1 — Data Cleaning
  Input:  data/baci_raw.csv, data/cepii_distances.csv
  Output: output/data/panel_clean.csv, progress_s1.md

Session 2 — Gravity Regressions
  Input:  output/data/panel_clean.csv, progress_s1.md
  Output: output/tables/table1_baseline.tex,
          output/tables/table2_robust.tex, progress_s2.md

Session 3 — Figures
  Input:  output/data/panel_clean.csv, progress_s2.md
  Output: output/figures/fig1_distance.pdf,
          output/figures/fig2_geopolitical.pdf, progress_s3.md

Session 4 — Writing
  Input:  output/tables/, output/figures/, progress_s3.md
  Output: sections/results.tex, sections/robustness.tex

Each session starts with a clean context and a clear mandate. Each session produces files that the next session reads. The project advances through files, not through a single marathon conversation.

Tip

Start each session with: “Read [progress file] and the current state of [key scripts]. Summarize where we are before we continue.” This takes 30 seconds and ensures Claude understands the project before it starts writing code.


Anti-Patterns to Avoid

Reading a 100MB CSV directly.

# Don't do this:
> "Read data/baci_full_2022.csv"

That file might be 500,000+ tokens. It will fill half your context window with raw data Claude doesn’t need to see. Instead:

“Read the first 100 rows of data/baci_full_2022.csv and describe the structure” “What are the column names and types in data/baci_full_2022.csv?”

Claude can inspect structure without reading every row.

Staying in one session for 4+ hours.

Even with /compact, a 4-hour session accumulates enormous amounts of context — false starts, abandoned approaches, redundant explanations. Start a fresh session when you move to a genuinely new task. The discipline of clean sessions produces better output.

Pasting long error logs or stack traces.

A full R traceback or a long compilation error is often hundreds of lines. Paste only the relevant part — the final error message and 5–10 lines of context:

“Here is the error: [paste just the error line]. The relevant code is in 03_gravity.R around line 47.”

Asking Claude to “review the whole project.”

This is a recipe for reading every file into context. Instead, give Claude a specific question: “Review the regression specification in 03_gravity.R and tell me if the standard error clustering is correct for a gravity model.”


When to Start Over: Signs Claude Is Getting Worse

These are signals that the context window is working against you:

  • Claude refers to code or decisions from early in the session as if it has forgotten recent changes
  • Responses are notably longer and more hedged than earlier in the session
  • Claude makes the same mistake twice in a row after you corrected it
  • Suggestions stop fitting your project’s conventions (e.g., reverting to lm() after you established feols() as the standard)
  • The model starts summarizing large blocks of context unnecessarily

When you see two or more of these, the right move is /compact with a good hint, or a fresh session with a progress file as context.


Keyboard Shortcuts

Command Effect
/compact [hint] Compress conversation history, optionally preserving key details
/clear Reset context entirely — fresh session
Escape or Ctrl+C Stop Claude mid-response
arrow Recall previous prompt for editing

None of these require the terminal basics guide — they work directly in the Claude Code prompt.