Tabbit
活动资源博客模型
Tabbit LogoTabbit

Tabbit — 为你工作的 AI 浏览器

主题资源

  • AI Browser Resources
  • Agentic Browser Resources
  • Browser Downloads and Install Guides
  • Browser Comparisons
  • AI Browser Alternatives
  • Browser Productivity Resources

热门指南

  • AI Browser
  • Agentic Browser Download
  • Best AI Browser 2026: Top 9 Tested & Ranked
  • AI Browser Download
  • Free AI Browser
  • Best AI Browser 2026
  • AI Browser Comparison 2026
  • AI Browser for Windows
  • AI Browser for Mac
  • Chrome Alternative 2026

活动

  • 别装了,你在《牛来》里早有原型
  • Tabbit 妙招大赛
  • KPOP SBTI 饭圈人格测试
  • Tabbit 校园共创者计划
  • fifi 的论文文献妙招精选
  • 用户问卷

关于

  • Tabbit 博客
  • 媒体报道
提示词
媒体Claude Opus 4.7

Claude Opus 4.7:官方 Claude Code 定制指南 - CLAUDE.md、Skills、Hooks 与 Subagents 的选择

原始来源

Anthropic 官方博客

作者Anthropic 官方

原文日期2026-06-18

Tabbit 整理2026-08-20

查看原文

一句话结论

Anthropic 官方提供七种定制 Claude Code 行为的方法(CLAUDE.md、Rules、Skills、Subagents、Hooks、Output Styles、System Prompt Appending),每种方法在加载时机、压缩行为和上下文成本上有所不同,需根据具体需求选择合适的方法。

适用场景

  • 适合的任务:需要系统化理解 Claude Code 定制机制的场景;需要决定在哪里放置项目规范、团队约定、自动化流程等

  • 不适合的任务:需要深度技术实现细节的场景(本文更偏向决策框架)

  • 适用的模型版本:Claude Opus 4.7(通过 Claude Code 使用)

  • 适用的客户端、Agent 或 API:Claude Code CLI

  • 推荐的推理档位和参数:N/A(本文讨论定制机制,不涉及具体任务)

可直接使用的内容

七种定制方法对比表

MethodWhen it's loadedCompaction behaviorContext costWhen to use
CLAUDE.md (root)Session start; stays in context for the entire sessionMemoized. Read once and cached for the session; cache cleared and re-read after compactionHigh. Every line costs tokens whether relevant or notBuild commands, directory layout, monorepo structure, coding conventions, team norms
CLAUDE.md (subdirectory)On-demand, when Claude reads a file under that subdirectoryLost until that subdirectory is touched againLow. Only consumes context when the relevant subdirectory is being worked onConventions specific to a subdirectory
RulesSession start (user-level rules) or only when matching files are touched (path-scoped)Re-injected on compactionMedium. Always-on unless path-scopedSpecific constraints or conventions (e.g., all API handlers must validate input with Zod)
SkillsName and description at session start; full body loads when the skill is invokedInvoked skills re-injected up to a shared budget; oldest dropped firstLow. Full body loads only when invoked; subject to a shared token budget across invoked skillsProcedural workflows (deploy or release checklists)
SubagentsName, description, and tool list at session start; body loads only when called via the Agent toolOnly the final message (summary plus metadata) returns to the main sessionLow. Zero cost in main context until called; runs in its own isolated context windowRunning work in parallel or side tasks that should run in isolation and return only a summary (deep search, log analysis, dependency audit)
HooksFire on lifecycle eventsBypass compaction entirelyLow. Configuration lives outside main context; some output may return (e.g., blocking errors)Deterministic automation: run linters, post to Slack on completion, block commands, back up chat history on PreCompact
Output stylesSession start; injected into the system promptNever compactedHigh. Occupies context window, but overwrites default system promptSignificant role changes (code assistant to general assistant)
Appending the system promptSession start; passed as a CLI flagNever compacted; applies only to that invocationModerate. Cached after first request in a sessionTone, response length, formatting preferences

CLAUDE.md 最佳实践

两种类型:

  1. Always loaded: 根目录 CLAUDE.md,在会话开始时加载,跨长会话不会丢失或降级

  2. On-demand: 子目录 CLAUDE.md,仅当 Claude 读取该子目录下的文件时加载

关键建议:

  • 保持 CLAUDE.md 在 200 行以内

  • 指定所有者,像代码一样审查变更

  • 将团队特定约定推送到 path-scoped rules

  • 将流程推送到 skills

  • 在 monorepos 中,给每个团队的目录自己的子目录 CLAUDE.md

