ogt-cli-claude

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Claude 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 -p
bash
echo "Your prompt here" | claude -p

With specific model

指定模型调用

bash
echo "Complex task requiring Opus" | claude -p --model opus
echo "Standard task with Sonnet" | claude -p --model sonnet
Note: 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

核心选项

OptionDescription
-p, --print
Non-interactive mode, print and exit
--model <model>
Model alias:
sonnet
,
opus
, or full name
--output-format <fmt>
text
(default),
json
,
stream-json
--system-prompt <prompt>
Custom system prompt
--max-budget-usd <amount>
Spending limit for the call
--allowedTools <tools>
Restrict available tools
--dangerously-skip-permissions
Skip permission checks (sandboxed use only)
选项描述
-p, --print
非交互式模式,输出结果后退出
--model <model>
模型别名:
sonnet
opus
或完整模型名称
--output-format <fmt>
输出格式:
text
(默认)、
json
stream-json
--system-prompt <prompt>
自定义系统提示词
--max-budget-usd <amount>
调用的花费上限
--allowedTools <tools>
限制可用工具
--dangerously-skip-permissions
跳过权限检查(仅适用于沙箱环境)

Working with Files

文件操作

Claude CLI can read and write files in its working directory:
bash
undefined
Claude CLI可读取和写入其工作目录下的文件:
bash
undefined

Analyze 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"
undefined
claude -p --add-dir /other/path "Work with files in both locations"
undefined

For Sub-Agent Delegation

子Agent任务委托

When spawning Claude CLI for background work:
bash
undefined
通过Claude CLI启动后台任务时:
bash
undefined

Run 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
undefined
claude -p --output-format json "Generate a report" > result.json
undefined

Script: 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 --version
If not authenticated, run interactively once:
bash
claude
Follow the OAuth prompts to link your account.
Claude CLI默认使用OAuth认证(关联你的Anthropic账户),无需配置API密钥。
检查认证状态:
bash
claude --version
若未认证,运行一次交互式命令:
bash
claude
跟随OAuth提示完成账户关联。

Model Selection

模型选择

AliasBest For
sonnet
Fast, capable, cost-effective. Default choice.
opus
Complex reasoning, nuanced tasks, extended thinking.
别名适用场景
sonnet
快速响应、能力全面、性价比高。默认选择。
opus
复杂推理、精细化任务、深度思考场景。

Tips

使用技巧

  1. Always use
    -p
    for non-interactive/scripted use
  2. Set timeouts for long-running tasks to prevent hangs
  3. Use
    --output-format json
    when you need to parse results
  4. Pipe input for file analysis:
    cat file.py | claude -p "Review this"
  5. Working directory matters — Claude sees files relative to cwd
  1. 非交互式/脚本化场景务必使用
    -p
    参数
  2. 为长时任务设置超时,避免进程挂起
  3. 需要解析结果时使用
    --output-format json
  4. 通过管道传递文件内容进行分析:
    cat file.py | claude -p "Review this"
  5. 工作目录很重要 —— 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
    模式下无法使用