Context & Memory in Claude Code
Claude Code in VS Code has no persistent memory between separate sessions. Understanding what Claude can and can't see in each conversation determines whether you get accurate, relevant answers. This module covers context window mechanics, what Claude sees in your IDE, strategies for managing long conversations, and patterns for working within the context limit.
Within one chat session, Claude remembers everything you've discussed. When you start a new session (or use /clear), the slate is wiped. You must re-attach context files each time for anything Claude needs to know.
How the Context Window Works
The context window is the total amount of information Claude can consider at once. Think of it as Claude's working memory for a single conversation. Every piece of text in the conversation — your messages, Claude's replies, system instructions, attached files — occupies space in this window.
200K Token Limit
All Claude 4 models support a 200,000-token context window — roughly 150,000 words or 500 pages of text. This is large enough to hold an entire codebase, a full legal contract, or weeks of email threads. But it is not infinite, and you need to manage it deliberately.
Tokens Are Not Words
One token averages about 3/4 of a word. "ThreadCo" is 2 tokens. Code is typically more token-dense than prose (more symbols, less natural language). A 1,000-line TypeScript file might be 8,000-12,000 tokens. A 1,000-word email is about 1,300 tokens.
Everything Counts
Your messages, Claude's responses, CLAUDE.md content, attached files, and system instructions all share the same 200K window. A long conversation with many attached files can fill the window, after which Claude starts losing access to early content.
Attention Is Not Uniform
Claude pays strongest attention to content at the beginning and end of the context window. Information in the middle of a very long context can receive less attention. This is called the "lost in the middle" effect and affects all LLMs. Place the most important information at the start or end of your prompt.
Research shows that LLMs — including Claude — recall information at the beginning and end of long contexts more reliably than information buried in the middle. For critical data (like your returns policy or pricing rules), place it early in the conversation or in the most recent message. Do not bury it between 50 other files and expect perfect recall.
What Claude Can See in VS Code
Files You @ Mention
Type @filename in the chat to attach any file in your workspace. Claude reads the full content. Attach multiple files in one message — Claude handles all of them simultaneously. This is the primary way to give Claude specific context.
The Current Editor Tab
Claude Code can see the file currently open in your editor without you needing to @ it explicitly, particularly when asking about "this file" or running inline edits via Ctrl+K. But being explicit with @ is always safer than relying on implicit context.
CLAUDE.md Automatically
Place a CLAUDE.md file at the root of your project. Claude Code reads it automatically at the start of every session — use it for standing instructions, brand voice, code conventions, and project background. This is your most important context management tool.
Terminal Output
When Claude runs a command in the integrated terminal, it reads the output automatically. If a test fails, Claude sees the error and can propose a fix without you copy-pasting anything. This includes build output, test results, and any command-line tool output.
What Claude Cannot See
Understanding what is not in Claude's context is just as important as knowing what is. These are the most common sources of confusion:
| Not Visible | Why | Workaround |
|---|---|---|
| Files you haven't @ mentioned | Claude does not scan your entire workspace automatically | Explicitly @ mention any file Claude needs to see |
| Previous sessions | No persistent memory between sessions | Use CLAUDE.md for standing context; re-attach files each session |
| Browser tabs or other apps | Claude Code only sees your VS Code workspace | Copy relevant content into a file and @ it, or paste into chat |
| Environment variables | Claude cannot read .env files unless you @ them (and you shouldn't) | Reference env var names, never values. Write code that reads from process.env |
| Database content | No direct database access | Set up MCP tools for database queries, or paste query results into chat |
| Git history | Claude doesn't automatically read commit history | Run git log or git diff in the terminal and let Claude read the output |
| Other team members' conversations | Each user's sessions are isolated | Share findings via CLAUDE.md or documented prompts in the repo |
Managing Context Across a Workday
| Situation | What to do | Command |
|---|---|---|
| Starting a new, unrelated task | Clear the conversation so old context doesn't bleed into the new task | /clear |
| Session is getting slow or confused | Summarise history into a compact handoff, freeing up context space | /compact |
| Need Claude to know the project background | Add it to CLAUDE.md — loads automatically every session | Edit CLAUDE.md |
| Working across multiple files | @ mention each file — or @ the whole folder for broad tasks | @folder/ |
| Long document Claude needs to reference repeatedly | Attach it at the start of the session and keep it in the conversation thread | @ it first |
Strategies for Long Context
When you need Claude to work with more information than fits comfortably in the context window — or when you want to maintain quality with large amounts of context — use these strategies:
Progressive Disclosure
Don't dump everything at once. Start with the most relevant file. Let Claude analyse it. Then add the next file and ask Claude to integrate. This gives Claude focused attention on each piece rather than spreading attention across 20 files simultaneously.
Summarise-Then-Detail
For a codebase review, first ask Claude to read the project structure and produce a summary. Then use /compact to compress the conversation. Now ask detailed questions about specific files — Claude has the summary as context without the raw bulk of every file.
Chunk Long Documents
For very long documents (e.g., a 200-page manual), split the work across sessions. Process chapters 1-5 in one session, summarise findings, then start a new session for chapters 6-10 with the summary from the first session as context.
Use CLAUDE.md as a Knowledge Base
After Claude produces a useful analysis, save the key findings to CLAUDE.md or a separate reference file. Future sessions can read this pre-digested knowledge without re-processing the original source material.
Prioritise What Goes First
Put the most critical context at the start of the conversation (CLAUDE.md content and first @ mentions) and in the most recent message. The "lost in the middle" effect means content in the middle of a long conversation gets less attention. Structure your sessions so critical information is at the edges.
Conversation Management Patterns
The "Fresh Start" Pattern
For each distinct task, use /clear and start a new conversation. Attach only the files relevant to this specific task. This prevents context pollution and gives Claude maximum attention budget for the current problem. Best for: task switching, code reviews, independent features.
The "Long Session" Pattern
For complex multi-step tasks (like building a feature), keep the conversation going across many turns. Claude builds up context about your decisions, constraints, and approach. Use /compact when the conversation gets slow. Best for: feature development, iterative design, debugging sessions.
The "Handoff" Pattern
When a long session ends, ask Claude to write a summary of what was discussed, what was decided, and what remains to do. Save this summary. Start the next session by pasting the summary and attaching the relevant files. Best for: multi-day projects, team handoffs.
The "Reference Session" Pattern
Keep one session open as a "reference desk" where Claude has your core docs loaded (brand guide, API docs, coding standards). Use a separate session for the actual work. When you need to check something, switch to the reference session. Best for: documentation-heavy work.
Summarisation Patterns
Summarisation is your most powerful tool for managing context. Here are specific patterns:
You (at the end of a long session): Summarise this conversation for a future session handoff. Include: 1. What we were working on (one sentence) 2. Key decisions made (bullet list) 3. Current state of the code (what's done, what's not) 4. Open questions and next steps 5. Any gotchas or constraints discovered Format it so I can paste it at the start of a new session and Claude will have full context. Claude produces a structured summary you save for next time.
You:
@long-document.pdf — I need to reference this document
across multiple conversations. Create a compressed summary
(under 500 words) that captures:
- All specific numbers, dates, and names
- Key rules and policies
- Anything that could be a gotcha or exception
I'll paste this summary into future sessions instead of
attaching the full document each time.
ThreadCo CLAUDE.md — Persistent Context Example
# ThreadCo Project Context
## About ThreadCo
Sustainable UK T-shirt brand. 3 staff, 2,000 products, 500 customer emails/week.
Founder: Maya. Primary concern: customer support response time and product copy quality.
## Current Projects
- ShopMate: AI customer support tool (in progress)
- Catalogue refresh: rewriting product descriptions for 2,000 SKUs
## Key Files
- /docs/brand-voice.md — tone and forbidden words
- /docs/returns-policy.md — customer-facing returns rules
- /docs/sizing-guide.md — size chart used in all customer replies
## Coding Standards
TypeScript. Tests required for all new functions. No inline styles.
## Do Not
- Suggest paid third-party services without noting the cost
- Write customer-facing copy with exclamation marks
Context Management Anti-Patterns
The "Everything Attached" Session
Attaching 20+ files "just in case" dilutes Claude's attention. Each file competes for focus with the others. Attach only the files Claude needs for the current task — typically 1-5 files. If Claude needs more, it will ask or you can add them as follow-up.
The "Novel-Length" CLAUDE.md
A 2,000-word CLAUDE.md with every detail about your project. Claude's attention on CLAUDE.md diminishes after ~500 words. Keep it concise: role, key conventions, banned patterns, and pointers to detailed docs. Use @ to attach the detailed docs when needed.
The "Never Clear" Session
Working for 4 hours without using /clear or /compact. By the 50th message, Claude's context window is full of old, irrelevant conversation. Quality degrades as Claude tries to reconcile early instructions with later ones. Clear between tasks; compact during long tasks.
The "Paste Everything" Approach
Copying file contents directly into chat instead of using @. This wastes context space on formatting overhead, makes it harder for Claude to reference specific files, and clutters the conversation history. Always use @ for file references.
Multi-Session Project Workflows
For projects that span multiple days or weeks, you need a deliberate strategy for maintaining context continuity across sessions:
Session Journaling
At the end of each work session, ask Claude to write a "session journal" — a structured summary of what was accomplished, decisions made, blockers identified, and next steps. Save this to a session-logs/ folder. Start the next session by attaching the most recent journal entry.
Living Architecture Document
For complex projects, maintain a living architecture document that Claude updates as the project evolves. Include: system design decisions, component relationships, API contracts, and tech debt items. This document becomes the single source of truth that carries context across sessions.
Decision Log
Keep a running log of decisions made with Claude's help: what was decided, why, what alternatives were considered, and any constraints. This prevents re-debating the same decisions in future sessions and gives new team members a decision history.
Structured CLAUDE.md Updates
As the project evolves, update CLAUDE.md to reflect new conventions, resolved decisions, and changed priorities. Review CLAUDE.md weekly. Remove outdated information — stale context is worse than no context because Claude may follow outdated instructions.
Think of each Claude session as a working draft that produces an artifact (code, document, decision, summary). The artifact is what persists — the conversation is disposable. Design your workflow around artifacts (files in your repo) rather than around conversations (which disappear on /clear). This mindset naturally leads to better context management because you focus on producing durable outputs.
Estimating Your Context Budget
| Content Type | Approximate Token Count | % of 200K Window |
|---|---|---|
| CLAUDE.md (500 words) | ~670 tokens | 0.3% |
| A 100-line TypeScript file | ~800-1,200 tokens | 0.5% |
| A 500-line source file | ~4,000-6,000 tokens | 2.5% |
| A 10-page PDF document | ~5,000-8,000 tokens | 3.5% |
| A 20-turn conversation | ~15,000-25,000 tokens | 10% |
| Claude's own responses (cumulative) | Varies widely | Can consume 30-50% |
| System prompt / instructions | ~500-1,000 tokens | 0.4% |
People forget that Claude's responses also consume context window space. A conversation where Claude writes 10 detailed code explanations might have 30,000+ tokens of Claude's own output in the context. This is why long sessions slow down — the window fills with history. Use /compact to reclaim this space.
Real-World Context Scenarios
Here is how ThreadCo manages context for their most common workflows:
| Workflow | Files Attached | Session Length | Context Strategy |
|---|---|---|---|
| Customer email replies | @returns-policy.md, @sizing-guide.md, the email thread | Short (5-10 messages) | /clear between each customer. Policy files re-attached each time. |
| Product descriptions (batch) | @brand-voice.md, 3-5 product detail files at a time | Medium (20-30 messages) | Process 5 products, /compact, process next 5. Refinement carries over. |
| Feature development | @schema.prisma, 3-5 source files, @test files | Long (50+ messages) | Start with architecture files, add implementation files as needed. /compact at the 30-message mark. |
| Code review | Changed files only (1-5 files), @PR description | Short (5-10 messages) | Fresh session per PR. All changed files attached upfront. |
| Weekly report generation | @this-week-data.csv, @last-week-report.md | Short (3-5 messages) | One shot. Attach data + previous report for format consistency. |
Session setup (first message every time): @returns-policy.md @sizing-guide.md @brand-voice.md You are a ThreadCo customer support agent. Use the attached policies to answer accurately. If the answer is not in the attached files, say "I'll need to check with the team and get back to you" — do not make up policy details. Then paste the customer's email and ask for a draft reply. The policy files ensure every reply is accurate and consistent.
For any task where accuracy matters (customer support, legal analysis, financial calculations), explicitly tell Claude: "If you don't have the information, say so — do not guess." Without this instruction, Claude may generate plausible-sounding but incorrect answers. With it, Claude is much more likely to flag gaps in its knowledge rather than filling them with hallucinated details.
Hands-On Exercises
Start a fresh Claude Code session. Attach a large file (500+ lines). Have a 10-turn conversation about it. Then ask Claude to recall a specific detail from the very first message. Is the recall accurate? Try the same thing after using /compact. Compare the results.
Work on a multi-step task for 15-20 minutes in one session. At the end, ask Claude to write a handoff summary. Use /clear, paste the summary, and continue the task. Was the handoff summary sufficient? What information was lost? Refine your handoff prompt template based on what was missing.
If your CLAUDE.md is over 500 words, condense it. Move detailed reference material to separate files. Test the condensed version by starting 3 new sessions and checking that Claude still follows all the important conventions. Iterate until you have the minimum effective CLAUDE.md.
Take a codebase with 10+ files. Try two approaches: (a) @ mention all 10 files at once and ask a question about how they interact, (b) @ mention 2-3 files at a time, ask Claude to summarise each group, then ask the interaction question with the summaries. Which approach produces a more accurate answer?
Using the Context Budget table above, estimate the total tokens for your typical work session: CLAUDE.md + average number of attached files + expected conversation length. Does it fit comfortably within 200K tokens? If not, identify what you can cut or compress. Create a "context budget" guideline for your team.
Key Takeaways
No Persistent Memory
Claude starts every session with a blank slate. CLAUDE.md and @ mentions are your tools for giving Claude the context it needs. Treat every new session as a fresh start — because that is exactly what it is.
Manage the Window
The 200K token context window is large but finite. Use /clear between tasks, /compact for long sessions, and be selective about what you attach. Quality degrades when the window is overfull with irrelevant content.
CLAUDE.md is Non-Negotiable
If you do nothing else from this module, create a CLAUDE.md file for your project. Under 500 words. Project context, coding standards, and key rules. This single file improves every session for every team member.
Artifacts Over Conversations
Conversations are ephemeral. Build your workflow around producing durable artifacts: code files, documents, summaries, decision logs. These persist and carry context forward. The conversation is a tool — the artifact is the output.