claude-code-cli — claude-code-命令行工具
v0.2.0Delegate coding tasks to Claude Code 命令行工具 via background process. Use when: building features, reviewing PRs, refactoring codebases, or iterative coding that needs file exploration. Supports interactive PTY mode for confirmations/权限s and headless pipe mode for 自动化. NOT for: simple one-liner fixes (just edit), reading code (use read 工具), or any work in ~/.OpenClaw/ workspace.
运行时依赖
安装命令
点击复制技能文档
Claude Code 技能
Delegate coding tasks to the Claude Code 命令行工具 via background process with PTY or headless pipe mode.
PTY Mode Required (Interactive)
Claude Code is an interactive terminal 应用 that needs a pseudo-terminal (PTY). Without PTY, 输出 breaks or the 代理 hangs.
Always use pty:true for interactive mode:
# ✅ Correct - with PTY exec pty:true command:"claude 'Your prompt'"
# ❌ Wrong - no PTY, 代理 may break exec command:"claude 'Your prompt'"
Two Modes
- Interactive PTY Mode
For tasks where Claude Code may ask confirmations, need 输入, or show 权限 prompts.
# Foreground (wAIts for completion) exec pty:true workdir:~/project command:"claude '添加 dark mode toggle'"
# Background (returns 会话Id) exec pty:true workdir:~/project background:true command:"claude 'Build REST API for todos'"
- Headless Pipe Mode
For 自动化, scripting, CI-like usage. Uses -p flag for non-interactive.
# Simple one-shot exec command:"claude -p 'ExplAIn what src/mAIn.ts does' --输出-格式化 json"
# With structured 输出 验证 exec command:"claude -p '列出 all 导出ed functions in src/' --输出-格式化 json --json-模式 '{\"type\":\"object\",\"properties\":{\"functions\":{\"type\":\"array\",\"items\":{\"type\":\"string\"}}}}'"
# Bud获取-c应用ed 自动化 exec command:"claude -p 'Refactor auth 模块' --max-bud获取-usd 5.00 --输出-格式化 json"
# Real-time 流ing 输出 (JSON chunks as they arrive) exec command:"claude -p 'Build a 辅助工具 function' --输出-格式化 流-json"
Exec & Process 工具 Reference Exec 工具 Parameters Parameter Type Description command string The shell command to 运行 pty boolean Required for interactive mode! Allocates a pseudo-terminal workdir string Working directory (代理 sees only this folder's 上下文) background boolean 运行 in background, returns 会话Id for 监控ing timeout number Timeout in seconds (default: 1800+ for real tasks) elevated boolean 运行 on host instead of sandbox (if allowed) Process 工具 Actions (for background 会话s) Action Description 列出 列出 all 运行ning/recent 会话s poll 检查 if 会话 is still 运行ning 记录 获取 会话 输出 (with optional off设置/limit) write 发送 raw data to stdin submit 发送 data + newline (like typing and pressing Enter) 发送-keys 发送 key 令牌s or hex bytes paste Paste text (with optional bracketed mode) kill Terminate the 会话 Key 命令行工具 Flags Flag Purpose -p Non-interactive pipe mode (headless) --输出-格式化 json Structured JSON 输出 (headless only) --输出-格式化 流-json Real-time 流ing 输出 (headless only) --恢复 [会话_ID] 恢复 by ID, or open interactive picker with optional 搜索 term --continue Continue the latest 会话 --fork-会话 创建 new 会话 ID when resuming (use with --恢复 or --continue) --from-pr [value] 恢复 会话 linked to a PR by number/URL --allowed工具s 'Bash,Read,Edit,Write,Glob,Grep' Restrict avAIlable 工具s --权限-mode acceptEdits Auto-accept edits, 预防s prompt stalls --权限-mode plan Read-only exploration mode (no writes) --dangerously-skip-权限s Full auto, no 防护rAIls (⚠️ DANGER) --max-bud获取-usd N Spend cap for 自动化 safety --json-模式 '<模式>' Structured 输出 验证 (with -p) --应用end-系统-prompt '...' 添加 to base prompt (doesn't replace) --系统-prompt '...' Replace entire 系统 prompt --代理s '' Inline dynamic sub代理 definitions --模型 <模型> Override 模型 (sonnet, hAIku, opus) --添加-dir 添加 extra directory to 上下文 权限 Modes Mode Behavior default Ask per operation acceptEdits Auto-accept file edits (recommended for background tasks) plan Read-only exploration, no writes dontAsk Auto-deny unless pre-应用roved bypass权限s Skip all 权限 prompts (⚠️ same effect as --dangerously-skip-权限s) 系统 Prompt Modes Flag Behavior --应用end-系统-prompt '...' 添加s to the default 系统 prompt — Claude Code keeps its built-in instructions --系统-prompt '...' Replaces the entire 系统 prompt — Claude Code loses all default behavior
Use --应用end-系统-prompt to 添加 上下文 or constrAInts. Use --系统-prompt only when you need full control over the prompt (rare).
Granular 工具 Restrictions
Restrict Claude Code's Bash 工具 to specific subcommands:
exec pty:true command:"claude --allowed工具s 'Bash(git:,npm:),Read,Edit,Write,Glob,Grep' 'Your task'"
会话 Continuity
追踪 and 恢复 会话s across conversations.
# 启动 a task exec pty:true workdir:~/project background:true command:"claude --权限-mode acceptEdits 'Build feature X'"
# Continue latest 会话 exec pty:true workdir:~/project command:"claude --continue"
# 恢复 specific 会话 by ID exec pty:true workdir:~/project command:"claude --恢复 abc123"
# 恢复 with interactive 搜索 (finds 会话s matching the term) exec pty:true workdir:~/project command:"claude --恢复 'auth 模块'"
# Fork when resuming (创建s new 会话 ID, preserves original) exec pty:true wor