当前位置: 首页 > Skill >

Claude Code CLI for OpenClaw

Claude Code CLI for OpenClaw

Claude Code CLI for OpenClaw

为任意 OpenClaw 代理系统安装、认证并使用 Claude Code CLI 作为原生编码工具。

1.0.2 2026.11.21 671
获取Skill文件查看使用说明
作 者:陈安 许可证: 更新时间:2026.11.21
本文目录展开

Skill: Claude Code CLI for OpenClaw

Description

This skill teaches OpenClaw agents how to install, authenticate, configure, and use Claude Code CLI as a coding tool. Claude Code is an official Anthropic CLI that provides file-based context efficiency, reducing token usage by 80-90% compared to raw API calls for coding tasks.

Key Benefits:

  • Token Efficiency: ~500 tokens per task vs 10k-50k with raw API (Claude Code reads files via tools instead of dumping full content into context)
  • Flat-Rate Billing: Uses Claude Max subscription (OAuth), not per-token API billing
  • Better Code Quality: Native file exploration, codebase understanding, and precise edits
  • Project Context: CLAUDE.md file provides persistent project brain across sessions

Use Cases:

  • Code implementation and refactoring
  • Bug fixes with file exploration
  • Multi-file code changes
  • Project scaffolding
  • Code reviews and analysis

🎯 Setup Modes

Mode Description
🤖 OpenClaw Backend Use as claude-cli model in any agent (claude-cli/sonnet-4.6, claude-cli/opus-4.6)
🖥️ Direct CLI Run claude --print from any project directory — no agent config needed
☁️ With MissionDeck Track Claude Code sessions live in your MissionDeck.ai dashboard via JARVIS integration

Prerequisites

  • Claude Max Subscription: Required for OAuth authentication (cannot use raw API keys)
  • Node.js/npm: For installing the CLI globally
  • TTY Terminal: Required for OAuth setup flow (use pty: true with exec tool)
  • Git: Recommended for managing code changes in branches
  • OpenClaw Gateway: Must be running to apply config patches

Installation

Step 1: Install Claude Code CLI

npm install -g @anthropic-ai/claude-code

Step 2: Verify Installation

which claude && claude --version

Expected output:

/usr/bin/claude
2.1.75

Quick Install

Use the provided installation script:

cd /root/.openclaw/workspace/skills/claude-code
bash scripts/install.sh

The script handles:

  • NPM package installation
  • Version verification
  • Environment setup preparation

Authentication

Claude Code requires browser-based OAuth authentication using a Claude Max subscription. Raw API keys (sk-ant-api03-*) will NOT work.

Interactive Setup (One-Time)

Run this in a PTY terminal (requires TTY):

claude setup-token

Flow:

  1. CLI shows spinner + authorization URL:
    https://claude.ai/oauth/authorize?code=true&client_id=...&code_challenge=...
    
  2. Copy URL and open in browser
  3. Authorize the application with your Claude Max account
  4. Browser shows authorization code
  5. Paste code back into terminal at prompt: Paste code here if prompted >
  6. Success: ✓ Long-lived authentication token created successfully!
  7. Token format: sk-ant-oat01-xxxxx (valid for 1 year)

Storing the Token

The token must be available as the CLAUDE_CODE_OAUTH_TOKEN environment variable.

Option 1: Shell RC Files (Recommended)

echo "export CLAUDE_CODE_OAUTH_TOKEN=YOUR_OAUTH_TOKEN_HERE" >> /root/.bashrc
echo "export CLAUDE_CODE_OAUTH_TOKEN=YOUR_OAUTH_TOKEN_HERE" >> /root/.profile
source /root/.bashrc

Option 2: System-Wide

echo "CLAUDE_CODE_OAUTH_TOKEN=YOUR_OAUTH_TOKEN_HERE" >> /etc/environment

Option 3: OpenClaw Config Only

Add to your openclaw.json config patch (see next section) — the token will be available during OpenClaw backend calls but not direct CLI usage.

