| name | claude-code |
| description | Claude Code CLI 完整使用指南。用于代码编写、调试、重构、测试、提交等开发任务。
支持终端、VS Code、桌面应用、Web、JetBrains 等多种环境。
|
| version | 1.0.0 |
| author | 0xCryptoZen |
| tags | ["claude","code","cli","development","ai","coding"] |
| triggers | ["claude code","claude cli","code assistant"] |
Claude Code CLI 使用指南
Claude Code 是一个强大的 AI 编码工具,支持读取代码库、编辑文件、运行命令。
安装
macOS / Linux / WSL
curl -fsSL https://claude.ai/install.sh | bash
Windows PowerShell
irm https://claude.ai/install.ps1 | iex
Homebrew (macOS)
brew install --cask claude-code
npm
npm install -g @anthropic-ai/claude-code
基本命令
| 命令 | 说明 |
|---|
claude | 启动交互式 REPL |
claude "query" | 带初始提示启动 |
claude -p "query" | 单次查询后退出 |
claude -c | 继续最近的会话 |
claude -r "session" "query" | 恢复指定会话 |
claude update | 更新到最新版本 |
常用 Flags
| Flag | 说明 |
|---|
--continue, -c | 继续最近的会话 |
--dangerously-skip-permissions | 跳过所有权限提示 |
--permission-mode plan | 计划模式(只读分析) |
--allowedTools | 允许的工具列表 |
--add-dir | 添加额外工作目录 |
--debug | 启用调试模式 |
--chrome | 启用 Chrome 浏览器集成 |
常见工作流
1. 理解新代码库
cd /path/to/project
claude
> give me an overview of this codebase
> explain the main architecture patterns
> what are the key data models?
2. 修复 Bug
claude "I'm seeing an error when I run npm test"
claude "suggest ways to fix the @ts-ignore in user.ts"
claude "update user.ts to add the null check"
3. 重构代码
claude "find deprecated API usage"
claude "refactor utils.js to use ES2024 features"
claude "run tests for the refactored code"
4. 编写测试
claude "write tests for the auth module"
claude "run the tests and fix any failures"
5. 创建 PR
claude "commit my changes with a descriptive message"
claude "create a PR for this feature"
6. 代码审查
claude "review my recent code changes for security issues"
claude "check for type errors"
Plan Mode(计划模式)
用于复杂重构或多文件修改前的计划。
claude --permission-mode plan
claude --permission-mode plan -p "Analyze the auth system"
在计划模式下:
- Claude 只执行只读操作
- 使用 Shift+Tab 切换模式
- 适合探索代码库和规划复杂变更
管道和脚本
cat logs.txt | claude -p "explain these errors"
tail -f app.log | claude -p "alert if you see anomalies"
git diff main --name-only | claude -p "review for security issues"
CLAUDE.md 配置
在项目根目录创建 CLAUDE.md 文件来设置编码规范:
# Project Guidelines
## Coding Standards
- Use TypeScript for all new files
- Follow ESLint rules
- Write tests for new features
## Architecture
- Use React functional components
- Follow the service/repository pattern
## Review Checklist
- [ ] Tests pass
- [ ] No TypeScript errors
- [ ] Code is documented
Subagents(子代理)
创建专用子代理处理特定任务:
> /agents
> use the code-reviewer subagent to check auth module
> /agents
MCP 集成
Model Context Protocol 用于连接外部数据源:
claude mcp
- Google Drive
- Jira
- Slack
- 自定义工具
最佳实践
- 明确描述任务 - 越具体越好
- 提供上下文 - 包含错误信息、文件路径
- 分步骤执行 - 复杂任务分解为小步骤
- 验证结果 - 让 Claude 运行测试验证
- 使用 CLAUDE.md - 设置项目规范
调试技巧
claude --debug "api,mcp"
claude --debug "api"
claude --debug "!statsig,!file"
故障排除
| 问题 | 解决方案 |
|---|
| 登录失败 | 运行 claude 重新登录 |
| 权限问题 | 检查 --allowedTools 设置 |
| 更新失败 | 手动运行 claude update |
| 性能慢 | 使用更具体的提示 |
资源