代码生成与开发者效率
CLAUDE.md、计划模式、内置工具和调查。
代码生成与开发者效率 是 CoddyKit 上的免费 Claude Architect 课时。 这是第 2 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Claude Architect 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Claude Architect 课程共包含 4 节课。
本课时的部分内容尚未翻译,以英文显示。
Scenario 4: Developer Productivity
This lesson maps to Scenario 4 — Developer Productivity, one of the eight exam scenarios. The architect's job here is to make Claude Code an effective teammate inside a real repository: investigating unfamiliar code, planning changes safely, and persisting team conventions.
Three pillars carry most of the exam weight in this scenario:
- CLAUDE.md — durable, shared project memory.
- Plan mode — explore and propose before editing.
- Built-in tools + incremental investigation — Glob, Grep, Read, Write, Edit, Bash used in a disciplined loop.
Get these decisions right and you'll handle most D3 (Config & Workflows) questions.
The CLAUDE.md Hierarchy
CLAUDE.md is persistent context loaded automatically into every session. There are three scopes, and choosing the right one is a frequent exam decision:
- User-level
~/.claude/CLAUDE.md— personal preferences. NOT shared via VCS, so new teammates never see it. - Project-level
./CLAUDE.mdor.claude/CLAUDE.md— committed to the repo and shared with the whole team. - Directory-level — scoped to a subtree, loaded when working in that folder.
Rule of thumb: anything every contributor must follow belongs in the project-level file. Putting team conventions only in your user-level file is a classic trap answer.
# Project memory — committed to VCS, shared with the team
# ./CLAUDE.md
## Build
- `yarn build` then run `dist/main.js`
## Conventions
- Use absolute imports from `src/`
- All API errors return structured `{ code, message }`
- Never commit secrets; read from env varsModularizing CLAUDE.md with @imports
A monolithic CLAUDE.md grows unwieldy and burns context tokens on every turn. Two mechanisms keep it lean:
- @path imports — pull in modular files, e.g.
@./standards/coding-style.md, so shared standards live in their own versioned files. - .claude/rules/ files — each carries YAML frontmatter with a
pathsglob, and loads only when you edit matching files. This saves context versus stuffing everything into one always-loaded CLAUDE.md.
Use rules for narrowly-scoped guidance (e.g. test conventions) that is irrelevant most of the time.
---
# .claude/rules/testing.md
paths:
- "**/*.test.ts"
- "**/*.spec.ts"
---
# Loaded ONLY when editing test files
- Use the existing `makeTestClient()` helper
- One assertion concern per `it(...)` block
- Never mock the database; use the in-memory fixtureEditing Memory: /memory and /compact
Two slash commands manage long-lived context:
- /memory edits CLAUDE.md directly and persists across sessions — use it to capture a hard-won convention so it's enforced next time.
- /compact compresses the current conversation to free context window. Beware: progressive summarization makes numbers, percentages, and dates vague. If exact values matter, keep them verbatim outside the summary rather than relying on /compact.
The exam likes to contrast durable memory (CLAUDE.md) with transient compression (/compact) — they solve different problems.
# Persist a convention into CLAUDE.md (survives future sessions)
/memory
# Compress the running conversation to reclaim context window
/compactPlan Mode: Explore Before You Edit
Plan mode lets Claude explore the codebase and propose an approach that you approve before any edits land. Reach for it when:
- The change is large or touches many files.
- There are multiple viable approaches to weigh.
- An architectural decision is involved.
- You want safe exploration of unfamiliar code first.
For a single-file fix or a clear stack trace, skip plan mode and go straight to direct execution — planning overhead there is wasted. Matching mode to task size is the core decision this scenario tests.
Isolating Discovery with the Explore Subagent
Investigation produces a lot of verbose output — file dumps, search hits, traces — that can crowd the main context window. The Explore subagent isolates that discovery work, returning a distilled summary instead of raw noise.
This is the same principle as a Skill with context: fork: run the messy, token-heavy part in an isolated context so the main session stays focused. Pair plan mode with an explore step for big, unfamiliar changes.
---
# .claude/skills/audit-deps.md
name: audit-deps
description: Scan the repo for outdated/vulnerable dependencies
context: fork # isolate verbose scan output
allowed-tools: [Bash, Grep, Read]
argument-hint: "[package-name]"
---
Run the dependency audit and report only actionable findings.The Built-in Tool Set
Claude Code ships a focused set of built-in tools. Knowing what each is FOR is exam-critical:
- Glob — find files by pattern, e.g.
**/*.test.tsx. - Grep — search file contents.
- Read — load a file into context.
- Write — create a file.
- Edit — a precise, unique-match change.
- Bash — run shell commands.
Glob finds files by name/pattern; Grep finds files by what's inside them. Mixing those two up is a common distractor.
# Glob: locate files by pattern
**/*.service.ts
# Grep: search contents across the repo
grep -rn "process_refund" src/
# Bash: run the test suite
yarn test --runInBandEdit vs Read+Write
Edit performs a precise change by matching a unique string in the file. If the target string is not unique, the edit fails — that's a safety feature, not a bug.
The correct fallback is to Read the file, then Write the full corrected version (or expand the match with more surrounding context to make it unique). Don't force ambiguous edits; that risks changing the wrong occurrence.
Edit is for surgical, unambiguous changes; Read+Write is for broader or ambiguous rewrites.
# Pseudocode of the decision
# 1) Try a unique-match Edit
# old_string must appear EXACTLY once in the file
# 2) If the match is not unique -> Edit fails
# 3) Fallback: Read the whole file, then Write the corrected version
# (or add more surrounding lines to old_string to disambiguate)Incremental Investigation
The exam rewards a disciplined investigation loop rather than dumping the whole repo into context. The canonical pattern:
- Grep the entry points (where does this feature start?).
- Read the relevant files you found.
- Grep for usages of the symbols you discovered.
- Read the consumers to understand impact.
This narrows scope step by step and avoids the lost-in-the-middle problem of over-stuffed context. Trim verbose tool output to the relevant fields as you go.
# 1) Find the entry point
grep -rn "router.post('/refund'" src/
# 2) Read the handler file (Read tool)
# 3) Grep usages of the function it calls
grep -rn "processRefund(" src/
# 4) Read each consumer to assess blast radiusExtending Reach with MCP
Built-in tools cover the local filesystem and shell. To reach external systems — a GitHub repo, a database, an issue tracker — connect an MCP server.
- Server primitives: Tools (actions), Resources (read-only data like schemas/catalogs), Prompts (templates).
- Scope: project
.mcp.json(shared in VCS) vs user~/.claude.json(personal). - Secrets go through env vars like
${GITHUB_TOKEN}— never commit tokens. - Prefer a maintained community MCP server over building a custom one for standard integrations.
{
"mcpServers": {
"github": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": { "GITHUB_TOKEN": "${GITHUB_TOKEN}" }
}
}
}Commands and Skills
Reusable workflows live in two places. .claude/commands/ is the legacy form; .claude/skills/ is the current one. Both follow the same scoping rule:
- Project scope (in the repo) — shared with the team via VCS.
- User scope (
~/.claude/) — personal, not shared.
Skill frontmatter gives you real control: context: fork to isolate verbose output, allowed-tools to restrict capability (least privilege), and argument-hint to document inputs. Package a recurring investigation as a project-scoped skill so the whole team runs it consistently.
---
# .claude/skills/triage-bug.md (project scope -> shared via VCS)
name: triage-bug
description: Reproduce a bug, locate root cause via incremental investigation
context: fork
allowed-tools: [Grep, Read, Bash]
argument-hint: "<issue-id or stack trace>"
---
Grep entry points, Read suspects, Grep usages, then summarize root cause.Quick Check: Choosing Your Approach
A scenario question on configuring Claude Code for a developer-productivity workflow.
Recap: Developer Productivity Essentials
Key takeaways for Scenario 4:
- CLAUDE.md scope: project-level (VCS-shared) for team rules; user-level is personal and unshared; directory-level for subtrees.
- Keep it lean: @path imports modularize, and
.claude/rules/with apathsglob load only when relevant. - /memory persists conventions; /compact compresses but blurs numbers and dates.
- Plan mode for large, multi-approach, or architectural changes; direct execution for single-file fixes and clear stack traces. The Explore subagent isolates noisy discovery.
- Built-in tools: Glob (find by pattern), Grep (search contents), Read, Write, Edit (unique-match; fall back to Read+Write), Bash. Investigate incrementally: Grep entry points -> Read -> Grep usages -> Read consumers.
- MCP extends reach to external systems; prefer community servers, scope via .mcp.json, secrets through env vars.
Match the tool and mode to the task, and let durable config do the remembering.
常见问题解答
「代码生成与开发者效率」课时是免费的吗?
是的 — 「代码生成与开发者效率」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Claude Architect 课程的其余内容,请升级到 CoddyKit PRO。 Claude Architect 课程共包含 4 节课。
「代码生成与开发者效率」这节课中我会学到什么?
CLAUDE.md、计划模式、内置工具和调查。 你通过在浏览器中直接运行的动手代码来练习 Claude Architect,全天候 AI 导师会在你学习这节课的过程中回答你的问题。
学习 Claude Architect 需要有经验吗?
无需任何先前经验。CoddyKit 上的 Claude Architect 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 2 节课,共 4 节。
「代码生成与开发者效率」课时需要多长时间?
大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。
我能在这节 Claude Architect 课中编写并运行代码吗?
能。每节 Claude Architect 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。
此课程中的所有课时
- 支持代理与多代理研究
- 代码生成与开发者效率
- CI/CD 与结构化提取
- 对话模式与代理式工具