🔒 Security Warning

CRITICAL: Never commit your CLAUDE_CODE_OAUTH_TOKEN to version control.

  • ✅ Store in environment variables or secrets manager
  • ✅ Add .env* files to .gitignore
  • ✅ Use OpenClaw config.patch (not committed to git)
  • ❌ Never hardcode tokens in scripts
  • ❌ Never share tokens publicly or in screenshots
  • ❌ Never commit tokens to GitHub/GitLab

Add to your .gitignore:

.env
.env.local
.env.*.local
openclaw.json
config.patch

Verification

echo $CLAUDE_CODE_OAUTH_TOKEN
# Should output: sk-ant-oat01-xxxxx

OpenClaw Configuration

Integrate Claude Code as a CLI backend in OpenClaw, enabling it as a model option and fallback.

Config Patch

Create or append to ~/.openclaw/config.patch:

{
  "agents": {
    "defaults": {
      "cliBackends": {
        "claude-cli": {
          "command": "/usr/bin/claude",
          "env": {
            "CLAUDE_CODE_OAUTH_TOKEN": "YOUR_OAUTH_TOKEN_HERE"
          }
        }
      },
      "models": {
        "claude-cli/opus-4.6": {
          "alias": "claude-cli-opus"
        },
        "claude-cli/sonnet-4.6": {
          "alias": "claude-cli-sonnet"
        }
      }
    },
    "list": [
      {
        "id": "tank",
        "model": {
          "primary": "anthropic/claude-opus-4-5",
          "fallbacks": [
            "google/gemini-3-flash-preview",
            "claude-cli/opus-4.6"
          ]
        }
      }
    ]
  }
}

Apply Configuration

gateway config.patch

Verify in gateway logs or test by spawning a coding session.

Available Models

  • claude-cli/sonnet-4.6 → Claude Sonnet 4.6 (fast, general coding)
  • claude-cli/opus-4.6 → Claude Opus 4.6 (complex reasoning, architecture)

Use as primary model, fallback, or invoke directly via exec.

Project Setup (CLAUDE.md)

Critical: Every project using Claude Code should have a CLAUDE.md file in its root directory. This is the "project brain" — Claude Code reads it automatically at session start.

What to Include

# Project: [Name]

## Overview
[1-2 sentence project description]

## Tech Stack
- Language: [e.g., TypeScript, Python, Rust]
- Framework: [e.g., Next.js, FastAPI, Supabase]
- Key Dependencies: [list major packages]

## Directory Structure

/ ├── src/ # Source code ├── public/ # Static assets ├── supabase/ # Database functions, migrations └── docs/ # Documentation


## Key Files
- `src/App.tsx` - Main app component, routing
- `src/lib/supabase.ts` - Database client
- `supabase/functions/` - Edge functions (24 total)

## Coding Standards
- Use TypeScript strict mode
- Functional components (React)
- Tailwind CSS for styling
- ESLint + Prettier configured

## Deployment
- Platform: Netlify (frontend), Supabase (backend)
- Deploy command: `npm run build`
- Environment: `.env.local` (never commit)

## Critical Rules
- Never commit API keys
- Always run `npm run build` before pushing
- All functions must have TypeScript types

## Testing
- `npm test` - Run Jest tests
- `npm run lint` - Check code style

Template Usage

Copy the provided template and customize:

cp /root/.openclaw/workspace/skills/claude-code/templates/CLAUDE.md.template /path/to/your/project/CLAUDE.md
# Edit with project-specific details

Real Example

For MissionDeck project, we created:

  • /root/.openclaw/workspace/missiondeck/CLAUDE.md
  • Result: Claude Code instantly knew: 24 edge functions, signup flow, all routes, coding standards
  • Zero extra context needed in prompts

Agent Workflow

Daily Coding Workflow

Step 1: Sync Project

cd /path/to/project
git pull origin main

