claude-code-mastery

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Claude Code Mastery

Claude Code 精通指南

Expert-level skill for mastering Claude Code CLI -- from CLAUDE.md optimization and skill authoring to subagent creation, hooks automation, and context engineering.
精通Claude Code CLI的高阶技能——从CLAUDE.md优化、Skill创作到子Agent创建、Hooks自动化及上下文工程全覆盖。

Keywords

关键词

claude-code, claude-cli, CLAUDE.md, skill-authoring, subagents, hooks, context-window, token-budget, MCP-servers, worktrees, permission-modes, prompt-engineering, context-engineering, progressive-disclosure, slash-commands

claude-code, claude-cli, CLAUDE.md, skill-authoring, subagents, hooks, context-window, token-budget, MCP-servers, worktrees, permission-modes, prompt-engineering, context-engineering, progressive-disclosure, slash-commands

Table of Contents

目录

Quick Start

快速开始

bash
undefined
bash
undefined

Scaffold a new skill package with proper structure

搭建结构规范的新Skill包脚手架

python scripts/skill_scaffolder.py my-new-skill --domain engineering --description "Brief description"
python scripts/skill_scaffolder.py my-new-skill --domain engineering --description "简要描述"

Analyze and optimize an existing CLAUDE.md

分析并优化现有CLAUDE.md

python scripts/claudemd_optimizer.py path/to/CLAUDE.md
python scripts/claudemd_optimizer.py path/to/CLAUDE.md

Estimate context window usage across a project

估算项目整体上下文窗口使用情况

python scripts/context_analyzer.py /path/to/project
python scripts/context_analyzer.py /path/to/project

All tools support JSON output

所有工具均支持JSON格式输出

python scripts/claudemd_optimizer.py CLAUDE.md --json python scripts/context_analyzer.py . --json --max-depth 3

---
python scripts/claudemd_optimizer.py CLAUDE.md --json python scripts/context_analyzer.py . --json --max-depth 3

---

Tools Overview

工具概览

1. Skill Scaffolder

1. Skill脚手架工具

Generates a complete skill directory with SKILL.md template, scripts/, references/, assets/ directories, and properly formatted YAML frontmatter.
bash
python scripts/skill_scaffolder.py my-skill --domain engineering --description "Does X"
python scripts/skill_scaffolder.py my-skill -d marketing --description "Campaign tools" --json
python scripts/skill_scaffolder.py my-skill -d product --description "User research" -o /path/
ParameterDescription
skill_name
Name for the skill (kebab-case recommended)
--domain, -d
Domain category (engineering, marketing, product, etc.)
--description
Brief description for YAML frontmatter
--version
Semantic version (default: 1.0.0)
--license
License type (default: MIT)
--category
Skill category for metadata
--output, -o
Parent directory for skill folder
--json
Output results as JSON
生成完整的Skill目录结构,包含SKILL.md模板、scripts/、references/、assets/目录,以及格式规范的YAML前置元数据。
bash
python scripts/skill_scaffolder.py my-skill --domain engineering --description "实现X功能"
python scripts/skill_scaffolder.py my-skill -d marketing --description "营销工具" --json
python scripts/skill_scaffolder.py my-skill -d product --description "用户研究" -o /path/
参数说明
skill_name
Skill名称(推荐使用短横线分隔格式)
--domain, -d
领域分类(engineering、marketing、product等)
--description
YAML前置元数据中的简要描述
--version
语义化版本(默认:1.0.0)
--license
许可证类型(默认:MIT)
--category
Skill元数据分类
--output, -o
Skill文件夹的父目录
--json
以JSON格式输出结果

2. CLAUDE.md Optimizer

2. CLAUDE.md优化工具

