ogt-cli-claude
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseClaude CLI Skill
Claude CLI 技能
Run Claude Code CLI to leverage Anthropic's models via OAuth authentication (no API tokens required).
运行Claude Code CLI,通过OAuth认证调用Anthropic的模型(无需API令牌)。
When to Use
适用场景
- Complex coding tasks that benefit from extended context
- Multi-file code generation or refactoring
- Research and analysis requiring deep reasoning
- Tasks that would benefit from Claude's thinking mode
- Delegating substantial work to a sub-process
- 复杂编码任务,可借助扩展上下文能力
- 多文件代码生成或重构
- 需要深度推理的研究与分析工作
- 适合使用Claude思考模式的任务
- 将大量工作委托给子进程处理
Quick Start
快速开始
One-shot query (non-interactive)
一次性查询(非交互式)
bash
echo "Your prompt here" | claude -pbash
echo "Your prompt here" | claude -pWith specific model
指定模型调用
bash
echo "Complex task requiring Opus" | claude -p --model opus
echo "Standard task with Sonnet" | claude -p --model sonnetNote: Piping the prompt via stdin is more reliable than passing it as an argument.
bash
echo "Complex task requiring Opus" | claude -p --model opus
echo "Standard task with Sonnet" | claude -p --model sonnet注意: 通过标准输入(stdin)传递提示词比作为参数传递更可靠。
With thinking/extended reasoning
启用思考/深度推理模式
bash
claude -p --model opus "Analyze this complex problem"bash
claude -p --model opus "Analyze this complex problem"JSON output (for parsing)
JSON格式输出(用于解析)
bash
claude -p --output-format json "Your prompt"bash
claude -p --output-format json "Your prompt"Stream JSON (real-time)
JSON流式输出(实时)
bash
claude -p --output-format stream-json "Your prompt"bash
claude -p --output-format stream-json "Your prompt"Key Options
核心选项
| Option | Description |
|---|---|
| Non-interactive mode, print and exit |
| Model alias: |
| |
| Custom system prompt |
| Spending limit for the call |
| Restrict available tools |
| Skip permission checks (sandboxed use only) |
| 选项 | 描述 |
|---|---|
| 非交互式模式,输出结果后退出 |
| 模型别名: |
| 输出格式: |
| 自定义系统提示词 |
| 调用的花费上限 |
| 限制可用工具 |
| 跳过权限检查(仅适用于沙箱环境) |
Working with Files
文件操作
Claude CLI can read and write files in its working directory:
bash
undefinedClaude CLI可读取和写入其工作目录下的文件:
bash
undefinedAnalyze a file
分析文件
claude -p "Review this code for bugs" < myfile.py
claude -p "Review this code for bugs" < myfile.py
Work in a specific directory
在指定目录工作
cd /path/to/project && claude -p "Summarize this codebase"
cd /path/to/project && claude -p "Summarize this codebase"
Give access to additional directories
授权访问额外目录
claude -p --add-dir /other/path "Work with files in both locations"
undefinedclaude -p --add-dir /other/path "Work with files in both locations"
undefinedFor Sub-Agent Delegation
子Agent任务委托
When spawning Claude CLI for background work:
bash
undefined通过Claude CLI启动后台任务时:
bash
undefinedRun with timeout protection
启用超时保护运行
timeout 300 claude -p --model sonnet "Complete this task..." 2>&1
timeout 300 claude -p --model sonnet "Complete this task..." 2>&1
Capture structured output
捕获结构化输出
claude -p --output-format json "Generate a report" > result.json
undefinedclaude -p --output-format json "Generate a report" > result.json
undefinedScript: Run Claude Task
脚本:运行Claude任务
Use the bundled script for reliable sub-agent execution:
bash
node {baseDir}/scripts/run-claude-task.cjs "Your task prompt" [--model sonnet|opus] [--timeout 300]The script handles:
- Timeout protection
- Error capture and formatting
- Clean output for parsing
- Exit code propagation
使用内置脚本实现可靠的子Agent执行:
bash
node {baseDir}/scripts/run-claude-task.cjs "Your task prompt" [--model sonnet|opus] [--timeout 300]该脚本支持:
- 超时保护
- 错误捕获与格式化
- 便于解析的纯净输出
- 退出码传递
Authentication
认证
Claude CLI uses OAuth by default (linked to your Anthropic account). No API key configuration needed.
To check auth status:
bash
claude --versionIf not authenticated, run interactively once:
bash
claudeFollow the OAuth prompts to link your account.
Claude CLI默认使用OAuth认证(关联你的Anthropic账户),无需配置API密钥。
检查认证状态:
bash
claude --version若未认证,运行一次交互式命令:
bash
claude跟随OAuth提示完成账户关联。
Model Selection
模型选择
| Alias | Best For |
|---|---|
| Fast, capable, cost-effective. Default choice. |
| Complex reasoning, nuanced tasks, extended thinking. |
| 别名 | 适用场景 |
|---|---|
| 快速响应、能力全面、性价比高。默认选择。 |
| 复杂推理、精细化任务、深度思考场景。 |
Tips
使用技巧
- Always use for non-interactive/scripted use
-p - Set timeouts for long-running tasks to prevent hangs
- Use when you need to parse results
--output-format json - Pipe input for file analysis:
cat file.py | claude -p "Review this" - Working directory matters — Claude sees files relative to cwd
- 非交互式/脚本化场景务必使用参数
-p - 为长时任务设置超时,避免进程挂起
- 需要解析结果时使用
--output-format json - 通过管道传递文件内容进行分析:
cat file.py | claude -p "Review this" - 工作目录很重要 —— Claude仅能看到相对于当前工作目录的文件
Limitations
局限性
- OAuth requires initial interactive setup
- Rate limits apply based on your Anthropic account tier
- Some operations may timeout on very complex tasks
- Interactive features (like file editing confirmations) don't work with
-p
- OAuth需要首次交互式配置
- 调用速率限制取决于你的Anthropic账户等级
- 部分超复杂任务可能会超时
- 交互式功能(如文件编辑确认)在模式下无法使用
-p