Claude Code context, compaction and memory: keeping long website sessions on track

By: Irina Shvaya | October 14, 2026
This article is part of our Claude Code Guide: what Claude Code is, how to use it safely on a business website, and how to budget for and choose help. Want it set up for your team? See Claude Code consulting.

Claude Code keeps a long session on track through three things: the context window (everything Claude can see right now), compaction (an automatic summary when that window gets full), and memory files (CLAUDE.md, which you write, and auto memory, which Claude writes). Anything that should outlast a long session or carry into tomorrow belongs in a memory file. Anything said only in the chat can be summarized away.

That matters on website work, where sessions get long fast. Reading a few templates, a build log and a crawl report can fill a lot of context, and the instruction you gave at the start ("never touch the pricing page") is exactly the kind of detail that can fade. This guide explains, as of October 2026, what fills the context, what survives compaction, how the two memory systems differ, and the habits that keep a session accurate. For what to write inside CLAUDE.md, see our guide on how to write a CLAUDE.md for a website.

Key Takeaways

  • The context window holds your conversation, file contents, command output, CLAUDE.md, auto memory, loaded skills and system instructions. Anthropic's best-practices page says performance "degrades as it fills."
  • Current models such as Opus 5.5 run with a 1 million token window by default in Claude Code, and for those models auto-compaction runs at about 967K tokens by default.
  • After compaction, the project-root CLAUDE.md and auto memory are re-read from disk. Instructions given only in conversation may be lost.
  • Run /context to see what is using space, /compact with a focus to summarize on your terms, and /clear between unrelated tasks.
  • Auto memory is on by default in local sessions, stored per repository on your machine, and not shared with teammates or cloud sessions.
  • Both memory systems are context, not enforced rules. To block an action outright, use permission rules or a hook.

What the context window is

The context window is the session's working memory: everything Claude takes into account when it decides its next step. According to Anthropic's how Claude Code works page, it holds "your conversation history, file contents, command outputs, CLAUDE.md, auto memory, loaded skills, and system instructions."

Some of that loads before you type anything: the system prompt, your CLAUDE.md files, the first part of auto memory, the names of connected MCP tools and one-line descriptions of available skills. Everything else accumulates as Claude works. On a website project, the biggest consumers are usually:

  • File reads. Theme templates, large stylesheets and generated HTML pages are long. You see "Read header.php" as one line, but Claude takes in the whole file.
  • Command output. Build logs, test runs and link-checker reports.
  • Back-and-forth corrections. Every failed attempt stays in the conversation until it is summarized or cleared.

Size is less of a constraint than it used to be. Anthropic's model configuration page says the Fable models, Sonnet 5 and later, Haiku 5.5, and Opus 4.7 and later "run with the 1M window by default." But a bigger window doesn't fix the underlying issue. Anthropic's best-practices page puts it plainly: "Claude's context window fills up fast, and performance degrades as it fills." A cluttered session makes more mistakes even before it hits any limit.

Check what is using space

Run /context at any point. It shows current usage as a colored grid with suggestions, including which CLAUDE.md and auto memory files loaded. If your CLAUDE.md didn't load, or a connected tool is taking more space than expected, this is where you see it.

A quick check before a big task:

  1. Run /context.
  2. Confirm your project CLAUDE.md appears under memory files.
  3. If the conversation is already large and mostly about an earlier job, clear or compact before starting (see below).

How compaction works

Compaction is Claude Code's automatic summary of the conversation when the window approaches its limit. The how-it-works page describes the order: "It clears older tool outputs first, then summarizes the conversation if needed. Your requests and key code snippets are preserved; detailed instructions from early in the conversation may be lost."

When it runs depends on your model and settings. For models with a native 1M window, Claude Code compacts "at about 967K tokens by default." You can set an earlier point with /autocompact and a token count, such as /autocompact 500k (accepted values run from 100K to 1M). Claude Code can also compact a long conversation you have left idle, shortly before its prompt cache expires, and it tells you when it has done so.

What survives depends on how something was loaded. Anthropic's context window page lists it:

ContentAfter compaction
Project-root CLAUDE.md and rules without a paths filterRe-read from disk
Auto memoryRe-read from disk
The plan Claude wrote in plan modeRe-read from disk
Path-scoped rules and CLAUDE.md files in subfoldersReload when Claude next works with matching files
Files Claude read or editedUp to five re-read, most recently modified first
Skills you invokedRe-added, capped at 5,000 tokens per skill and 25,000 in total
Instructions you typed in the chatOnly what the summary keeps

The last row is the one that bites. A rule like "don't edit anything in the /legal/ folder," typed once at the start of a three-hour session, may not make it through. Put it in CLAUDE.md, or better, in a permission rule that blocks the action. Because a skill's body is truncated from the end when it is re-added, put the most important instructions near the top of any skill file; our article on Claude Code skills covers skill design.

Steer compaction instead of waiting for it

You have several ways to control what the summary keeps:

  • Compact with a focus. Run /compact with instructions, for example /compact focus on the redirect changes and the list of files edited. The summary keeps what you chose rather than what the automatic pass guesses matters.
  • Add compact instructions to CLAUDE.md. Anthropic suggests a "Compact Instructions" section, with lines such as "When compacting, always preserve the full list of modified files and any test commands."
  • Summarize part of the conversation. Run /rewind (or press Esc twice on an empty prompt), pick a message and choose Summarize from here or Summarize up to here. Summarizing doesn't change any files. Our guide to checkpoints and rewind explains the menu.
  • Ask side questions without adding to the conversation. /btw answers a quick question about the session ("what was that config file called?") without the question and answer entering the history.

Clear between tasks