Analyzes a CLAUDE.md file and produces actionable optimization recommendations.
bash
python scripts/claudemd_optimizer.py CLAUDE.md
python scripts/claudemd_optimizer.py CLAUDE.md --token-limit 4000 --json
ParameterDescription
file_path
Path to the CLAUDE.md file to analyze
--token-limit
Maximum recommended token count (default: 6000)
--json
Output results as JSON
Report includes: line count, token estimate, section completeness, redundancy detection, missing sections, hierarchical loading suggestions, scored recommendations.
分析CLAUDE.md文件并提供可落地的优化建议。
bash
python scripts/claudemd_optimizer.py CLAUDE.md
python scripts/claudemd_optimizer.py CLAUDE.md --token-limit 4000 --json
参数说明
file_path
待分析的CLAUDE.md文件路径
--token-limit
建议的最大Token数量(默认:6000)
--json
以JSON格式输出结果
**报告包含:**行数统计、Token估算、章节完整性检查、冗余内容检测、缺失章节提示、分层加载建议、带评分的优化方案。

3. Context Analyzer

3. 上下文分析工具

Scans a project to estimate context window consumption by file category.
bash
python scripts/context_analyzer.py .
python scripts/context_analyzer.py /path/to/project --max-depth 4 --json
python scripts/context_analyzer.py . --context-window 200000
ParameterDescription
project_path
Path to the project directory
--max-depth
Maximum directory traversal depth (default: 5)
--context-window
Total context window size in tokens (default: 200000)
--json
Output results as JSON
Report includes: token estimates per category, percentage of context consumed, largest files, budget breakdown, reduction recommendations.

扫描项目,按文件类别估算上下文窗口消耗情况。
bash
python scripts/context_analyzer.py .
python scripts/context_analyzer.py /path/to/project --max-depth 4 --json
python scripts/context_analyzer.py . --context-window 200000
参数说明
project_path
项目目录路径
--max-depth
目录遍历的最大深度(默认:5)
--context-window
上下文窗口总Token容量(默认:200000)
--json
以JSON格式输出结果
**报告包含:**各分类的Token估算、上下文占用百分比、最大文件列表、预算分配明细、缩减建议。

Core Workflows

核心工作流

Workflow 1: CLAUDE.md Optimization

工作流1:CLAUDE.md 优化

Step 1: Audit --
python scripts/claudemd_optimizer.py CLAUDE.md
Step 2: Follow the recommended structure:
markdown
undefined
步骤1:审计 --
python scripts/claudemd_optimizer.py CLAUDE.md
步骤2:遵循推荐结构:
markdown
undefined

CLAUDE.md

CLAUDE.md

Project Purpose -- What the project is, who it serves

项目目标 -- 项目定位与服务对象

Architecture Overview -- Directory structure, key patterns

架构概览 -- 目录结构、核心模式

Development Environment -- Build commands, test commands, setup

开发环境 -- 构建命令、测试命令、环境搭建

Key Principles -- 3-7 non-obvious rules Claude must follow

核心原则 -- Claude必须遵循的3-7条非显式规则

Anti-Patterns to Avoid -- Things that look reasonable but are wrong

避坑指南 -- 看似合理但实际错误的做法

Git Workflow -- Branch strategy, commit conventions

Git工作流 -- 分支策略、提交规范


**Step 3: Apply token-saving patterns:**
- Bullet points over paragraphs (30% fewer tokens)
- Code blocks for commands (prevents misinterpretation)
- Remove generic advice Claude already knows
- Move domain details to child CLAUDE.md files

**Step 4: Set up hierarchical loading:**
project/ ├── CLAUDE.md # Global: purpose, architecture, principles ├── frontend/CLAUDE.md # Frontend-specific: React patterns, styling ├── backend/CLAUDE.md # Backend-specific: API patterns, DB conventions └── .claude/CLAUDE.md # User-specific overrides (gitignored)

**Step 5: Validate** -- `python scripts/claudemd_optimizer.py CLAUDE.md --token-limit 4000`

**步骤3:应用Token节省技巧:**
- 使用 bullet 点代替段落(减少30% Token)
- 用代码块展示命令(避免误解)
- 删除Claude已掌握的通用建议
- 将领域细节移至子CLAUDE.md文件

