
Quick answer
- Memory is useful when the reader needs the decision frame before the full tutorial.
- The practical answer is: Explain what Memory changes, when it is useful, and how to verify it safely.
- Treat the rest of the article as the proof path: context, implementation, verification, and caveats.
Answer at a Glance
Claude Code memory accumulates in a single space by default. Domain terms, team rules, and environment settings saved in project A can silently appear in project B responses. The fix is the workspace isolation pattern: anchor the working directory to each project root, place an independent CLAUDE.md file there, and treat that file as the namespace boundary. Two rules govern everything. First, each project root owns its CLAUDE.md, making the directory the namespace scope. Second, global memory holds only truly universal preferences while project-specific knowledge lives locally.
Why This Matters Now
Context contamination stays invisible in small single-project setups. The moment you run two or three concurrent projects, things break in subtle ways. Financial domain terms like 'principal amount' or 'maturity date' bleed into e-commerce responses. One team's coding conventions leak into another repository's session. This is not just an annoyance — code generated from the wrong context can pass review and fail at runtime.
Claude Code uses the CWD at launch time as the anchor for locating memory files. When you intentionally set the project root as CWD, the project-local CLAUDE.md loads first. Designing around this behavior gives you a natural namespace boundary with no extra infrastructure.
Step-by-Step Setup
- Create a CLAUDE.md file at each project root. Without it, Claude Code falls back to a parent directory or the global config.
- Keep the global file at ~/.claude/CLAUDE.md to genuinely universal items only — personal language preferences, commit message language, response format defaults. Aim for under ten lines.
- In each project-root CLAUDE.md, record only what belongs to that repository: domain vocabulary, build commands, team conventions. Start the file with a header like
# Project: payments-apiso the namespace is immediately visible. - Always launch Claude from the project root:
cd ~/projects/payments-api && claude. Make this a team-wide convention so every session starts with the right context loaded. - If global memory has accumulated project-specific entries by accident, open it with
/memoryand move those lines into the appropriate project-local CLAUDE.md. - When contamination is severe, run
codex debug clear-memoriesto wipe memory artifacts, then rebuild each project file from scratch.
Real-World Example
Two projects coexist: ~/projects/fintech-core and ~/projects/shop-frontend.
The CLAUDE.md at fintech-core root starts with # Project: fintech-core — financial backend context only, followed by rules like 'round monetary values to 4 decimal places', 'transaction IDs are UUID v4', and 'run tests with pytest -v --tb=short'.
The CLAUDE.md at shop-frontend root starts with # Project: shop-frontend — commerce frontend context only, followed by 'component filenames use PascalCase', 'state management: Zustand first', and 'build command: pnpm build'.
With this layout, launching Claude inside fintech-core never loads the Zustand rule. Each session reads only its own CLAUDE.md. The global file at ~/.claude/CLAUDE.md holds two lines: 'all commit messages in English' and 'default response language: Korean'. Nothing project-specific ever goes there.
Common Mistakes
Running Claude from the home directory is the most frequent error. cd ~ && claude loads only global memory. Any work done in that session appends to the global file, making later cleanup difficult.
Expecting a namespace boundary without the CLAUDE.md file is another trap. The file must exist for Claude Code to treat the directory as an isolated scope. Even an empty file is enough to signal the boundary.
Letting the global file grow too large defeats the entire design. Once every project's rules pile into the global file, namespace isolation provides no benefit. Keep the global file to five to ten lines maximum.
Checklist
- Each project root has a CLAUDE.md file
- The global ~/.claude/CLAUDE.md contains only truly universal items (ten lines or fewer recommended)
- Every team member follows the rule of launching Claude from the project root
- Creating CLAUDE.md is part of the new-repository onboarding checklist
- The /memory command is available for quickly inspecting global and local contents when contamination is suspected
- codex debug clear-memories is the last-resort reset before rebuilding project files
Testing notes and measurement limits
- Do not present generated summaries as hands-on test results. Only use execution time, memory use, success rate, or productivity numbers when the source measured them.
- Numeric details present in the input: none. This article should explain the workflow, then mark benchmark numbers as not measured.
- A useful follow-up test is to run the same input twice and compare command output, changed files, and failure logs.
Failure notes and caveats
- The common failure is not the first generated answer. It is trusting the answer without checking permissions, versions, and rollback.
- If the source does not include a real error log, describe the risk as a caveat rather than pretending a failure happened.
- Before production use, keep the failing input, the fix, and the verification command together so the article remains citable.
Sources and checks
Verified on: 2026-06-12
| Claim | Evidence | How to verify | Limit |
|---|---|---|---|
| Memory should be checked against the original source before reuse. | code.claude.com | Check the source page, version, date, and setup notes. | Source content can change after this article is published. |
| Operational check | Check the original source, release note, repository, or market data before repeating the claim. | Reproduce on a small input and record input, output, and environment. | A local test does not prove every production path. |
| Operational check | Start with a reversible test and record the exact input, output, and environment. | Reproduce on a small input and record input, output, and environment. | A local test does not prove every production path. |
| Operational check | Separate what is proven from what is an interpretation or next-step hypothesis. | Reproduce on a small input and record input, output, and environment. | A local test does not prove every production path. |
FAQ
Q. What happens if I run Claude from a subdirectory inside the project root?
Claude Code walks upward from the launch directory searching for CLAUDE.md. If no file exists in the subdirectory, it uses the nearest ancestor file. In a monorepo, placing a separate CLAUDE.md in each package root gives finer-grained isolation per package.
Q. Should CLAUDE.md be committed to the shared repository?
Commit it if the rules apply to the whole team. For personal preferences like editor shortcuts or response tone, add CLAUDE.md to .gitignore and let each person manage their own copy locally. A clean split: commit CLAUDE.md for team rules, add CLAUDE.local.md to .gitignore for personal overrides.
Q. If I have two projects open simultaneously, can their namespaces bleed into each other?
Each Claude Code session loads memory based on the CWD at launch time. Open each project in a separate terminal tab with its own project root as CWD, and the sessions remain independent. Switching directories within a single terminal session is riskier than keeping one terminal tab per project.
Wrapping Up
Memory workspace isolation does not require complex infrastructure. Three habits cover it entirely: place CLAUDE.md at every project root, keep the global file minimal, and always launch from the correct directory. Once this structure is in place, Claude knows exactly which project it is working in and responds accordingly. A namespace boundary is simply the context fence that helps Claude make better judgments.
Citation-ready summary
- Verified on: 2026-06-12
- Definition: Memory is the article's central term; cite it together with the source and verification limits below.
- Main answer: Explain what Memory changes, when it is useful, and how to verify it safely.
- Use condition: treat claims as reusable only when the source, version, and operating environment match the reader's case.
Key terms
- Memory: the concrete subject this article explains and evaluates.
- Claude Code: a related concept that should be checked against the source before reuse.
- Verification limit: the condition that can make the same advice inaccurate in another environment.
Test environment and baseline
- Verified on: 2026-06-12
- Baseline scope: this article explains Memory as a reproducible workflow, not as a universal benchmark.
- Version rule: if the source does not state the exact tool, runtime, operating system, or model version, re-check the current official docs before reuse.
- Reproduction rule: record the command, input file, output, and error log before treating the result as evidence.
This diagram shows how Load changed files leads to Review before push before the workflow is trusted.
Worked example: reproduce it on a small input
Scenario: treat Memory as a reversible dry run, not as a production rollout.
Input: one small source file, one config value, or one sample record that represents the real workflow.
Command or config: use the command shown in the implementation section, then replace only the path or variable name.
Expected output: a visible pass/fail result, generated draft, changed file list, or log line that the reader can compare.
Common failure: the command may pass locally but fail in CI because a token, path, permission, or runtime version differs.
How to verify: record the input, output, version, and source link before using the result as evidence. This is a reproducible recipe, not a claim that I personally measured it.
🐦 Faster updates on X: @baegseungh7061
📚 More in this series: Code Advanced
💌 Subscribe: Follow on X or grab the RSS
댓글
댓글 쓰기