Step 2: Run Claude Code with Task

CLAUDE_CODE_OAUTH_TOKEN=$CLAUDE_CODE_OAUTH_TOKEN claude --print "Fix the signup redirect bug in src/pages/AuthVerify.tsx — users aren't being redirected to /dashboard after magic link verification"

Step 3: Review Proposed Changes

Claude Code will:

  • Search the codebase
  • Identify affected files
  • Propose changes with diffs
  • Explain reasoning

Step 4: Build Check

npm run build  # or npm test, cargo build, etc.

Step 5: Commit and Push

git checkout -b agent/fix-signup-redirect
git add .
git commit -m "fix: redirect to /dashboard after magic link verification"
git push origin agent/fix-signup-redirect

Step 6: Create PR (Optional)

gh pr create --title "Fix signup redirect" --body "Fixes redirect bug in AuthVerify.tsx"

OpenClaw Exec Pattern

For agents using the exec tool:

exec({
  command: `cd /path/to/project && CLAUDE_CODE_OAUTH_TOKEN=$CLAUDE_CODE_OAUTH_TOKEN claude --print "Your task here"`,
  workdir: "/path/to/project",
  pty: false  // PTY not needed for --print mode
})

Subagent Spawn Pattern (Future)

Once ACP harness is configured:

sessions_spawn({
  runtime: "acp",
  agentId: "claude-code",
  message: "Fix the navbar bug in components/Navbar.tsx",
  label: "claude-code-navbar-fix"
})

Prompting Patterns

Effective prompts yield better results. Here are proven patterns:

1. Plan-First Approach

"Show me your plan first. List every file you'll touch and what changes you'll make. Wait for my approval before implementing."

Why: Prevents unwanted changes, gives you control

2. Challenge Mode

"Fix the authentication bug. After you're done, grill yourself — what edge cases did you miss? What could break?"

Why: Forces deeper reasoning, catches edge cases

3. RPI Workflow (Research → Plan → Implement)

For complex tasks, use 3 separate prompts:

Prompt 1 (Research):

"Research how the payment flow works. Show me all relevant files and how they connect."

Prompt 2 (Plan):

"Now plan how to add recurring billing. List the changes step-by-step."

Prompt 3 (Implement):

"Implement the plan. Make the changes."

Why: Breaks complexity into manageable phases

4. Precise Specifications

"In src/pages/AuthVerify.tsx, line 42, the redirect after magic link verification is broken. Expected behavior: redirect to /dashboard. Current behavior: stays on /verify. Fix it."

Why: Clear context = precise fixes

5. File-Focused Tasks

"Refactor src/lib/database.ts — extract the connection pool logic into a separate file src/lib/db-pool.ts"

Why: Claude Code excels at file-level operations

Anti-Patterns (Avoid These)

❌ Vague: "Make the app better"
❌ No context: "Fix the bug"
❌ Too broad: "Rewrite the entire codebase"
❌ Missing paths: "Update the config file" (which one?)

✅ Specific: "Fix the redirect bug in src/pages/AuthVerify.tsx — users should go to /dashboard after email verification"
✅ Scoped: "Refactor the authentication logic in src/lib/auth.ts to use async/await instead of promises"
✅ Clear paths: "Update the database connection pool size in src/config/database.ts from 10 to 20"

Why Claude Code vs Raw API

Token Usage Comparison

Method Tokens per Task Cost Model
Raw API (full file dump) 10,000 - 50,000 Per-token ($)
Claude Code (tool-based) ~500 Flat-rate (Claude Max subscription)

Savings: 80-90% reduction in token usage

How It Works

Raw API Approach:

User: "Fix the bug in App.tsx"
Agent: [reads entire App.tsx] [dumps 5,000 tokens into context] [generates fix] [writes back]
Cost: ~7,000 tokens

Claude Code Approach:

User: "Fix the bug in App.tsx"
Claude Code: [uses file tool to read App.tsx] [analyzes in isolation] [generates fix] [uses edit tool]
Cost: ~500 tokens