**步骤4:设置分层加载:**
project/ ├── CLAUDE.md # 全局:目标、架构、原则 ├── frontend/CLAUDE.md # 前端专属:React模式、样式规范 ├── backend/CLAUDE.md # 后端专属:API模式、数据库约定 └── .claude/CLAUDE.md # 用户自定义配置(已加入git忽略)

**步骤5:验证** -- `python scripts/claudemd_optimizer.py CLAUDE.md --token-limit 4000`

Workflow 2: Skill Authoring

工作流2:Skill 创作

Step 1: Scaffold --
python scripts/skill_scaffolder.py my-skill -d engineering --description "..."
Step 2: Write the SKILL.md following this order:
  1. YAML frontmatter (name, description with trigger phrases, license, metadata)
  2. Title and one-line summary
  3. Table of contents
  4. Quick Start (3-5 copy-pasteable commands)
  5. Tools Overview (each script with usage, parameters table)
  6. Workflows (step-by-step sequences combining tools and knowledge)
  7. Reference Documentation (links to references/)
  8. Quick Reference (tables, cheat sheets)
Step 3: Optimize the description for auto-discovery:
yaml
description: >-
  This skill should be used when the user asks to "analyze performance",
  "optimize queries", "profile memory", or "benchmark endpoints".
  Use for performance engineering and capacity planning.
Step 4: Build Python tools -- standard library only, argparse, --json flag, module docstring, error handling. See references/skill-authoring-guide.md.
步骤1:搭建脚手架 --
python scripts/skill_scaffolder.py my-skill -d engineering --description "..."
步骤2:按以下顺序编写SKILL.md:
  1. YAML前置元数据(名称、包含触发短语的描述、许可证、元数据)
  2. 标题与单行摘要
  3. 目录
  4. 快速开始(3-5个可直接复制粘贴的命令)
  5. 工具概览(每个脚本的用法、参数表格)
  6. 工作流(结合工具与知识的分步流程)
  7. 参考文档(指向references/的链接)
  8. 速查表(表格、 cheat sheet)
步骤3:优化描述以支持自动发现:
yaml
description: >-
  当用户要求“分析性能”、“优化查询”、“内存分析”或“端点基准测试”时,应使用本技能。
  适用于性能工程与容量规划。
步骤4:开发Python工具 -- 仅使用标准库、argparse、--json flag、模块文档字符串、错误处理。详见references/skill-authoring-guide.md

Workflow 3: Subagent Creation

工作流3:子Agent 创建

Step 1: Define a narrow scope (one thing done well).
Step 2: Create
.claude/agents/agent-name.yaml
:
yaml
---
name: security-reviewer
description: Reviews code for security vulnerabilities and compliance
model: claude-sonnet-4-20250514
allowed-tools:
  - Read
  - Glob
  - Grep
  - Bash(git diff*)
custom-instructions: |
  You are a security-focused code reviewer. For every change:
  1. Check for hardcoded secrets
  2. Identify injection vulnerabilities
  3. Verify auth patterns
  4. Flag insecure dependencies
  Output a structured report with severity levels.
---
Step 3: Configure tool access -- read-only (
Read, Glob, Grep
), read+commands (
+ Bash(npm test*)
), or write-capable (
+ Edit, Write
).
Step 4: Invoke --
/agents/security-reviewer Review the last 3 commits
See references/subagent-patterns.md for delegation patterns, memory persistence, and production recipes.
步骤1:定义窄范围职责(专注做好一件事)。
步骤2:创建
.claude/agents/agent-name.yaml
yaml
---
name: security-reviewer
description: 审查代码中的安全漏洞与合规性问题
model: claude-sonnet-4-20250514
allowed-tools:
  - Read
  - Glob
  - Grep
  - Bash(git diff*)
custom-instructions: |
  你是专注于安全的代码审查员。对于每一处变更:
  1. 检查硬编码密钥
  2. 识别注入漏洞
  3. 验证认证模式
  4. 标记不安全依赖
  输出包含严重级别的结构化报告。