Monorepo 配置:

{
  "claudeMdExcludes": ["teams/other-team/**"]
}

Rules 示例

---
paths:
  - "src/api/**"
  - "**/*.handler.ts"
---
All API handlers must validate input with Zod before processing.

决策框架

选择 CLAUDE.md (root) 当:

  • 构建命令、目录布局、monorepo 结构

  • 编码约定、团队规范

  • 需要在整个会话中始终可用

选择 CLAUDE.md (subdirectory) 当:

  • 约定仅适用于特定子目录

  • 希望减少上下文成本

选择 Rules 当:

  • 需要硬约束(如"所有 API 处理器必须用 Zod 验证输入")

  • 需要 path-scoped 约束

选择 Skills 当:

  • 需要可复用的流程(部署清单、发布检查)

  • 希望按需加载以节省上下文

选择 Subagents 当:

  • 需要并行运行工作

  • 需要在隔离上下文中运行任务并仅返回摘要(深度搜索、日志分析、依赖审计)

选择 Hooks 当:

  • 需要确定性自动化(运行 linter、阻止命令、备份聊天历史)

  • 需要在生命周期事件上触发

选择 Output styles 当:

  • 需要显著角色变更(代码助手到通用助手)

选择 Appending the system prompt 当:

  • 需要设置语调、响应长度、格式偏好

测试/工作流步骤

  1. 评估当前项目:识别哪些规范需要始终可用(放入 CLAUDE.md root),哪些仅在特定场景下需要(放入子目录或 rules)

  2. 审查现有 CLAUDE.md:如果超过 200 行,考虑将团队约定推送到 rules,流程推送到 skills

  3. 为 Monorepo 配置:为每个团队创建子目录 CLAUDE.md,使用 claudeMdExcludes 排除不相关的团队文件

  4. 创建 Rules:为硬约束创建 path-scoped rules

  5. 创建 Skills:为可复用流程创建 skills

  6. 配置 Hooks:为自动化任务配置 hooks(如运行 linter、阻止危险命令)

  7. 测试压缩行为:在长会话中测试各种方法的压缩行为,确保关键规范不会丢失

原始证据与数据

  • 文章明确列出七种方法及其加载时机、压缩行为、上下文成本和使用时机

  • 强调 CLAUDE.md 应保持 200 行以内,并指定所有者

  • 提供 Rules 的 YAML frontmatter 格式示例

  • 详细说明每种方法的优缺点和适用场景

  • 强调 Skills 使用共享 token 预算,最旧的最先丢弃

  • 说明 Subagents 在主上下文中零成本,仅在调用时加载

适用边界

  • 本文提供决策框架,不提供具体实现细节

  • 七种方法可以组合使用,需要根据具体项目需求权衡

  • CLAUDE.md 的 always-loaded 类型会在每次会话中消耗 token,即使不相关

  • Skills 的共享 token 预算可能导致最旧的 skills 被丢弃

  • Hooks 绕过压缩,但配置在主上下文之外

来源摘录或观察(仅做合规短引)

官方文章:"Think of this file as giving Claude an overview of your codebase, or as an index pointing to other files where Claude can find more information as needed."

"Keep CLAUDE.md under 200 lines, give it an owner, and review changes to it like code."

"Each method trades context cost against authority."

Tabbit 小编提醒

提示词内容来自公开资料与 Tabbit 编辑整理。引用前请查看原文授权与适用范围。

Claude Opus 4.7

在 Tabbit 中使用

Claude Opus 4.7

相关提示词

媒体Anthropic Claude Platform Docs / Anthropic Newsroom2026-04-16

Claude Opus 4.7:努力档位与迁移提示模板

媒体Anthropic 官方文档

Claude Opus 4.7:Anthropic 官方提示词库与最佳模式

媒体ZooClaw AI Help2026-04-07

Claude Opus 4.7:三模式实战策略 - Caveman 提示词、CLAUDE.md 安全护栏与 Git Worktrees

媒体Tenten Learning

Claude Opus 4.7:50+ 社群精华技巧完全攻略

Claude Opus 4.7

相关测评

媒体Anthropic Newsroom2026-04-16

Claude Opus 4.7:官方编码、视觉与 Agent 基准

媒体Vellum2026-04-16

Claude Opus 4.7:Vellum 跨模型基准与任务选型

社区Reddit r/ClaudeCode

Claude Opus 4.7:Reddit ClaudeCode 发布后长会话体验