-
Notifications
You must be signed in to change notification settings - Fork 3
feat: add 4 deep-dive comparisons (instruction/MDM/telemetry/token) #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,274 @@ | ||||||
| # 指令文件加载 Deep-Dive | ||||||
|
|
||||||
| > CLAUDE.md vs QWEN.md——项目指令如何被发现、解析和注入到系统提示?本文基于 Claude Code(v2.1.89 源码分析)和 Qwen Code(v0.15.0 开源)的源码分析,对比两者在指令文件发现层级、`@include` 指令、Frontmatter 路径过滤和信任模型方面的设计差异。 | ||||||
|
|
||||||
| --- | ||||||
|
|
||||||
| ## 1. 架构总览 | ||||||
|
|
||||||
| | 维度 | Claude Code | Qwen Code | | ||||||
| |------|------------|-----------| | ||||||
| | **指令文件名** | `CLAUDE.md`, `CLAUDE.local.md`, `.claude/rules/*.md` | `QWEN.md`, `AGENTS.md`(可配置) | | ||||||
| | **层级数** | 6 层(Managed/User/Project/Local/AutoMem/TeamMem) | 3 层(Global/Home/Project) | | ||||||
| | **@include 指令** | ✅ 5 层嵌套,循环检测,路径验证 | ✅ 5 层嵌套,循环检测,路径验证 | | ||||||
| | **Frontmatter 路径过滤** | ✅ `paths:` glob 模式,条件规则 | ❌ | | ||||||
| | **HTML 注释剥离** | ✅ | ❌ | | ||||||
| | **条件规则(按文件路径)** | ✅ `.claude/rules/*.md` + `paths:` frontmatter | ❌ | | ||||||
| | **信任模型** | `hasTrustDialogAccepted` + 外部 include 审批 | `folderTrust` 布尔值 | | ||||||
| | **Auto Memory** | ✅ `MEMORY.md`(200 行 / 25KB 截断) | ❌ | | ||||||
| | **Team Memory** | ✅(feature-gated) | ❌ | | ||||||
| | **Hook 事件** | ✅ `InstructionsLoaded`(含加载原因) | ❌ | | ||||||
|
|
||||||
| --- | ||||||
|
|
||||||
| ## 2. Claude Code:六层指令体系 | ||||||
|
|
||||||
| ### 2.1 发现层级(优先级从低到高) | ||||||
|
|
||||||
| ``` | ||||||
| 1. Managed Memory /etc/claude-code/CLAUDE.md(全局策略,管理员设置) | ||||||
| ↓ | ||||||
| 2. User Memory ~/.claude/CLAUDE.md(用户全局,所有项目) | ||||||
| ↓ | ||||||
| 3. Project Memory 从 CWD 向上遍历到项目根: | ||||||
| ├── CLAUDE.md | ||||||
| ├── .claude/CLAUDE.md | ||||||
| └── .claude/rules/*.md(条件和非条件规则) | ||||||
| ↓ | ||||||
| 4. Local Memory CLAUDE.local.md(项目本地,不提交到 Git) | ||||||
| ↓ | ||||||
| 5. Auto Memory .claude/projects/<slug>/memory/MEMORY.md(自动学习) | ||||||
| ↓ | ||||||
| 6. Team Memory API 同步的团队记忆(feature-gated) | ||||||
| ``` | ||||||
|
|
||||||
| **目录遍历逻辑**(源码: `claudemd.ts#L790-L977`): | ||||||
| - 从 CWD 向上遍历到文件系统根 | ||||||
| - 在项目根处停止(git/hg/svn 边界) | ||||||
| - Git worktree 特殊处理:避免从主仓库重复加载 | ||||||
| - 距 CWD 更近的文件优先级更高(后加载覆盖先加载) | ||||||
|
|
||||||
| > 源码: `utils/claudemd.ts`(1,479 行) | ||||||
|
|
||||||
| ### 2.2 @include 指令 | ||||||
|
|
||||||
| **语法**: | ||||||
|
|
||||||
| ```markdown | ||||||
| 参考 @./src/CODING_STANDARDS.md 中的编码规范 | ||||||
| 数据库模型定义见 @./docs/schema.md#models | ||||||
| 用户指南: @~/shared-docs/guide.md | ||||||
| ``` | ||||||
|
|
||||||
| **路径解析规则**: | ||||||
|
|
||||||
| | 语法 | 解析方式 | | ||||||
| |------|----------| | ||||||
| | `@path` | 相对于包含文件所在目录 | | ||||||
| | `@./path` | 相对路径(同上) | | ||||||
| | `@~/path` | Home 目录 | | ||||||
| | `@/path` | 绝对路径 | | ||||||
| | `@path#fragment` | 自动剥离 `#` 后缀 | | ||||||
| | `@path\ with\ spaces` | 反斜杠转义空格 | | ||||||
|
|
||||||
| **安全约束**(源码: `claudemd.ts#L626-L667`): | ||||||
| - 最大嵌套深度:**5 层** | ||||||
| - 循环引用检测:`Set<string>` 存储已处理文件的规范路径 | ||||||
| - Symlink 解析后加入已处理集合 | ||||||
| - 外部文件(项目目录外)需 `hasClaudeMdExternalIncludesApproved` 审批 | ||||||
|
|
||||||
| **代码区域排除**(源码: `claudemd.ts#L451-L535`): | ||||||
| - `@include` 不在以下区域内解析: | ||||||
| - HTML 注释 `<!-- ... -->` | ||||||
| - 围栏代码块 ` ```...``` ` | ||||||
| - 行内代码 `` `...` `` | ||||||
|
||||||
| - 行内代码 `` `...` `` | |
| - 行内代码 <code>`...`</code> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
表格里的路径示例
@path\\ with\\ spaces在 Markdown inline code 中不需要转义反斜杠,当前会渲染成双反斜杠,导致示例与实际语法不一致。建议改为单反斜杠形式。