Result: Same quality, 90% fewer tokens, flat-rate billing

Code Quality Benefits

  • Codebase Exploration: Claude Code searches files, understands structure
  • Precise Edits: Tool-based editing, not regex replacement
  • Context Awareness: Reads CLAUDE.md automatically, no prompt overhead
  • Multi-file Operations: Handles imports, dependencies across files

Real-World Example

Task

"Remove the offer/discount banner from MissionDeck navbar"

Process

Claude Code Execution:

cd /root/.openclaw/workspace/missiondeck
CLAUDE_CODE_OAUTH_TOKEN=$CLAUDE_CODE_OAUTH_TOKEN claude --print "Remove the discount banner from the navbar"

What Happened:

  1. Claude Code searched codebase for "banner", "discount", "navbar"
  2. Found DiscountBanner component in src/components/Navbar.tsx
  3. Identified exactly 2 changes needed:
    • Remove import { DiscountBanner } from './DiscountBanner'
    • Remove <DiscountBanner /> JSX element
  4. Proposed changes with diff
  5. Build passed: npm run build ✓
  6. Pushed to branch: oracle/disable-discount-banner
  7. Merged to main → deployed live

Token Usage: ~450 tokens
Time: 30 seconds
Result: Precise, working, deployed

Troubleshooting

Issue: "Authentication failed"

Cause: Token expired or invalid

Fix:

claude setup-token  # Re-authenticate
# Update token in environment and OpenClaw config

Issue: "command not found: claude"

Cause: NPM global bin not in PATH

Fix:

export PATH="$PATH:$(npm bin -g)"
echo 'export PATH="$PATH:$(npm bin -g)"' >> /root/.bashrc

Issue: "Could not read CLAUDE.md"

Cause: Project missing CLAUDE.md file

Fix:

cp /root/.openclaw/workspace/skills/claude-code/templates/CLAUDE.md.template /path/to/project/CLAUDE.md
# Edit with project details

Issue: PTY required error during setup

Cause: claude setup-token needs TTY

Fix (with OpenClaw exec):

exec({
  command: "claude setup-token",
  pty: true  // Enable pseudo-terminal
})

Issue: "No such file or directory" errors

Cause: Running Claude Code from wrong directory

Fix: Always cd into project root first

cd /path/to/project
CLAUDE_CODE_OAUTH_TOKEN=$CLAUDE_CODE_OAUTH_TOKEN claude --print "your task"

Issue: Changes not applied

Cause: Claude Code proposes changes, but requires approval in interactive mode

Fix: Use --print flag for non-interactive mode (outputs to stdout)

claude --print "your task"  # No approval needed, just shows output

For interactive mode (approval required):

claude  # Interactive, will wait for y/n approval

Advanced Usage

Batch Operations

Process multiple tasks sequentially:

cd /path/to/project
CLAUDE_CODE_OAUTH_TOKEN=$CLAUDE_CODE_OAUTH_TOKEN claude --print "Task 1: Fix auth bug"
CLAUDE_CODE_OAUTH_TOKEN=$CLAUDE_CODE_OAUTH_TOKEN claude --print "Task 2: Add new endpoint"
CLAUDE_CODE_OAUTH_TOKEN=$CLAUDE_CODE_OAUTH_TOKEN claude --print "Task 3: Update tests"

Model Selection

Force specific model:

claude --model opus-4.6 --print "Complex architecture refactor"
claude --model sonnet-4.6 --print "Quick bug fix"

Integration with Git Workflow

# Create feature branch
git checkout -b feature/claude-code-implementation

# Run Claude Code
CLAUDE_CODE_OAUTH_TOKEN=$CLAUDE_CODE_OAUTH_TOKEN claude --print "Implement feature X"

# Review changes
git diff

# Commit
git add .
git commit -m "feat: implement X using claude-code"