The single most useful habit is /clear when you switch to unrelated work. It starts a new conversation with empty context; your CLAUDE.md and auto memory load again, and the previous session stays stored so /resume can bring it back. Anthropic's costs page notes that stale context "wastes tokens on every subsequent message," so clearing also helps with usage limits; see keeping Claude Code costs under control.

Anthropic's best-practices page gives a clear trigger: "If you've corrected Claude more than twice on the same issue in one session," the context is cluttered with failed approaches, so run /clear and start again with a more specific prompt. A good pattern for website work:

  1. Name the session with /rename (for example, "footer-redesign") so you can find it later.
  2. Do one task: one template, one batch of redirects, one section of the site.
  3. Commit the result in git.
  4. Run /clear before the next task.
  5. To continue an old task another day, use claude --continue for the most recent session or claude --resume to pick from a list.

When we run eseospace.com, "one task per session; clear between unrelated jobs" is a house rule for exactly this reason.

Keep big reads out of the main session

Research that reads many files, such as "find every template that outputs a canonical tag," can fill your context with content you won't need again. A subagent does that reading in its own separate context window and sends back only a summary. That keeps the main session focused on the actual change. See subagents explained for when to split work this way.

Being specific helps too. "Fix the missing alt attributes in templates/product-card.html" reads one file. "Fix the alt text on the site" may read dozens.

The two memory systems: CLAUDE.md and auto memory

Context ends with the session. Memory files carry knowledge into the next one. Claude Code has two, and Anthropic's memory docs compare them:

CLAUDE.mdAuto memory
Who writes itYou (or Claude when you ask)Claude
What it holdsInstructions and rulesLearnings: your preferences, corrections, project context Claude can't get from the code
Where it livesIn the project (shareable through git), your user folder, or organization policy~/.claude/projects/<project>/memory/ on your machine
What loads each sessionThe whole file (keep it short)The first 200 lines or 25 KB of the MEMORY.md index; topic files are read when needed
Shared with teammates?Yes, if committed to the repoNo. It is machine-local and not shared with cloud environments

Auto memory is on by default in local sessions. Claude saves notes when it thinks they will help in a future conversation, and you will see messages such as "Saved 2 memories." If you say "remember that we use pnpm, not npm," Claude saves it to auto memory. If you want it in CLAUDE.md, where the whole team gets it, say "add this to CLAUDE.md."

Two cautions. First, Anthropic says both systems are treated "as context, not enforced configuration." Claude usually follows them, but nothing guarantees it; anything that must never happen, like reading an .env file or pushing to main, belongs in permission rules or a hook (see our safety guide). Second, auto memory files are plain markdown you can open and edit. Run /memory now and then to review what Claude saved, delete anything wrong or out of date, and turn auto memory off with the toggle there if you prefer. Starter CLAUDE.md files for Next.js, WordPress and Shopify sites and for a content and SEO pipeline are in our Claude Code templates.

Long-session checklist for website work

WhenDo thisWhy
Before startingRun /context; confirm CLAUDE.md loadedRules you think apply may not be loaded
At the startPut lasting rules in CLAUDE.md, not the chatChat-only rules can be lost to compaction
During researchUse a subagent for wide searchesLarge reads stay out of your context
Mid-task, long session/compact with a focusYou choose what the summary keeps
After two failed corrections/clear and rewrite the promptFailed attempts clutter the context
Between tasksCommit, then /clearFresh context; git holds the result
WeeklyReview /memoryRemove stale or wrong notes

Conclusion

Long Claude Code sessions stay accurate when you treat the context window as a resource you manage: check it with /context, compact on your terms, clear between tasks, and send big reads to subagents. Anything that has to last belongs in CLAUDE.md or auto memory, and anything that must never happen belongs in permission rules or hooks, because memory is guidance, not enforcement. If you want help setting up CLAUDE.md, permissions and session habits for your team, see our Claude Code consulting. More guides are in our Claude Code Guide.

Frequently asked questions

How big is Claude Code's context window?

As of October 2026, Anthropic's model configuration page says the Fable models, Sonnet 5 and later, Haiku 5.5, and Opus 4.7 and later run with a 1 million token window by default in Claude Code. Older models can differ, and Anthropic still says performance degrades as the window fills, so a large window is no reason to skip /clear.

Why did Claude forget an instruction I gave earlier?

Most likely the session compacted, and the instruction lived only in the conversation. After compaction Claude Code re-reads the project-root CLAUDE.md and auto memory from disk, but chat-only instructions survive only if the summary kept them. Move lasting rules into CLAUDE.md, or into a permission rule if they must be enforced.

What is the difference between /clear and /compact?

/clear starts a new conversation with empty context, and the old one stays available through /resume. /compact keeps you in the same conversation but replaces its history with a summary, optionally focused on what you name. Use /clear for a new task and /compact to keep going on the current one.

Does auto memory share what it learns with my team?

No. Auto memory is stored on your machine under ~/.claude/projects/, shared across worktrees of the same repository but not across machines or cloud environments. To share a rule with your team, add it to the project CLAUDE.md and commit it.

Can I see or delete what Claude has remembered?

Yes. Run /memory to list your memory files, open the auto memory folder and toggle auto memory on or off. The files are plain markdown, so you can edit or delete any note. You can also turn it off for one project with the autoMemoryEnabled setting.

Put this into action with eSEOspace

We help businesses grow with seo, geo & aeo that actually performs. Explore the services behind this guide:

Book a free strategy call →

Get a FREE Audit

We'll perform a comprehensive SEO, AEO, GEO & CRO audit of your website — completely free — and show you exactly how to outrank your competitors.

Don't have a site yet? Get in touch →

Get a FREE GEO/AEO/SEO Audit

We'll analyze your site's SEO, GEO, AEO & CRO — completely free — and show you exactly how to get found across Google and AI answers.

Don't have a site yet? Get in touch →

You Might Also like to Read