技能 Frontmatter
context: fork、allowed-tools 和 argument-hint。
技能 Frontmatter 是 CoddyKit 上的免费 Claude Architect 课时。 这是第 2 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Claude Architect 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Claude Architect 课程共包含 4 节课。
本课时的部分内容尚未翻译,以英文显示。
Why Frontmatter Matters
In Claude Code, a skill lives under .claude/skills/ and packages a reusable workflow. The body holds the instructions; the YAML frontmatter at the top configures how the skill executes.
Three frontmatter keys do most of the architectural work:
context: fork— isolate verbose output from your main session.allowed-tools— restrict which tools the skill may use.argument-hint— document the expected input.
Getting these right is the difference between a tidy, least-privilege skill and one that floods your context window or runs tools it never should.
Anatomy of a Skill File
A skill is a markdown file. The fenced YAML block at the very top is the frontmatter; everything below is the prompt Claude follows.
Note the distinction from the older .claude/commands/ directory (legacy) — .claude/skills/ is the current home. Both share project scope via VCS, while a copy under ~/.claude/ is personal and not shared with teammates.
---
name: audit-deps
description: Scan dependencies for known CVEs and summarize risk
context: fork
allowed-tools: Read, Grep, Glob, Bash
argument-hint: <package-name> [--severity high]
---
Audit the project's dependencies. If a package name is
provided as $ARGUMENTS, focus on that package; otherwise
scan all manifests. Report only HIGH and CRITICAL findings.context: fork — The Core Idea
context: fork runs the skill in an isolated context branched from a shared point, then returns only the result to the main conversation. The verbose, intermediate output stays in the fork and never pollutes your primary window.
This is the same isolation principle behind an Explore subagent: discovery work generates a lot of noise, so you isolate it and hand back a clean summary. Skills make that pattern declarative — one line of frontmatter.
Why Isolation Protects Reliability
Context windows are not infinite, and models attend to the start and end of a long context more than the middle ("lost-in-the-middle"). A skill that greps hundreds of files or dumps long build logs into the main session pushes your real task into that weak middle zone.
context: fork keeps that bulk out. You preserve attention for what matters and avoid burning tokens on transient tool chatter that you'll never reference again.
When to Fork (and When Not To)
Fork when the skill produces verbose output you don't need to keep: dependency scans, log analysis, broad codebase exploration, test-suite runs.
Do not fork when the skill's full output is the deliverable you want inline in the main conversation — for example a short refactor of one file you're about to discuss. Forking there just adds a round-trip and hides detail you actually wanted.
- Fork: noisy discovery, returns a summary.
- No fork: small, surgical edits you keep working with.
---
name: analyze-logs
description: Parse the last 24h of error logs and surface top failure modes
context: fork
allowed-tools: Read, Grep, Bash
argument-hint: [service-name]
---
Grep the log files for ERROR/FATAL lines, group by message
template, and return ONLY the top 5 failure modes with counts.
Keep raw log lines inside this fork; do not echo them back.allowed-tools — Least Privilege
allowed-tools restricts the skill to a named set of tools. This is the principle of least privilege applied to a workflow: a read-only audit skill should never hold Write or Edit.
It mirrors how you scope an agent's allowed_tools to its role. Narrow tool access reduces blast radius and also sharpens selection — fewer, well-scoped tools are chosen more reliably than a large grab-bag.
---
name: read-only-review
description: Inspect code and report findings WITHOUT modifying files
context: fork
allowed-tools: Read, Grep, Glob
argument-hint: <path-or-glob>
---
Review the matching files for correctness issues.
You may read and search only. Report findings as a list;
never attempt to edit — you have no write tools.Restriction Is Not Enforcement
Be precise about what allowed-tools guarantees. It limits the menu of tools the skill can pick from — a useful, deterministic boundary on capability.
But it is not a substitute for a hook when a business rule must hold with certainty. If "never refund over $500" or "never push to main" has financial, legal, or safety stakes, enforce it with a deterministic hook (e.g. PostToolUse or an outgoing-call block), not by hoping the skill's prompt and tool list behave. Prompts are ~90% probabilistic; hooks are 100%.
argument-hint — Documenting Input
argument-hint describes the arguments the skill expects. It surfaces usage to the caller and documents intent — the angle-bracket and bracket convention signals required vs optional parameters.
Inside the body, those arguments arrive via $ARGUMENTS (or positional $1, $2). The hint is for humans and tooling; it does not parse or validate — your skill body decides how to interpret the input.
---
name: scaffold-endpoint
description: Generate a REST endpoint with handler, route, and test
allowed-tools: Read, Write, Edit, Glob
argument-hint: <resource-name> <http-method> [--auth]
---
Scaffold an endpoint for $1 using HTTP method $2.
If --auth is present, wire in the auth middleware.Writing a Good argument-hint
A good hint follows the same discipline as a good tool description: state the input format, show the expected shape, and signal which parts are optional.
- Use
<required>for mandatory arguments. - Use
[optional]for flags and extras. - Order positional arguments the way the body reads them.
An ambiguous hint causes misuse the same way an ambiguous tool description causes misrouting — clarity at the boundary prevents errors downstream.
The Three Keys Together
The keys compose into one coherent contract. A well-formed skill says: here is what I take (argument-hint), here is what I'm allowed to touch (allowed-tools), and here is how I keep your session clean (context: fork).
Read together, the frontmatter lets a teammate understand the skill's behavior and safety boundary without reading the body — exactly what shared, version-controlled config should provide.
---
name: security-scan
description: Static security scan; returns a ranked findings summary
context: fork
allowed-tools: Read, Grep, Glob, Bash
argument-hint: <path> [--fail-on critical]
---
Scan $1 for injection, secrets, and unsafe deserialization.
Run analysis in this fork; return a ranked summary only.
You have no Write/Edit tools — report, do not patch.Scope and Sharing
Where the skill file lives decides who gets it. A skill in the project's .claude/skills/ is committed to VCS and shared with the whole team. A skill under ~/.claude/skills/ is personal — a new teammate cloning the repo will never see it.
This is the same trade-off as user-level vs project-level CLAUDE.md. If a skill encodes a team standard, commit it to project scope so the contract travels with the code.
Quick Check
Apply what you've learned to a concrete design decision.
Recap
Skill frontmatter is a compact safety-and-clarity contract built from three keys:
- context: fork — isolate verbose output, return a clean summary, protect the main context window from lost-in-the-middle dilution.
- allowed-tools — least-privilege capability boundary; restricts the tool menu but does NOT enforce business rules — use a deterministic hook for policies with financial/legal/safety stakes.
- argument-hint — documents expected input (<required> vs [optional]); like a good tool description, clarity here prevents misuse. It does not validate.
Commit team skills to project .claude/skills/ so the contract ships with the code; keep personal ones in ~/.claude/.
常见问题解答
「技能 Frontmatter」课时是免费的吗?
是的 — 「技能 Frontmatter」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Claude Architect 课程的其余内容,请升级到 CoddyKit PRO。 Claude Architect 课程共包含 4 节课。
「技能 Frontmatter」这节课中我会学到什么?
context: fork、allowed-tools 和 argument-hint。 你通过在浏览器中直接运行的动手代码来练习 Claude Architect,全天候 AI 导师会在你学习这节课的过程中回答你的问题。
学习 Claude Architect 需要有经验吗?
无需任何先前经验。CoddyKit 上的 Claude Architect 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 2 节课,共 4 节。
「技能 Frontmatter」课时需要多长时间?
大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。
我能在这节 Claude Architect 课中编写并运行代码吗?
能。每节 Claude Architect 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。
此课程中的所有课时
- 自定义命令与技能
- 技能 Frontmatter
- 计划模式与直接执行
- 使用示例进行迭代改进