---
步骤3:配置工具权限 -- 只读(
Read, Glob, Grep
)、可读可执行(
+ Bash(npm test*)
)、可写(
+ Edit, Write
)。
步骤4:调用 --
/agents/security-reviewer 审查最近3次提交
详见references/subagent-patterns.md中的委托模式、内存持久化及生产级实践方案。

Workflow 4: Hooks Setup

工作流4:Hooks 配置

Hooks run custom scripts at lifecycle events without user approval.
HookFires WhenBlocking
PreToolUse
Before tool executesYes (exit 1 blocks)
PostToolUse
After tool completesNo
Notification
Claude sends notificationNo
Stop
Claude finishes turnNo
SessionStart
Session/compact beginsNo
Configure in
.claude/settings.json
:
json
{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Edit|Write",
        "hooks": [{ "type": "command", "command": "prettier --write \"$CLAUDE_FILE_PATH\" 2>/dev/null || true" }]
      }
    ],
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [{ "type": "command", "command": "bash .claude/hooks/validate.sh" }]
      }
    ]
  }
}
See references/hooks-cookbook.md for 25+ ready-to-use recipes.
Hooks会在生命周期事件中自动运行自定义脚本,无需用户手动批准。
Hook 类型触发时机是否阻塞
PreToolUse
工具执行前是(返回1会阻塞执行)
PostToolUse
工具执行完成后
Notification
Claude发送通知时
Stop
Claude完成当前轮次交互时
SessionStart
会话/压缩模式启动时
.claude/settings.json
中配置:
json
{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Edit|Write",
        "hooks": [{ "type": "command", "command": "prettier --write \"$CLAUDE_FILE_PATH\" 2>/dev/null || true" }]
      }
    ],
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [{ "type": "command", "command": "bash .claude/hooks/validate.sh" }]
      }
    ]
  }
}
详见references/hooks-cookbook.md中的25+个即用型实践方案。

Workflow 5: Context Management

工作流5:上下文管理

Step 1: Audit --
python scripts/context_analyzer.py /path/to/project
Step 2: Apply the context budget framework:
CategoryBudgetPurpose
System prompt + CLAUDE.md5-10%Project configuration
Skill definitions5-15%Active skill content
Source code (read files)30-50%Files Claude reads
Conversation history20-30%Messages and responses
Working memory10-20%Reasoning space
Step 3: Reduce overhead:
  • Keep root CLAUDE.md under 4000 tokens
  • Use hierarchical loading (child CLAUDE.md files load on demand)
  • Avoid reading entire large files -- use line ranges
  • Use
    /compact
    proactively after completing subtasks
  • Start new sessions for unrelated tasks
步骤1:审计 --
python scripts/context_analyzer.py /path/to/project
步骤2:应用上下文预算框架:
分类预算占比用途
系统提示 + CLAUDE.md5-10%项目配置
Skill定义5-15%活跃Skill内容
源代码(读取文件)30-50%Claude读取的文件
对话历史20-30%消息与回复
工作内存10-20%推理空间
步骤3:减少开销:
  • 根目录CLAUDE.md控制在4000 Token以内
  • 使用分层加载(子CLAUDE.md文件按需加载)
  • 避免读取完整大文件——使用行范围读取
  • 完成子任务后主动使用
    /compact
    命令
  • 针对无关任务启动新会话

Workflow 6: Prompt Engineering for Claude Code

工作流6:Claude Code 提示词工程

Be specific about scope:
undefined
明确范围:
undefined

Weak: Fix the bug in the login flow

弱提示:修复登录流中的bug

Strong: Fix the auth bug in src/auth/login.ts where expired refresh tokens

强提示:修复src/auth/login.ts中过期刷新令牌导致5xx错误的认证bug。在第45行的try/catch中捕获TokenExpiredError。

cause a 500 error. Catch TokenExpiredError in the try/catch on line 45.


**Specify output format:**
Create .claude/settings.json with hooks that:
  1. Auto-format TypeScript with prettier after Edit/Write
  2. Block Bash commands containing "rm -rf"
  3. Log all tool uses to /tmp/claude-session.log

