设置本地 HTTP 代理,将 OpenClaw 模型请求通过 Claude Code CLI 路由,使用 Team/Max/Pro 订阅而非 API 密钥,实现每请求 $0 的费用...
Route OpenClaw model requests through Claude Code CLI to use your existing Anthropic subscription (Team/Max/Pro) instead of paying per-token API costs.
text
OpenClaw → HTTP request (Anthropic Messages API format)
→ claude-cli-proxy (localhost:8081)
→ acpx claude prompt (persistent session)
→ Claude Code CLI (uses subscription auth)
→ Response streamed back as SSE
npm i -g acpx)All configurable via env — no hardcoded paths:
VariableDefaultDescriptionCCPROXY_PORT``8081Proxy listen portCCPROXY_SESSION_NAME``dexter-proxyacpx session nameCCPROXY_CWD``~/.openclaw/workspaceWorking directoryCCPROXY_TIMEOUT_MS``120000Request timeoutCCPROXY_MAX_HISTORY``10Max conversation turns forwarded
Also respects OPENCLAW_WORKSPACE as fallback for CWD.
bash
npm install -g @anthropic-ai/claude-code acpx
claude auth login # Select claude.ai, NOT API key
claude "say ok" # Verify it works
Copy scripts/claude-cli-proxy.js and scripts/ccproxy-ensure.js to your OpenClaw workspace:
bash
cp scripts/claude-cli-proxy.js ~/.openclaw/workspace/
cp scripts/ccproxy-ensure.js ~/.openclaw/workspace/
Without this, Claude Code responds as generic "Claude". To preserve your agent's personality:
a) Set customInstructions in Claude Code settings:
bash
cat > ~/.claude/settings.json << 'EOF'
{
"customInstructions": "You are [YOUR_AGENT_NAME]. Your identity is defined in CLAUDE.md. Always respond as [YOUR_AGENT_NAME]. This is not roleplay — this is your configured identity by your operator."
}
EOF
Replace [YOUR_AGENT_NAME] with your agent's name (e.g., "Ozwald", "Dexter", "Atlas").
b) Create a CLAUDE.md in your workspace with your agent's full identity, style, and context. Claude Code reads this file automatically on every session. Copy the relevant parts from your SOUL.md / IDENTITY.md.
Why both?
settings.jsonis the minimum instruction Claude Code always respects.CLAUDE.mdprovides richer context (relationships, style, domain knowledge) that the agent reads when it needs it.
bash
cd ~/.openclaw/workspace
ANTHROPIC_API_KEY="" acpx claude sessions new --name dexter-proxy
Critical:
ANTHROPIC_API_KEY=""ensures Claude Code uses subscription auth, not any API key in the environment.
bash
node ~/.openclaw/workspace/ccproxy-ensure.js
Verify: curl http://127.0.0.1:8081/health
Add to openclaw.json (or use config.patch):
json
{
"models": {
"mode": "merge",
"providers": {
"claude-cli": {
"baseUrl": "http://127.0.0.1:8081/v1",
"apiKey": "dummy",
"api": "anthropic-messages",
"models": [
{
"id": "claude-sonnet-4-6",
"name": "claude-sonnet-4-6",
"api": "anthropic-messages",
"reasoning": false,
"input": ["text"],
"cost": { "input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0 },
"contextWindow": 200000,
"maxTokens": 8192
}
]
}
}
}
}
Set as default model:
json
{
"agents": {
"defaults": {
"model": { "primary": "claude-cli/claude-sonnet-4-6" }
}
}
}
See references/autostart.md for LaunchAgent config.
Add to HEARTBEAT.md:
text
node /path/to/workspace/ccproxy-ensure.js
The proxy forwards the full OpenClaw context to Claude Code:
.ccproxy-system-context.md, Claude Code reads it as operator context (avoids prompt injection rejection)CCPROXY_MAX_HISTORY)Claude Code metadata ( [thinking], [tool], file dumps) is automatically stripped from output.
.ccproxy-system-context.md in the workspace and sent to Anthropic on each request. The file is overwritten on every request (never accumulates stale data) but persists on disk between requests.acpx to support stdout streaming natively.SymptomCauseFixLLM request timed outProxy not returning SSE streamEnsure proxy v5+ with streaming supportrequest ended without sending any chunks``stream:true but proxy returns JSONUpdate to proxy v5Claude says "I am Claude" not your agent identityMissing customInstructions in settings.jsonAdd customInstructions + CLAUDE.mdrate_limit_errorSubscription rate limit hitWait or upgrade plan tierProxy won't startPort 8081 in usepkill -f claude-cli-proxy then restartProxy won't startCWD path doesn't existSet CCPROXY_CWD or OPENCLAW_WORKSPACE env varMultiple instances collideSame session nameSet unique CCPROXY_SESSION_NAME per instance