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

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:
- Run /context.
- Confirm your project CLAUDE.md appears under memory files.
- 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:
| Content | After compaction |
|---|---|
| Project-root CLAUDE.md and rules without a paths filter | Re-read from disk |
| Auto memory | Re-read from disk |
| The plan Claude wrote in plan mode | Re-read from disk |
| Path-scoped rules and CLAUDE.md files in subfolders | Reload when Claude next works with matching files |
| Files Claude read or edited | Up to five re-read, most recently modified first |
| Skills you invoked | Re-added, capped at 5,000 tokens per skill and 25,000 in total |
| Instructions you typed in the chat | Only 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:
- Name the session with /rename (for example, "footer-redesign") so you can find it later.
- Do one task: one template, one batch of redirects, one section of the site.
- Commit the result in git.
- Run /clear before the next task.
- 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.md | Auto memory | |
|---|---|---|
| Who writes it | You (or Claude when you ask) | Claude |
| What it holds | Instructions and rules | Learnings: your preferences, corrections, project context Claude can't get from the code |
| Where it lives | In the project (shareable through git), your user folder, or organization policy | ~/.claude/projects/<project>/memory/ on your machine |
| What loads each session | The 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 repo | No. 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
| When | Do this | Why |
|---|---|---|
| Before starting | Run /context; confirm CLAUDE.md loaded | Rules you think apply may not be loaded |
| At the start | Put lasting rules in CLAUDE.md, not the chat | Chat-only rules can be lost to compaction |
| During research | Use a subagent for wide searches | Large reads stay out of your context |
| Mid-task, long session | /compact with a focus | You choose what the summary keeps |
| After two failed corrections | /clear and rewrite the prompt | Failed attempts clutter the context |
| Between tasks | Commit, then /clear | Fresh context; git holds the result |
| Weekly | Review /memory | Remove 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:
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 →
Great — your audit is on the way!
We'll send your free SEO/GEO/AEO/CRO audit within the next few hours. Where should we send it?
You're all set! ✓
Your free audit is being prepared — check your inbox in the next few hours. Talk soon!
On this page
- Key Takeaways
- What the context window is
- Check what is using space
- How compaction works
- Steer compaction instead of waiting for it
- Clear between tasks
- Keep big reads out of the main session
- The two memory systems: CLAUDE.md and auto memory
- Long-session checklist for website work
- Conclusion
- Frequently asked questions





