Skip to content

命令系统

Claude Code 的命令系统提供了强大的斜杠命令框架,通过简洁的命令接口执行复杂的开发任务。

命令概览

命令功能Wave支持主要用途
/analyze代码分析和洞察代码质量、性能分析、架构洞察
/build项目构建和部署框架检测、自动构建、部署管理
/cleanup项目清理和优化代码清理、依赖管理、性能优化
/design架构设计和规划系统设计、API设计、数据建模
/document智能文档生成API文档、用户指南、技术规范
/estimate工作量估算时间估算、资源评估、风险分析
/explain代码解释教学代码解释、概念教学、学习支持
/gitGit操作管理智能提交、分支管理、工作流
/implement功能实现开发代码实现、专家激活、质量保证
/improve代码优化和改进性能优化、重构建议、最佳实践
/load项目上下文加载项目分析、上下文建立、智能索引
/spawn任务编排协作多代理协作、工作流编排、智能调度
/task任务管理和执行任务分解、进度跟踪、团队协作
/test全面测试工作流单元测试、集成测试、E2E测试
/troubleshoot故障排除诊断问题诊断、根因分析、解决方案
/workflow工作流程管理流程设计、自动化执行、团队协作

命令架构

核心结构

每个命令都遵循统一的结构规范:

yaml
---
command: "/{command-name}"
category: "Primary classification"
purpose: "Operational objective"
wave-enabled: true|false
performance-profile: "optimization|standard|complex"
---

处理流程

基本使用

命令语法

bash
# 基本语法
/{command} [arguments] [options]

# 文件引用
/{command} @path/to/file

# 选项标志
/{command} --option1 --option2=value

# 复合使用
/{command} @src/main.js --analyze --optimize

参数类型

1. 文件路径引用 (@)

bash
# 单个文件
/analyze @src/components/UserCard.jsx

# 多个文件
/improve @src/api/ @src/utils/

# 通配符
/build @src/**/*.ts

2. 命令选项 (--)

bash
# 布尔选项
/build --watch --verbose

# 值选项
/analyze --depth=3 --format=json

# 多值选项
/improve --exclude=test,node_modules

3. 子命令 (!)

bash
# 执行前置命令
/build !npm install

# 链式命令
/deploy !build !test

Wave 系统集成

自动激活条件

Wave 系统在以下情况自动激活:

yaml
wave_activation:
  complexity_threshold: 0.7
  file_count_threshold: 20
  operation_types_threshold: 2
  
# 示例触发场景
triggers:
  - "分析整个项目架构"
  - "重构多个模块的代码"
  - "构建包含测试和部署的完整流水线"

Wave 编排过程

命令配置

全局配置

json
{
  "commands": {
    "enabled": ["build", "analyze", "improve", "design", "task"],
    "disabled": [],
    "default_options": {
      "verbose": false,
      "auto_save": true,
      "confirm_destructive": true
    },
    "wave_settings": {
      "auto_enable": true,
      "max_stages": 5,
      "timeout_per_stage": 300
    }
  }
}

命令别名

json
{
  "aliases": {
    "/b": "/build",
    "/a": "/analyze", 
    "/i": "/improve",
    "/d": "/design",
    "/t": "/task"
  }
}

使用策略

开发工作流

1. 项目初始化流程

bash
# 分析现有项目
/analyze @.

# 设计改进方案
/design "项目架构优化"

# 构建和测试
/build --test --coverage

# 任务分解
/task "将优化建议转化为具体任务"

2. 功能开发流程

bash
# 代码实现
/build @src/features/auth/

# 质量分析
/analyze @src/features/auth/ --security --performance

# 优化改进
/improve @src/features/auth/ --refactor

# 集成测试
/build --test=integration

3. 维护优化流程

bash
# 全面分析
/analyze @. --deep --report

# 识别问题
/improve @. --identify-issues

# 批量优化
/improve @src/ --auto-fix --safe-only

团队协作

代码评审辅助

bash
# 分析PR变更
/analyze @src/modified-files/ --diff --review

# 生成评审报告
/task "基于分析结果生成代码评审清单"

文档生成

bash
# API文档生成
/build --docs --api-spec

# 架构文档
/design @. --document --diagrams

性能优化

命令缓存

bash
# 启用结果缓存
/analyze @src/ --cache

# 清除缓存
/analyze --clear-cache

# 缓存状态查看
/analyze --cache-status

并行执行

bash
# 并行分析多个模块
/analyze @src/module1/ @src/module2/ --parallel

# 批量处理
/improve @src/**/*.js --batch-size=10

自定义命令

命令扩展

yaml
# custom-commands.yaml
commands:
  /test-e2e:
    base: build
    purpose: "端到端测试执行"
    options:
      - browser: [chrome, firefox, safari]
      - headless: boolean
    actions:
      - run: "npm run test:e2e"
      - generate: "test-report.html"

命令组合

bash
# 创建组合命令
/define-workflow "full-ci" = [
  "/build --clean",
  "/analyze --all --report", 
  "/improve --auto-fix",
  "/build --test --coverage",
  "/build --docs"
]

# 执行工作流
/run-workflow full-ci

调试和诊断

命令调试

bash
# 详细输出模式
/build --verbose --debug

# 执行计划预览
/build --dry-run --show-plan

# 性能分析
/analyze --profile --timing

错误处理

bash
# 错误恢复
/build --continue-on-error --backup

# 回滚操作
/build --rollback-on-failure

# 错误报告
/analyze --error-report --suggest-fixes

监控和报告

使用统计

bash
# 命令使用统计
/stats --commands --time-range=30d

# 性能指标
/stats --performance --detailed

# 成功率分析
/stats --success-rate --by-command

报告生成

bash
# 生成综合报告
/report --type=comprehensive --format=html

# 进度报告
/report --type=progress --project=current

# 质量报告
/report --type=quality --metrics=all

安全考虑

权限控制

json
{
  "command_permissions": {
    "/build": {
      "file_operations": ["read", "create"],
      "network_access": true,
      "system_commands": ["npm", "yarn", "docker"]
    },
    "/analyze": {
      "file_operations": ["read"],
      "network_access": false,
      "system_commands": []
    }
  }
}

危险操作保护

bash
# 危险操作确认
/improve --delete-unused-files --confirm

# 只读模式
/analyze --read-only --no-side-effects

# 沙盒执行
/build --sandbox --isolated

最佳实践

1. 命令选择策略

bash
# 根据任务选择合适命令
分析阶段: /analyze
设计阶段: /design  
实现阶段: /build
优化阶段: /improve
管理阶段: /task

# 避免命令滥用
不要用 /build 做分析
不要用 /analyze 做实现

2. 参数使用技巧

bash
# 明确的参数指定
/analyze @src/auth/ --security --performance

# 模糊的参数
/analyze @. --all --everything

3. Wave 系统优化

bash
# 复杂任务让 Wave 系统处理
/analyze @. --deep --comprehensive

# 简单任务直接执行
/build @single-file.js

4. 错误处理

bash
# 带有容错的执行
/build --continue-on-error --log-errors

# 增量式处理
/improve @src/ --incremental --checkpoint

深入学习

核心命令

辅助命令

高级功能

实用工具


命令系统 - 简洁的接口,强大的功能

Claude Code 使用指南