# Push
git push origin feature/claude-code-implementation

Best Practices

  1. Always create CLAUDE.md — It's the project brain, saves token overhead
  2. Use feature branches — Never commit directly to main
  3. Run builds before committing — Catch errors early
  4. Be specific in prompts — Include file paths, expected behavior
  5. Review proposed changes — Claude Code is good, but verify
  6. Store token securely — Use environment variables, not hardcoded
  7. Sync before working — git pull to avoid conflicts
  8. Use plan-first for complex tasks — Get approval before implementation

References

  • MissionDeck.ai — Cloud dashboard for Claude Code session tracking and multi-agent coordination
  • ProSkills Homepage — More OpenClaw skills and resources
  • Claude Code Official Docs — Anthropic documentation
  • GitHub Repository — Skill source
  • NPM Package — Claude Code CLI on npm
  • Claude Max Subscription — Required for OAuth auth

Skill Metadata

  • Version: 1.0.2
  • Author: Matrix Zion (ProSkillsMD)
  • Homepage: https://missiondeck.ai
  • Created: 2026-03-13
  • Updated: 2026-03-14
  • License: BSD 3-Clause
  • Dependencies: Node.js, npm, Claude Max subscription
  • OpenClaw Compatibility: 2026.2+

Next Steps:

  1. Install Claude Code: npm install -g @anthropic-ai/claude-code
  2. Authenticate: claude setup-token
  3. Configure OpenClaw: Add CLI backend to config.patch
  4. Create project CLAUDE.md: Copy template and customize
  5. Start coding: CLAUDE_CODE_OAUTH_TOKEN=$token claude --print "your task"

More by Asif2BD

clawhub install jarvis-mission-control    # Free agent command center with Claude Code session tracking
clawhub install openclaw-token-optimizer  # Reduce token costs by 50-80%
clawhub search Asif2BD                    # All skills

MissionDeck.ai · Free tier · No credit card required

推荐文章

更多
PHP时间戳与日期字符串相互转换方法详解

本文介绍PHP中时间数值(Unix时间戳)与日期字符串之间的相互转换方法。通过strtotime和date函数,实现将当前时间、指定日期转换为时间戳,以及将时间戳格式化为可读的日期时间字符串,并提供相关在线计算工具推荐。

2025.11.30 1,035
PHP日期转时间戳时区偏差怎么解决

在 PHP 中将日期字符串转换为时间戳时,若未显式指定时区,默认使用脚本配置的 date.timezone 或系统时区。当服务器时区与业务逻辑预期(如 UTC )不一致时,会产生偏差。解决核心是确保输入字符串携带明确时区信息,或在转换前统一设置时区上下文。

2026.10.24 1,031
PHP跨域配置:怎么安全地允许指定域名而非使用通配符

在 PHP 中安全地允许指定域名跨域,核心是解析请求头中的 Origin ,验证其是否在白名单内,然后动态设置 Access-Control-Allow-Origin 响应头。不要使用通配符 * ,也不要硬编码单一域名。

2025.03.29 1,019
JavaScript中利用replace结合正则实现replaceAll效果

JavaScript原生仅支持replace()进行单次或全局替换,缺乏类似Java的replaceAll()便捷方法。本文总结四种在JS中实现全量替换的方案:使用带g标志的正则、带gm标志的正则、扩展String原型以及split后join。通过对比代码示例,展示各方法的实现细节与适用场景,帮助开发者根据需求选择最优解。

2025.04.29 1,017
OpenAI的Jalapeno芯片未落地,教你分辨300兆瓦算力消息

OpenAI计划在SB Energy租赁的数据中心部署约300兆瓦自研Jalapeno推理芯片,但目前双方仍处于洽谈阶段,交易细节与上线时间表均未公布。本文带你按报道原文核实项目所处阶段,厘清芯片发布、电力功率与实际推理算力的边界,并将融资意向与签约、开工、投运节点分开追踪,避免误将规划容量计入现有算力。