**Use checkpoints for multi-step work:**
Implement the dashboard. After each step, wait for confirmation:
  1. Create route at src/app/dashboard/page.tsx
  2. Build DashboardLayout component
  3. Add API endpoint at src/app/api/dashboard/route.ts
  4. Write tests in tests/dashboard.test.tsx

**Leverage Claude Code's strengths:** point it at existing code, ask it to follow
established patterns, give it test cases, let it search before changing.

---

**指定输出格式:**
创建.claude/settings.json配置Hooks,实现:
  1. 执行Edit/Write操作后自动用prettier格式化TypeScript代码
  2. 阻止包含"rm -rf"的Bash命令
  3. 将所有工具使用日志记录到/tmp/claude-session.log

**多步骤工作使用检查点:**
实现仪表盘功能。完成每一步后等待确认:
  1. 在src/app/dashboard/page.tsx创建路由
  2. 构建DashboardLayout组件
  3. 在src/app/api/dashboard/route.ts添加API端点
  4. 在__tests__/dashboard.test.tsx编写测试用例

**发挥Claude Code优势:** 指向现有代码、要求遵循已建立的模式、提供测试用例、先搜索再修改。

---

Advanced Techniques

高级技巧

Worktrees for Parallel Work

并行工作的工作树

/worktree feature/new-api    # Creates isolated working copy
Useful for exploring alternatives, parallel tasks, and risky refactors.
bash
git worktree add .claude/worktrees/feature-api feature/new-api
git worktree list
git worktree remove .claude/worktrees/feature-api
/worktree feature/new-api    # 创建独立的工作副本
适用于探索替代方案、并行任务及高风险重构。
bash
git worktree add .claude/worktrees/feature-api feature/new-api
git worktree list
git worktree remove .claude/worktrees/feature-api

Permission Modes

权限模式

ModeBehaviorBest For
DefaultAsks permission for writesNormal development
AllowlistAuto-approves listed toolsRepetitive workflows
YoloAuto-approves everythingTrusted automation
json
{ "permissions": { "allow": ["Read", "Glob", "Grep", "Bash(npm test*)"],
                    "deny": ["Bash(rm -rf*)", "Bash(git push*)"] } }
模式行为适用场景
默认模式写入操作需用户批准常规开发
白名单模式自动批准列表中的工具重复性工作流
Yolo模式自动批准所有操作可信自动化场景
json
{ "permissions": { "allow": ["Read", "Glob", "Grep", "Bash(npm test*)"],
                    "deny": ["Bash(rm -rf*)", "Bash(git push*)"] } }

MCP Server Integration

MCP服务器集成

Configure in
.claude/settings.json
under
mcpServers
:
ServerPurpose
server-filesystem
File access beyond project
server-github
GitHub API (issues, PRs)
server-postgres
Database queries
server-memory
Persistent key-value store
server-brave-search
Web search
server-puppeteer
Browser automation
.claude/settings.json
mcpServers
字段中配置:
服务器用途
server-filesystem
访问项目外的文件系统
server-github
GitHub API(issues、PRs)
server-postgres
数据库查询
server-memory
持久化键值存储
server-brave-search
网页搜索
server-puppeteer
浏览器自动化

Memory and Session Management

内存与会话管理

  • CLAUDE.md -- Project-level memory, loads every session
  • Session handoff -- Ask Claude to write
    .claude/session-notes.md
  • MCP memory server -- Structured persistent memory across sessions
  • /compact
    -- Summarize conversation to free context

  • CLAUDE.md -- 项目级内存,每次会话都会加载
  • 会话交接 -- 要求Claude写入
    .claude/session-notes.md
  • MCP内存服务器 -- 跨会话的结构化持久化内存
  • /compact
    -- 总结对话以释放上下文空间

Best Practices

最佳实践

Progressive Disclosure

