claude-code-project-memory

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Claude Code Project Memory (Jan 2026)

Claude Code项目内存(2026年1月)

Configure
CLAUDE.md
project memory so Claude Code gets stable, scoped instructions across sessions while keeping token cost low.
配置
CLAUDE.md
项目内存,让Claude Code在不同会话中获得稳定、限定范围的指令,同时降低Token消耗。

Quick Reference

快速参考

Memory TypeTypical LocationPurpose
Managed policyOS-dependent (see official docs)Organization-wide standards (security, compliance)
Project memory
./CLAUDE.md
or
./.claude/CLAUDE.md
Shared project context and conventions
Project rules
./.claude/rules/*.md
Modular, topic-focused rules (testing, security, style)
User memory
~/.claude/CLAUDE.md
Personal preferences across projects
Project memory (local)
./CLAUDE.local.md
(git-ignored)
Local-only, project-specific preferences
内存类型典型存放位置用途
托管策略依赖操作系统(详见官方文档)全组织范围的标准(安全、合规)
项目内存
./CLAUDE.md
./.claude/CLAUDE.md
共享项目上下文与规范
项目规则
./.claude/rules/*.md
模块化、主题化规则(测试、安全、风格)
用户内存
~/.claude/CLAUDE.md
跨项目的个人偏好设置
本地项目内存
./CLAUDE.local.md
(已被Git忽略)
仅本地生效的项目特定偏好

How Loading Works (High Level)

加载机制(概览)

  • Recursive loading: from the current working directory up to (but not including) filesystem root (
    /
    ).
  • On-demand loading: nested
    CLAUDE.md
    files under the cwd are loaded only when Claude reads files in those subtrees.
  • Imports:
    @path/to/file
    pulls in additional context (max depth: 5;
    ~
    supported).
  • 递归加载:从当前工作目录向上加载,直至(但不包含)文件系统根目录(
    /
    )。
  • 按需加载:当前工作目录下的嵌套
    CLAUDE.md
    文件仅在Claude读取对应子目录中的文件时才会加载。
  • 导入
    @path/to/file
    可引入额外上下文(最大深度:5;支持
    ~
    路径)。

Workflow (Best Practice)

最佳实践工作流

  1. Start with a minimal
    CLAUDE.md
    (50–120 lines): what the project is, how it’s shaped, and the “must not break” rules.
  2. Move long or fragile guidance into
    .claude/rules/
    (one topic per file).
  3. Use
    @imports
    as navigation for detailed docs instead of copying them into memory.
  4. Treat memory like code: PR review, ownership, and periodic cleanup (remove dead rules).
  1. 从精简版
    CLAUDE.md
    开始(50–120行):说明项目内容、架构以及“绝对不能破坏”的规则。
  2. 将冗长或易变的指引迁移至
    .claude/rules/
    目录(每个主题一个文件)。
  3. 使用
    @imports
    作为详细文档的导航,而非将内容复制到内存文件中。
  4. 将内存文件视为代码:进行PR评审、明确所有权并定期清理(移除失效规则)。

Rules With Optional Path Scope

带可选路径范围的规则

Create
.claude/rules/testing.md
,
.claude/rules/security.md
, etc. If a rule only applies to a slice of the repo, scope it:
yaml
---
paths:
  - "src/api/**/*.ts"
---
创建
.claude/rules/testing.md
.claude/rules/security.md
等文件。如果某条规则仅适用于仓库的部分内容,可设置范围:
yaml
---
paths:
  - "src/api/**/*.ts"
---

Commands (Claude Code)

Claude Code命令

  • > /memory
    to view and directly edit memories.
  • > /init
    to bootstrap project memory (see official docs for current behavior).
  • > /memory
    :查看并直接编辑内存文件。
  • > /init
    :引导生成项目内存(当前行为详见官方文档)。

Cross-Platform Strategy (AGENTS.md + CLAUDE.md)

跨平台策略(AGENTS.md + CLAUDE.md)

If you support multiple coding assistants, keep one canonical file and mirror it:
  • macOS/Linux: symlink one to the other.
  • Windows: prefer copying (or a small sync script) over symlinks unless Developer Mode is enabled.
Avoid tool-specific claims in the memory file; keep it portable and strictly project-focused.
如果您同时使用多个编码助手,请维护一个标准文件并进行镜像同步:
  • macOS/Linux:将一个文件软链接到另一个。
  • Windows:除非启用开发者模式,否则优先选择复制(或使用小型同步脚本)而非软链接。
避免在内存文件中加入工具专属内容;保持文件的可移植性,严格聚焦于项目本身。

Validation (Fast Checks)

验证(快速检查)

  • Run the bundled linter:
    bash frameworks/shared-skills/skills/claude-code-project-memory/scripts/lint_claude_memory.sh .
  • Manually scan for unresolved
    @imports
    and secrets before merging memory changes.
  • 运行内置的检查器:
    bash frameworks/shared-skills/skills/claude-code-project-memory/scripts/lint_claude_memory.sh .
  • 在合并内存文件变更前,手动扫描未解析的
    @imports
    和敏感信息。

Resources

资源

ResourcePurpose
references/memory-patterns.mdPatterns and anti-patterns
references/memory-examples.mdFull examples by stack
references/large-codebase-strategy.md100K–1M LOC strategy
data/sources.jsonOfficial links
资源用途
references/memory-patterns.md内存模式与反模式
references/memory-examples.md按技术栈分类的完整示例
references/large-codebase-strategy.md10万–100万行代码库的策略
data/sources.json官方链接

Related Skills

相关技能

SkillPurpose
claude-code-skillsSkill creation patterns
claude-code-agentsClaude Code agent setup
docs-codebaseRepo documentation patterns
技能用途
claude-code-skills技能创建模式
claude-code-agentsClaude Code Agent配置
docs-codebase仓库文档模式