AI guide
# Claude Code实战:Harness工程之道
【One-Line Pitch】
A practical engineering guide to Claude Code as a programmable agent framework—covering memory systems, skills, subagents, hooks, and MCP—for developers who want to move beyond chat-style usage and build robust, automated AI-assisted workflows.
【Book Arc】
- **Opening (~0%–10%)**: Introduces Claude Code as an "Agentic Harness"—not just a CLI tool but a programmable framework. Establishes the four-layer architecture model (memory, extension, integration, and automation layers) and contrasts naive "manual scripting" usage with systematic configuration.
- **Early (~10%–29%)**: Deep dive into the memory layer (CLAUDE.md) and the extension layer's four components—Commands, Skills, SubAgents, and Hooks. Covers the deterministic-vs-AI-judgment trigger dichotomy, component selection decision trees, and the "request journey" data flow. Includes practical CLAUDE.md templates for frontend and Node.js backend projects.
- **Early–Middle (~29%–43%)**: Focuses on Skills design patterns (router thinking, YAML frontmatter, quick-reference tables, dynamic command injection) and the five SubAgent patterns (read-only, executor, pipeline, parallel, team-based). Emphasizes when subagents add value (input >> output scenarios) versus when they add unnecessary overhead.
- **Middle (~43%–57%)**: Covers Hooks for event-driven automation—positioning them as enforced guardrails (unlike CLAUDE.md's suggestions). Details the six-layer configuration priority system, three handler types (command/prompt/agent) with a "degrade by default" principle, and the hookSpecificOutput protocol. Transitions into MCP for external integrations.
- **Late (~57%–end)**: Explores MCP configuration (stdio vs HTTP transport, CLI commands, .mcp.json), the "kitchen vs recipe" analogy for MCP+Skills synergy, and Headless mode for CI/CD integration—enabling unattended PR review, automated testing, and pipeline embedding.
【Key Takeaways】
- **Claude Code is a harness, not a chatbot** (Opening): It reshapes how model intelligence is controlled and transmitted—like a horse harness directing power. The framework's value lies in systematic configuration over per-session prompting.
- **CLAUDE.md is the foundation layer** (Early): It encodes project context (tech stack, conventions, commands) so every session starts with "read the manual." Without it, Claude defaults to internet-popular patterns (Express over Fastify, npm over pnpm) rather than your team's standards.
- **Four extension components map to four trigger philosophies** (Early): Commands ("you call it"), Skills ("it knows when to act"), SubAgents ("it delegates"), Hooks ("checkpoint enforcement"). The deterministic-vs-AI-judgment split guides component selection—use Hooks for security-critical checks, Skills for flexible domain matching.
- **Skills are routers, not repositories** (Early): SKILL.md should contain core workflow and a Quick Reference table (~50 tokens for 3 lines), with detailed knowledge in referenced files. Write descriptions with What/When/Not-For structure to maximize trigger accuracy within the 1024-character limit.
- **SubAgents shine when input >> output** (Middle): Use them for large-file analysis, high-volume output filtering, context protection for long tasks, and security isolation. Skip them for simple edits where isolation overhead isn't justified. Five patterns (read-only, executor, pipeline, parallel, team) combine flexibly but avoid nesting beyond two levels.
- **Hooks enforce what CLAUDE.md can only suggest** (Middle): PreToolUse hooks can block dangerous operations (e.g., committing .env files) with deterministic checks. Follow the degradation principle: command type > prompt type > agent type—use LLM judgment only when pattern matching can't suffice.
- **MCP + Skills = kitchen + recipes** (Late): MCP provides the tools/data (kitchen), Skills provide the standardized procedures (recipes). Combining them yields stable, repeatable automation without relying on Claude's improvisation each session.
- **Headless mode transforms Claude into a pipeline citizen** (Late): With `claude -p`, `--output-format json`, `--max-turns`, and `--allowed-tools`, Claude runs unattended in CI/CD—acting as a PR "first reviewer" that frees human engineers for higher-level judgment.
【Reading Tips】
- **Skim the narrative dialogue sections** (the "咖哥/小雪" story framing) and focus on the technical tables, code blocks, and decision trees—they contain the actionable content.
- **Deep-read Chapters 2–3** (CLAUDE.md and Skills): These are the most transferable skills. The frontend/backend CLAUDE.md templates and Skill design patterns (template-driven, script-enhanced, knowledge-layered, tool-isolated) are directly reusable.
- **Pay attention to the component selection decision trees** (around 10% and 29% marks): They provide practical heuristics for choosing between Commands/Skills/SubAgents/Hooks and for deciding when subagents are worth the overhead.
- **For Hooks and MCP chapters**, focus on the configuration patterns and security principles rather than memorizing every JSON example—the "degrade by default" rule and the stdio-vs-HTTP transport guideline are the key takeaways.
- **If you're a solo developer**, skim the team-collaboration and CI/CD sections lightly; if you're a team lead, those sections (especially Headless mode for PR review) are your primary value.
【Coverage Limits】
Excerpts do not cover the Agent SDK or Plugins ecosystem chapters in depth (mentioned in the introduction but not detailed in sampled content), nor the final chapters on enterprise deployment beyond CI/CD integration.
Passage locations
Page 17
转变,不仅极大地提升了效率,更深刻 地重塑了人机协作的质量。配置一旦确立,Claude Code便不会遗忘、不会懈怠, 更不会因深夜加班而降低标准——这正是将个体智慧沉淀为制度规范的工程思想精 髓。 接下来,我们将深入拆解这一框架的内部结构。 1.2 四层架构模型 任何复杂系统在被人真正理解之前,都需要一张清晰的...
View in text
Excerpt 2
itignore排除,不会提交至 代码仓库。 这一机制构建了一个“犯错→纠正→记忆写入→避免再犯”的良性闭环。随着时间 的推移,你的记忆文件将愈发精准,Claude Code在项目中的表现也将随之持续进 化。 2.4 条件化规则系统 随着项目的演进,单一CLAUDE.md终将面临容量瓶颈。 当项目涵盖前端组件规范...
View in text
Excerpt 3
“怎么做”:详述具体的执行工作流、标准化的 输出格式以及所需的专业领域知识。 下面是一个完整的代码审查子智能体定义示例。在展示具体代码前,我们先明确其 设计意图:该子智能体被定位为一名严格的只读审查员。它仅具备观察代码的权 限,严禁修改任何文件;同时,其审查结果将遵循固定的结构化格式输出,以便主 智能体能高效提取...
View in text
Excerpt 4
NSIONS=("pem" "key" "p12" "pfx") # 受保护的目录 PROTECTED_DIRS=(".git/" ".ssh/" "node_modules/") # 检查目录 for dir in "${PROTECTED_DIRS[@]}"; do if [[ "$FILE_PATH" ==...
View in text