Skip to content

Instantly share code, notes, and snippets.

@dazuiba
Last active May 28, 2026 03:44
Show Gist options
  • Select an option

  • Save dazuiba/b0cb5d7c2bce5652f06de127828ff473 to your computer and use it in GitHub Desktop.

Select an option

Save dazuiba/b0cb5d7c2bce5652f06de127828ff473 to your computer and use it in GitHub Desktop.
claudep — Claude Code proxy wrapper via oc-cc-proxy

claude-p — Claude Code + OpenCode Go 代理

一、背景:在 Claude Code 中使用 OpenCode Go 订阅

Claude Code 默认走 Anthropic API。如果你有 OpenCode Go 订阅,可以用它来跑 Claude Code,享受 opencode-go 的极低价格和模型选择(如 deepseek-v4)。

为什么值得

  • deepseek-v4 能力持平 sonnet / gpt-5.4,它们能干的事 deepseek-v4 都能干
  • 成本是后者的 ~1/3;而 opencode-go 的价格又是官方 deepseek 的 ~1/3
  • 速度快、量大管饱,不存在 rate limit 焦虑

原理

OpenCode Go 提供了一套兼容 OpenAI/Anthropic 格式的 API。借助 oc-cc-proxy 在本地做协议转换:

Claude Code CLI  →  oc-cc-proxy (127.0.0.1:4000)  →  OpenCode Go  →  deepseek-v4

配置

1. 安装 oc-cc-proxy

git clone https://github.com/iTzFaisal/oc-cc-proxy.git
cd oc-cc-proxy
# 按项目 README 配置 opencode-go 的 API key 等
# 启动代理(默认监听 127.0.0.1:4000)

2. 创建包装脚本

将此 gist 中的 claudep 放入 PATH(推荐 ~/bin/):

mkdir -p ~/bin
cp claudep ~/bin/
chmod +x ~/bin/claudep

3. 使用

claudep "请帮我重构这个文件"

此时 Claude Code 的所有请求走 opencode-go 通道,由 deepseek-v4 处理。


二、claude-p Skill安装与使用

安装

将本 gist 的 SKILL.md 复制到对应目录:

# Claude Code
mkdir -p ~/.claude/skills/claude-p
cp SKILL.md ~/.claude/skills/claude-p/

# Codex(如果用的话)
mkdir -p ~/.codex/skills/claude-p
cp SKILL.md ~/.codex/skills/claude-p/

确保 claudep 已在 PATH 中(见上一节)。

使用

配置完成后,主会话中的 SOTA 模型通过 /claude-p 调度 deepseek-v4:

SOTA (opus-4.6 / gpt-5.5)              deepseek-v4
       │                                     │
       │  决策、审查、核心改动                  │  调查、外围执行
       │                                     │
       └─────── /claude-p ──────────────────┘

使用示例

# codex: gpt-5.5 下面

用 多个 $claude-p 调查 @src 下的模块,  你来指定重写计划. 你自己负责核心模块, 让 $claude-p 做外围工作


文件

  • claudep — 代理包装脚本
  • SKILL.md — Skill 定义,复制到 ~/.claude/skills/claude-p/~/.codex/skills/claude-p/
  • 本文件 — 配置说明
#!/usr/bin/env bash
export ANTHROPIC_BASE_URL=http://127.0.0.1:4000
export ANTHROPIC_AUTH_TOKEN=unused
export ANTHROPIC_MODEL=deepseek-v4-flash
export ANTHROPIC_DEFAULT_OPUS_MODEL=deepseek-v4-pro
export ANTHROPIC_DEFAULT_SONNET_MODEL=deepseek-v4-flash
export ANTHROPIC_DEFAULT_HAIKU_MODEL=deepseek-v4-flash
export CLAUDE_CODE_SUBAGENT_MODEL=deepseek-v4-flash
exec claude "$@" --dangerously-skip-permissions
name claude-p
description Delegate a coding task to Claude Code CLI via print mode (oai -p). Use for one-shot, non-interactive tasks: fix a bug, add a feature, review code, extract structured data. No PTY needed.

OpenCode — Print Mode (claude -p)

One-shot delegation to Claude Code CLI. Runs the task, returns the result, and exits. No interactive prompts, no tmux needed.

Basic Invocation

Use claudep instead of claude — it's a wrapper that routes to DeepSeek via the Anthropic-compatible API and enables --dangerously-skip-permissions automatically.

