### 总体摘要
本次更新重点修复了 Hooks 在 Windows 平台的路径匹配安全性问题,明确了 Skills(技能)Frontmatter 字段在本地与云端环境下的标准兼容性,并新增了关于 Files API 的关键安全警告,强调防止跨用户数据泄露。
### 核心变更主题
* **Windows 路径标准化与安全:** 详细阐明了 `PreToolUse` 和 `PostToolUse` 中的 `file_path` 始终为绝对路径,且在 Windows 上使用反斜杠 (`\`)。文档特别警告,若在 Hook 脚本中仅硬编码正斜杠 (`/`) 进行匹配,将导致匹配失败,从而可能绕过安全检查。
* **Agent Skills 开放标准合规性:** 区分了 Claude Code 私有扩展字段(如 `paths`)与 [Agent Skills](https://agentskills.io) 开放标准字段。当将 Skills 上传至 `claude.ai` 或使用 `package_skill.py` 打包时,仅允许使用标准字段,否则会直接报错。
* **Files API 安全警示:** 新增严重警告,指出上传的文件 `file_id` 作用于整个工作区,而非特定用户。严禁接受不受信任的(如用户端提交的)`file_id`,否则会导致数据泄露风险。
* **Hook 输出流控制:** 澄清了 Exit 0 状态下的 Stderr 仅写入调试日志,不可被 Claude 读取。若需向 Claude 发出警告,必须使用 Exit 2。
### 影响等级:高
**理由:**
1. **安全风险:** Windows 路径处理不当可能导致 Hook 安全策略失效;Files API 的误用可能导致严重的越权访问漏洞。
2. **构建阻断:** Skills 打包或上传流程增加了严格验证,使用了非标准字段的现有项目将遭遇硬错误阻断。
3. **跨平台兼容性:** Windows 用户的 Hook 脚本可能需要修改才能按预期工作。
### 开发者行动项
1. **修复 Windows Hook 路径匹配:** 审查所有涉及文件工具(`Write`, `Edit`, `Read`)的 Hook 脚本,务必添加路径分隔符归一化逻辑(例如在 Bash 中使用 `${FILE_PATH//\\//}` 或 Python 中使用 `.replace("\\", "/")`),以防 Windows 反斜杠导致匹配失效。
2. **合规化 Skills Frontmatter:** 若需将 Skills 分发至 `claude.ai`或通过 API 使用,请检查 `SKILL.md`,移除仅 Claude Code 支持的字段(如 `argument-hint`、`paths`),仅保留 6 个标准字段(`name`, `description`, `license`, `compatibility`, `metadata`, `allowed-tools`)。
3. **加固 Files API 安全:** 检查代码逻辑,确保服务器端从不接受用户直接提供的 `file_id`。必须由服务端维护用户与文件的映射,防止利用 ID 读取他人文件。
4. **调整 Hook 退出码逻辑:** 如果您希望 Hook 中的警告信息能被 Claude 看到,请修改脚本让其在警告时返回 Exit 2 而非 Exit 0,否则 Stderr 内容仅限开发者调试查看。
💭 Model Reasoning
1. **Analyze the Request:**
* **Role:** World-class programmer analyzing documentation changes.
* **Output Format:** Markdown (Concise, insightful).
* **Language:** Chinese.
* **Input:** 5 pages of diffs (`hooks.md`, `hooks-guide.md`, `skills.md`, `slash-commands.md`, `build-with-claude/files.md`).
2. **Analyze the Diffs:**
* **`hooks.md`:**
* *Exit 0 vs Exit 2 behavior:* Clarifies that stderr on exit 0 goes *only* to debug log (never to Claude/Transcript). To surface a warning to Claude (from `PostToolUse` etc.), use exit 2.
* *Path Normalization in Hooks:* Big section added regarding `PreToolUse` input.
* `file_path` is always absolute.
* Expanded `~` and relative paths.
* **Critical:** Windows paths use backslashes (`\`). Hooks running under Git Bash see `/c/project` but inputs have `\`.
* If hooks compare using `/`, they fail to match `\`.
* Solution: Normalize separators (`/` vs `\`) before matching.
* Example given for Windows `Write` call.
* Note: `PostToolUse` input paths are now noted to be the same format.
* **`hooks-guide.md`:**
* *Code Example Update:* Added a snippet in a bash hook example to normalize Windows backslashes: `FILE_PATH="${FILE_PATH//\\//}"`. This directly supports the changes in `hooks.md`.
* **`skills.md` & `slash-commands.md`:**
* *Note:* Both pages have identical diffs regarding the Skills spec.
* *Frontmatter Compatibility:* Added new frontmatter fields: `metadata`, `license`, `compatibility`.
* *Standard vs Extensions:* Clarifies that Claude Code supports the [Agent Skills](https://agentskills.io) open standard.
* *Strict Validation elsewhere:* When uploading to `claude.ai` or using `package_skill.py`, only 6 fields are allowed (`name`, `description`, `license`, `compatibility`, `metadata`, `allowed-tools`).
* *Hard Error:* If you use a Claude Code-only field (like `argument-hint` implied by the error message example, or `paths`?) in the standard context, it throws a hard error ("Unexpected key(s)...").
* *Conclusion:* Developers must be careful which fields are used where. Standard fields work everywhere; Claude Code extensions only work locally in the CLI.
* **`build-with-claude/files.md`:**
* *Security Warning:* Added a `<Warning>` box. Uploaded files are workspace-scoped, not user-scoped.
* *Risk:* If accepting `file_id` from an untrusted user, they could read another user's files (IDOR vulnerability).
* *Action:* Never accept `file_id` from end users. Keep mapping server-side.
3. **Synthesize Themes:**
* *Windows Compatibility & Robustness:* The hooks changes are heavily focused on making hooks work correctly on Windows (path separators).
* *Standards Compliance & Portability:* The skills changes focus on aligning with the "Agent Skills" open standard vs. Claude Code specific extensions.
* *Security & Best Practices:* The files API change is a critical security warning about scoping and IDOR.
4. **Determine Impact Level:**
* *Hooks (Windows):* Medium to High for cross-platform devs. If they wrote hooks assuming forward slashes, their security policies might be bypassed on Windows.
* *Skills (Frontmatter):* Medium. If they are sharing skills or packaging them, this causes breaking build errors.
* *Files (Security):* High. Security vulnerabilities are high impact.
* *Overall:* High (due to the combination of potential security bugs and broken hooks on Windows).
5. **Draft Action Items:**
* Update hook scripts to normalize path separators (specifically for Windows).
* Review `SKILL.md` files to remove Claude Code-only fields if packaging for `claude.ai` or public distribution.
* Implement strict validation on `file_id` inputs in application code (never trust user input).
* Adjust hook exit code logic (use exit 2 for warnings) if they were relying on stderr being seen by Claude on success.
6. **Translate to Chinese:**
* *Summary:* 重点关注 Hooks 的 Windows 路径兼容性、Skills 的 Agent Skills 标准合规性以及 Files API 的安全警告。
* *Themes:* Windows 路径处理, 标准与扩展区分, 安全风险.
* *Impact:* High (Critical security fix + Cross-platform stability).
* *Action Items:* Normalize paths, Clean up frontmatter, Validate file IDs, Review exit codes.
7. **Refine the Output (Markdown structure):**
* **Overall Summary:** 本次更新重点解决了 Hooks 在 Windows 平台上的路径匹配问题,明确了 Skills(技能)在不同环境(本地 vs 云端)下的 Frontmatter 字段兼容性标准,并新增了关于 Files API 的关键安全警告,强调了工作区级别的文件访问隔离。
* **Key Themes:**
* **Windows 路径标准化:** 针对 `PreToolUse` 和 `PostToolUse`,强调文件路径始终为绝对路径,且在 Windows 上使用反斜杠 (`\`)。文档明确指出,若在 Hook 中硬编码正斜杠 (`/`) 进行匹配,将导致安全检查失效。
* **Agent Skills 标准合规性:** 划分了 Claude Code 私有扩展字段(如 `paths`)与 Agent Skills 开放标准字段(如 `license`)。当打包或上传至 `claude.ai` 时,仅允许使用标准字段,否则会报错。
* **Files API 安全警示:** 明确警告 `file_id` 具有工作区作用域,而非用户级别。严禁接受用户提供的 `file_id`,否则会导致跨用户数据泄露(IDOR 漏洞)。
* **Hook 输出流控制:** 澄清了 Exit 0 时 Stderr 仅写入调试日志,若需向 Claude 发出警告,需使用 Exit 2。
* **Impact Level: High**
* **Reasoning:** 路径标准化问题直接影响 Windows 用户 Hook 的安全性与功能(可能导致权限绕过);Skills 字段的严格验证可能导致打包流程中断;Files API 的安全漏洞若不修复,将造成严重的数据泄露风险。
* **Action items:**
* **修复 Windows 路径匹配:** 检查所有涉及文件操作(`Write`, `Read`, `Edit`)的 Hook 脚本,添加路径分隔符归一化逻辑(例如将 `\` 替换为 `/`)。
* **清理 Skills Frontmatter:** 若计划将 Skills 上传至 `claude.ai` 或使用 `package_skill.py` 打包,请移除仅 Claude Code 支持的字段(如 `argument-hint`, `paths`),仅保留标准字段(`name`, `description`, `license`, `compatibility`, `metadata`, `allowed-tools`)。
* **加固 Files API 安全:** 审查处理文件上传和引用的应用代码,确保服务器端严格拒绝来自客户端(用户)的 `file_id` 输入,由服务端维护用户与文件的映射关系。
* **调整 Hook 错误处理:** 如果希望 Hook 的警告信息被 Claude 看到,请将退出码从 0 改为 2,否则 Stderr 内容仅限调试查看。
8. **Final Polish:** Ensure tone is professional and concise. The translation looks natural for technical documentation. The distinction between standard and extension fields in skills is clear. The Windows path issue is highlighted as a potential security bypass.
*Self-Correction during drafting:* Make sure to mention the specific error message for skills, as that helps developers debug if they hit it. The "Exit 2" change is important for workflow logic.
*Final check against constraints:* "Concise, insightful analysis in markdown format." "Focus on what matters to developers." "Chinese response." All met.