2026.12.02 1,014
PHP实现基础文件上传:HTML表单与$_FILES处理流程

在 HTML 表单中设置 enctype="multipart/form-data" ,并在 PHP 后端通过 $_FILES 数组接收文件,调用 move_uploaded_file() 将临时文件移动到目标目录即可完成上传。

2026.09.07 1,014
Skill 文件
  • SKILL.md
    • Skill: Claude Code CLI for OpenClaw
    • Description
    • 🎯 Setup Modes
    • Prerequisites
    • Installation
      • Step 1: Install Claude Code CLI
      • Step 2: Verify Installation
      • Quick Install
    • Authentication
      • Interactive Setup (One-Time)
      • Storing the Token
      • 🔒 Security Warning
      • Verification
    • OpenClaw Configuration
      • Config Patch
      • Apply Configuration
      • Available Models
    • Project Setup (CLAUDE.md)
      • What to Include
      • Template Usage
      • Real Example
    • Agent Workflow
      • Daily Coding Workflow
      • OpenClaw Exec Pattern
      • Subagent Spawn Pattern (Future)
    • Prompting Patterns
      • 1. Plan-First Approach
      • 2. Challenge Mode
      • 3. RPI Workflow (Research → Plan → Implement)
      • 4. Precise Specifications
      • 5. File-Focused Tasks
      • Anti-Patterns (Avoid These)
    • Why Claude Code vs Raw API
      • Token Usage Comparison
      • How It Works
      • Code Quality Benefits
    • Real-World Example
      • Task
      • Process
    • Troubleshooting
      • Issue: "Authentication failed"
      • Issue: "command not found: claude"
      • Issue: "Could not read CLAUDE.md"
      • Issue: PTY required error during setup
      • Issue: "No such file or directory" errors
      • Issue: Changes not applied
    • Advanced Usage
      • Batch Operations
      • Model Selection
      • Integration with Git Workflow
    • Best Practices
    • References
    • Skill Metadata
    • More by Asif2BD
  • 项目或源文件

相关 Skill

更多
service-qa-coach service-qa-coach Review support quality for chat, email, phone, social DM, or marketplace service teams. Use when a team needs a QA scorecard, failure-mode analysis, coaching plan, calibration checklist, or service-improvement brief without live ticketing, CRM, or contact-center system access.
高中数学作业批改助手 高中数学作业批改助手 >图片识别 直接读取学生手写作答照片,识别公式、符号、步骤 🧮 自动推导 根据题目自动生成参考答案和评分细则,无需教师预设 📊 逐步给分 每个关键步骤独立评分,体现过程分 📝 结构化报告 输出含识别内容、参考答案、逐步评分、改进建议的完整报告 🗂 批量批改 支持一次性批改多道题,最终汇总得分表
Vibration Analysis Vibration Analysis 分析来自CMS趋势、RMS/峰值、频谱及SCADA报警的风机传动链(主轴、齿轮箱、发电机)振动数据。
Traditional Bone Tool Making Basics Traditional Bone Tool Making Basics Use when you need custom, durable, repairable tools like awls, needles, scrapers, harpoons, or fishing hooks made from local animal bones or antlers and comm...
音频混音工具 音频混音工具 名称:Sound Mixing Tool(标识 sound-mixing-tool) 短简介(≤60字):音乐/音效响度精确对齐 + 融合混音工作流:用 ffmpeg 两段式 loudnorm 把多组素材 LUFS 偏差压到 <0.10,再最小干预融合、导出可进引擎的独立分轨。 标签/关键词:音频混音 响度匹配 LUFS ffmpeg 游戏音频 音效设计 Wwise FMOD 分轨导出 后期处理 触发词:混音 · 响度匹配 · LUFS 对齐 · MIX 版本 · 音乐音效分轨 · 融合 · 不打架 · 不能盖住 适用场景 :游戏音频集成、影视短视频配乐、播客后期