claudep -p "<prompt>" \
  --allowedTools "Read,Edit,Bash" \
  --max-turns 10 \
  --output-format json \
  > /tmp/claude_result.json

Parse the result:

cat /tmp/claude_result.json | python3 -c 'import json,sys; r=json.load(sys.stdin); print(r["result"])'

When to Use

  • One-shot coding tasks (fix a bug, add a feature, refactor)
  • Code review / security audit
  • CI/CD automation and scripting
  • Structured data extraction with --json-schema
  • Piped input: cat file | claude -p "analyze this"
  • Any task fully describable upfront

Print mode skips ALL interactive dialogs — no workspace trust prompt, no permission confirmations.

Key Flags

Model & Cost Control

Flag Effect
--model sonnet|opus|haiku Model selection
--effort low|medium|high|max Reasoning depth
--max-turns <n> Limit agentic loops (prevents runaway)
--max-budget-usd <n> Cap API spend in dollars (min ~$0.05)
--fallback-model haiku Auto-fallback when default model is overloaded

Permissions

Flag Effect
--allowedTools <tools> Whitelist specific tools (comma-separated)
--disallowedTools <tools> Blacklist specific tools
--dangerously-skip-permissions Auto-approve ALL tool use

Tool name syntax:

Read                   # all file reading
Edit                   # editing existing files
Write                  # creating new files
Bash                   # all shell commands
Bash(git *)            # only git commands
Bash(npm run lint:*)   # pattern matching

Output Format

Flag Effect
--output-format text Plain text (default)
--output-format json Single JSON result object
--output-format stream-json Newline-delimited streaming JSON
--json-schema <schema> Force structured JSON output matching a schema
--verbose Full turn-by-turn output
--include-partial-messages Partial chunks as they arrive (stream-json)

Context & Session

Flag Effect
--add-dir <path> Grant access to additional directories
--continue Resume most recent session in current directory
--resume <id> Resume specific session by ID
--fork-session Resume but create a new session ID
--no-session-persistence Don't save session to disk
--append-system-prompt <text> Add to default system prompt
--bare Skip hooks, plugins, MCP, CLAUDE.md (fastest, needs API key)

Output JSON Schema

{
  "type": "result",
  "subtype": "success",
  "result": "The output text...",
  "session_id": "75e2167f-...",
  "num_turns": 3,
  "total_cost_usd": 0.0787,
  "duration_ms": 10276,
  "stop_reason": "end_turn",
  "usage": { "input_tokens": 5, "output_tokens": 603 }
}

subtype values: success, error_max_turns, error_budget.

Common Patterns

Review a diff

git diff main...feature | claude -p "Review for bugs, security issues, and style." \
  --allowedTools "Read" --max-turns 1

Fix a bug

claudep -p "Fix the null pointer error in src/auth.py" \
  --allowedTools "Read,Edit" --max-turns 10 \
  --output-format json > /tmp/result.json

Structured extraction

claudep -p "List all exported functions in src/" \
  --output-format json \
  --json-schema '{"type":"object","properties":{"functions":{"type":"array","items":{"type":"string"}}},"required":["functions"]}' \
  --max-turns 5

Session resume

# Start
claudep -p "Refactor the database layer" --output-format json --max-turns 10 > /tmp/s.json

# Resume with session ID
SESSION=$(cat /tmp/s.json | python3 -c 'import json,sys; print(json.load(sys.stdin)["session_id"])')
claudep -p "Now add connection pooling" --resume "$SESSION" --max-turns 5

Pipe input

cat src/auth.py | claude -p "Review for security issues" --max-turns 1
cat src/*.py    | claude -p "Find all TODO comments"     --max-turns 1

Streaming output (real-time)

claudep -p "Explain the auth module" \
  --output-format stream-json --verbose --include-partial-messages | \
  jq -rj 'select(.type=="stream_event" and .event.delta.type?=="text_delta") | .event.delta.text'

Gotchas

  1. --max-turns is print-mode only — ignored in interactive sessions.
  2. --max-budget-usd minimum is ~$0.05 — system prompt cache creation costs this much.
  3. --bare requires ANTHROPIC_API_KEY — skips OAuth.
  4. --json-schema needs enough --max-turns — Claude reads files before producing structured output.
  5. Slash commands don't work in -p mode — describe the task in natural language instead.
  6. --continue finds the most recent session for the current working directory — must run from the same directory.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment