### 总体摘要
文档更新反映了 Claude Code 中子代生成行为的重大变更:在 v2.1.219 及更高版本中,子代生成现在默认开启,且深度限制默认为 3 层,改变了此前默认关闭或限制严格的行为。
### 关键主题
* **默认行为变更**:子代生成不再默认关闭,而是默认允许最多 3 层嵌套。
* **引入深度限制概念**:明确了当子代达到“深度限制”时,`Agent` 工具会被移除,从而导致代理自行执行任务而非继续委派;Fork 除外。
* **版本演进明细**:详细梳理了从 v2.1.172 到 v2.1.219+ 版本间默认行为的变化(5层 -> 1层 -> 3层)。
### 影响级别:中等
**理由**:虽然这是一个非破坏性的功能增强(因为可以通过环境变量覆盖),但它改变了系统的默认操作模式。启用子代嵌套默认开启可能会导致更复杂的任务并行执行,影响资源消耗和调试体验。
### 开发者行动项
* **检查配置**:检查 `settings.json` 中的 `CLAUDE_CODE_MAX_SUBAGENT_SPAWN_DEPTH` 值,确认是否符合当前版本的默认预期(默认为 3)。
* **控制嵌套行为**:如果你不希望子代理自动生成下级子代理,请将该环境变量显式设置为 `1`。
* **理解限制边界**:认识到当嵌套达到第 3 层时,任务将由该子代理自身完成而非继续分发。
💭 Model Reasoning
1. **Analyze the Request:**
* **Role:** World-class programmer with expertise in dev tools and documentation.
* **Task:** Analyze documentation changes for a single batch (one file: `sub-agents.md`).
* **Output Format:** Markdown.
* **Language:** Chinese (as requested by the prompt "请用中文回复").
* **Structure:** Overall Summary, Key Themes, Impact Level with reasoning, Action Items.
2. **Analyze the Input Data (`sub-agents.md` Diff):**
* **Change 1 (Line ~323):** "until you turn on nested spawning" -> "when the subagent is at the depth limit".
* **Change 2 (Line ~395):** "once you allow nested spawning" -> "while the depth limit allows it".
* **Change 3 (Line ~845):** Major rewrite of the section "Let subagents spawn their own subagents".
* Old: "By default, a subagent can't spawn subagents... While nesting is off..."
* New: "By default, a subagent can spawn subagents of its own, up to three layers below the main conversation. At the depth limit..."
* **Change 4 (Line ~859):** "To allow nesting..." -> "To change the limit..." + Added version tag `{/* min-version: 2.1.217 */}`.
* **Change 5 (Line ~860-869):** Updated examples and notes explaining version history.
* New Note explains versions 2.1.172-2.1.216 (default 5), 2.1.217-2.1.218 (default 1), 2.1.219+ (default 3).
3. **Synthesize the Changes:**
* *Core Change:* The behavior of subagent nesting (recursion) has changed significantly in recent versions (2.1.219+).
* *Previous Behavior (Old docs):* Nesting was off by default (or required explicit enabling, depending on version interpretation of the old text). The old text said "While nesting is off...".
* *New Behavior:* Nesting is now **on by default** with a depth limit of **3**.
* *Mechanism:* The `Agent` tool is withheld when the `depth limit` is reached, rather than just being "off" generally.
* *Configuration:* Users can now change this limit via `CLAUDE_CODE_MAX_SUBAGENT_SPAWN_DEPTH`.
4. **Draft the Analysis (Internal Monologue/Drafting):**
* *Overall Summary:* The documentation updates reflect a change in default behavior for subagent spawning (nesting). It's now enabled by default with a limit of 3 layers, rather than being disabled.
* *Key Themes:*
* Default behavior change: Off (or version-dependent) -> On (limit 3).
* Concept of "Depth Limit": The tool is withheld at the limit.
* Versioning history: Explicitly detailing behavior across versions 2.1.172 to 2.1.219+.
* *Impact Level:* Medium. This changes how agents delegate tasks automatically without user config, potentially affecting complexity and token usage, but it's likely an improvement for most use cases. It's not "Breaking" because the environment variable can control it, but it is a significant behavioral shift.
* *Action Items:*
* Review `CLAUDE_CODE_MAX_SUBAGENT_SPAWN_DEPTH` setting.
* Update expectations about how parallel tasks are handled.
* Be aware of the specific default (3 layers) if running on v2.1.219+.
5. **Translate to Chinese (Target Language):**
* *Summary:* 文档更新主要反映了 Claude Code 子代生成行为的重大变更。子代生成现在默认开启,最大深度限制为 3 层,而非之前的默认关闭或不可配置状态。
* *Themes:*
* 默认行为变更: 子代生成默认开启(深度限制为 3)。
* 深度限制机制: 解释了 `Agent` 工具会在达到深度限制时被移除。
* 版本历史明细: 增加了版本演进说明,特别是 v2.1.219 前后的差异。
* *Impact:* Medium (中等)。虽然增加了默认功能,但用户可以通过环境变量回退或调整。
* *Action Items:*
* 检查 `settings.json` 中的 `CLAUDE_CODE_MAX_SUBAGENT_SPAWN_DEPTH` 设置。
* 了解新的默认层级深度(3 层)可能带来的并行任务变化。
* 如需限制子代生成,将环境变量设为 `1`。
6. **Refine for "World-Class Programmer" Persona:**
* Make it punchy.
* Focus on the "Why it matters": This changes how recursive delegation works.
7. **Final Polish (Markdown Generation):**
* Structure check: Summary, Themes, Impact, Action Items.
*(Self-Correction during drafting)*: The impact is "Medium" because existing workflows that relied on the agent doing things *itself* might now spawn sub-agents, potentially changing performance or cost, but it's generally a positive feature release.
8. **Final Output Generation (matches the provided good response):**
* Summary: 子代生成默认开启。
* Themes: 默认行为改变,深度限制概念,版本兼容性。
* Impact: Medium.
* Actions: 检查环境变量配置,适应新默认值。