渐进式披露

  1. Root CLAUDE.md -- Project-wide rules only (under 200 lines)
  2. Domain CLAUDE.md files --
    frontend/CLAUDE.md
    ,
    backend/CLAUDE.md
  3. Skill files -- Loaded when relevant skills trigger
  4. Reference files -- Deep knowledge loaded on explicit request
Rule: If Claude does not need it for every task, move it out of root CLAUDE.md.
  1. 根目录CLAUDE.md -- 仅包含项目全局规则(200行以内)
  2. 领域CLAUDE.md文件 --
    frontend/CLAUDE.md
    ,
    backend/CLAUDE.md
  3. Skill文件 -- 相关Skill触发时加载
  4. 参考文件 -- 深度知识仅在显式请求时加载
规则: 如果Claude并非每个任务都需要某部分内容,就将其移出根目录CLAUDE.md。

Token Budget Management

Token预算管理

  • 1 token is approximately 3.5 characters for Claude models
  • A 200-line CLAUDE.md is roughly 2000-3000 tokens
200K context window:
├── System prompt:     ~3K tokens (fixed)
├── CLAUDE.md tree:    ~5K tokens (target)
├── Active skills:     ~10K tokens (on demand)
├── Source files:      ~80K tokens (the work)
├── Conversation:      ~70K tokens (grows)
└── Headroom:          ~32K tokens (reasoning)
  • 对于Claude模型,1个Token约等于3.5个字符
  • 200行的CLAUDE.md约占200-3000个Token
20万Token上下文窗口分配:
├── 系统提示:     ~3K Token(固定)
├── CLAUDE.md树:    ~5K Token(目标值)
├── 活跃Skills:     ~10K Token(按需加载)
├── 源文件:      ~80K Token(核心工作内容)
├── 对话历史:      ~70K Token(持续增长)
└── 预留空间:      ~32K Token(推理使用)

Context Engineering

上下文工程

Include: non-obvious conventions, technology versions, test/deploy commands, architecture decisions and rationale.
Exclude: generic programming advice, language syntax Claude knows, verbose paragraphs replaceable by bullets, historical information irrelevant to current work.
Test: Ask Claude to do a common task. If it makes preventable mistakes, update CLAUDE.md. If it succeeds without reading a section, that section may be unnecessary.

需包含: 非显式约定、技术版本、测试/部署命令、架构决策及理由。
需排除: 通用编程建议、Claude已掌握的语言语法、可被bullet点替代的冗长段落、与当前工作无关的历史信息。
测试方法: 让Claude完成常见任务。如果它犯了可预防的错误,就更新CLAUDE.md。如果它无需读取某部分内容就能成功完成任务,那该部分可能是多余的。

Editor and Agent Integration

编辑器与Agent集成

Claude Code with VS Code / Cursor

Claude Code 与 VS Code / Cursor

  • VS Code: Claude Code in terminal + Copilot for inline completions
  • Cursor: Cursor Tab/Cmd+K for inline edits, Claude Code for multi-file work
  • Exclude
    .claude/
    from VS Code search:
    "search.exclude": {".claude": true}
  • VS Code:终端中使用Claude Code + Copilot实现行内补全
  • Cursor:使用Tab/Cmd+K进行行内编辑,Claude Code处理多文件工作
  • 在VS Code搜索中排除
    .claude/
    目录:
    "search.exclude": {".claude": true}

Claude Code vs Codex CLI

Claude Code vs Codex CLI

FeatureClaude CodeCodex CLI
Context awarenessCLAUDE.md hierarchySingle prompt
Tool ecosystemMCP serversFunction calling
Permission modelGranular allowlistsSandbox only
Session memoryConversation + compactStateless
SubagentsBuilt-in agent systemNot available
特性Claude CodeCodex CLI
上下文感知CLAUDE.md分层结构单一提示词
工具生态MCP服务器函数调用
权限模型细粒度白名单仅沙箱环境
会话内存对话历史+压缩无状态
子Agent内置Agent系统不支持

Programmatic Invocation

程序化调用

bash
echo "Explain this project" | claude --print
claude --print "Run tests and summarize failures"
claude --model claude-sonnet-4-20250514 --print "Quick review of last commit"

bash
echo "解释这个项目" | claude --print
claude --print "运行测试并总结失败案例"
claude --model claude-sonnet-4-20250514 --print "快速审查最近一次提交"

Reference Documentation

参考文档

DocumentPathDescription
Skill Authoring Guidereferences/skill-authoring-guide.mdComplete skill writing reference
Subagent Patternsreferences/subagent-patterns.mdAgent creation, delegation, recipes
Hooks Cookbookreferences/hooks-cookbook.md25+ practical hook recipes
文档路径说明
Skill创作指南references/skill-authoring-guide.md完整的Skill编写参考
子Agent模式references/subagent-patterns.mdAgent创建、委托模式及实践方案
Hooks实践手册references/hooks-cookbook.md25+个实用Hooks方案

Templates

模板

TemplatePathDescription
Skill Templateassets/skill-template.mdReady-to-use SKILL.md template
Agent Templateassets/agent-template.mdReady-to-use subagent definition

模板路径说明
Skill模板assets/skill-template.md即用型SKILL.md模板
Agent模板assets/agent-template.md即用型子Agent定义模板

Quick Reference Tables

速查表

Slash Commands

斜杠命令

CommandDescription
/help
Show available commands
/compact
Summarize conversation to free context
/clear
Clear conversation history
/model
Switch model mid-session
/agents
List and invoke custom agents
/permissions
View and modify tool permissions
/config
Open settings
/cost
Show token usage and cost
/doctor
Diagnose configuration issues
/init
Generate CLAUDE.md for current project
命令说明
/help
显示可用命令
/compact
总结对话以释放上下文空间
/clear
清除对话历史
/model
会话中切换模型
/agents
列出并调用自定义Agent
/permissions
查看并修改工具权限
/config
打开设置界面
/cost
显示Token使用量及成本
/doctor
诊断配置问题
/init
为当前项目生成CLAUDE.md

CLAUDE.md Loading Order

CLAUDE.md 加载顺序

  1. ~/.claude/CLAUDE.md
    -- user global, always loaded
  2. /project/CLAUDE.md
    -- project root, always loaded
  3. /project/.claude/CLAUDE.md
    -- project config, always loaded
  4. /project/subdir/CLAUDE.md
    -- subdirectory, loaded when files accessed
  1. ~/.claude/CLAUDE.md
    -- 用户全局配置始终加载
  2. /project/CLAUDE.md
    -- 项目根目录配置始终加载
  3. /project/.claude/CLAUDE.md
    -- 项目配置始终加载
  4. /project/subdir/CLAUDE.md
    -- 子目录配置,访问该目录文件时加载

Settings.json Structure

Settings.json 结构

json
{
  "permissions": { "allow": ["Tool(pattern*)"], "deny": ["Tool(pattern*)"] },
  "hooks": {
    "PreToolUse": [{ "matcher": "regex", "hooks": [{ "type": "command", "command": "script" }] }],
    "PostToolUse": [{ "matcher": "regex", "hooks": [{ "type": "command", "command": "script" }] }]
  },
  "mcpServers": { "name": { "command": "cmd", "args": [], "env": {} } }
}

Last Updated: February 2026 Version: 1.0.0 Tools: 3 Python CLI tools References: 3 deep-dive guides Templates: 2 ready-to-use templates
json
{
  "permissions": { "allow": ["Tool(pattern*)"], "deny": ["Tool(pattern*)"] },
  "hooks": {
    "PreToolUse": [{ "matcher": "regex", "hooks": [{ "type": "command", "command": "script" }] }],
    "PostToolUse": [{ "matcher": "regex", "hooks": [{ "type": "command", "command": "script" }] }]
  },
  "mcpServers": { "name": { "command": "cmd", "args": [], "env": {} } }
}

最后更新: 2026年2月 版本: 1.0.0 工具: 3个Python CLI工具 参考文档: 3份深度指南 模板: 2个即用型模板