openclaw - 💡(How to fix) Fix Investigation: ACP ↔ Claude Code CLI stream-json adapter for subscription auth [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#60901Fetched 2026-04-08 02:45:56
View on GitHub
Comments
1
Participants
2
Timeline
2
Reactions
0
Author
Participants
Timeline (top)
commented ×1subscribed ×1

Code Example

OpenClaw → acpx → @zed-industries/claude-agent-acp → Anthropic API (直接)

---

【現状】
OpenClaw → acpx → @zed/claude-agent-acp → Anthropic APIAPIキー必須)

【提案】
OpenClaw → acpx → claude-code-acp-adapter → claude CLI (stream-json)Anthropic API
                   (npm パッケージ, 新規)    (サブスク認証OK
---

claude-code-acp-adapter/        ← スタンドアロン npm パッケージ(OpenClaw リポ外)
├── package.json
├── adapter.ts                  ← 本体(200300行)
└── tsconfig.json

---

Part 1: Claude Code CLI を子プロセスとして起動(30行)
  claude -p --input-format stream-json --output-format stream-json --verbose --permission-mode bypassPermissions

Part 2: ACP入力を読み取り、stream-jsonに変換(40行)
  session/prompt → {"type":"user","message":"..."}
  initialize → 応答返却
  cancel → プロセス kill

Part 3: Claude Code出力をACPイベントに変換(100行)
  assistant (text) → agent_message_chunk
  assistant (tool_use) → tool_call
  result → prompt response (stopReason, usage)

Part 4: ユーティリティ(30行)
  emitAcp(), classifyTool(), summarizeInput()

---

# npm パッケージとして公開した場合
acpx config set agents.claude-native.command "npx -y claude-code-acp-adapter"

# ローカルスクリプトの場合
acpx config set agents.claude-native.command "node /path/to/adapter.js"

# OpenClaw config
acp.defaultAgent: "claude-native"
RAW_BUFFERClick to expand / collapse

背景

OpenClawのACPセッションで「Claude Codeで実行して」と依頼した場合、現状は以下の経路を辿る:

OpenClaw → acpx → @zed-industries/claude-agent-acp → Anthropic API (直接)

Claude Code CLIは経由しておらず、Zed社製のACPアダプターがAnthropic APIを直接叩いている。このためClaude Codeのサブスクリプション認証は利用できない(APIキーが必要)。

提案: スタンドアロンの ACP ↔ stream-json アダプター

Claude Code CLIの --input-format stream-json / --output-format stream-json とACPプロトコルの間を変換する薄いアダプタースクリプト(1ファイル, 200〜300行) を外部 npm パッケージとして作る。OpenClaw 本体のコード変更は不要。

アーキテクチャ

【現状】
OpenClaw → acpx → @zed/claude-agent-acp → Anthropic API(APIキー必須)

【提案】
OpenClaw → acpx → claude-code-acp-adapter → claude CLI (stream-json) → Anthropic API
                   (npm パッケージ, 新規)    (サブスク認証OK)

なぜ成立するか

ACPもClaude Code stream-jsonも「stdin/stdout上のNDJSON(改行区切りJSON)」。構造が同じなので、JSONフィールド名の変換だけで繋がる:

ACP (acpx側)Claude Code stream-json
session/prompt { prompt: [{type:"text", text:"..."}] }{"type":"user","message":"..."}
session/update { sessionUpdate:"agent_message_chunk" }{"type":"assistant","message":{content:[{type:"text"}]}}
session/update { sessionUpdate:"tool_call" }{"type":"assistant","message":{content:[{type:"tool_use"}]}}
prompt response { stopReason:"end_turn" }{"type":"result","subtype":"success"}
session/request_permission⚠️ stream-json単体では非対応(後述)

ファイル構成

claude-code-acp-adapter/        ← スタンドアロン npm パッケージ(OpenClaw リポ外)
├── package.json
├── adapter.ts                  ← 本体(200〜300行)
└── tsconfig.json

adapter.ts の構成(4パート)

Part 1: Claude Code CLI を子プロセスとして起動(30行)
  claude -p --input-format stream-json --output-format stream-json --verbose --permission-mode bypassPermissions

Part 2: ACP入力を読み取り、stream-jsonに変換(40行)
  session/prompt → {"type":"user","message":"..."}
  initialize → 応答返却
  cancel → プロセス kill

Part 3: Claude Code出力をACPイベントに変換(100行)
  assistant (text) → agent_message_chunk
  assistant (tool_use) → tool_call
  result → prompt response (stopReason, usage)

Part 4: ユーティリティ(30行)
  emitAcp(), classifyTool(), summarizeInput()

登録方法(OpenClaw側の変更は config のみ)

# npm パッケージとして公開した場合
acpx config set agents.claude-native.command "npx -y claude-code-acp-adapter"

# ローカルスクリプトの場合
acpx config set agents.claude-native.command "node /path/to/adapter.js"

# OpenClaw config
acp.defaultAgent: "claude-native"

権限処理

stream-json 単体ではACPの request_permission に相当する対話型権限リクエストができない。対処法は2つ:

方法A: 事前許可で割り切る(追加工数ゼロ)

  • --permission-mode bypassPermissions または --allowedTools で事前に全許可
  • 動的な権限対話はできないが、実用上は十分なケースが多い

方法B: Claude Agent SDK の permissionHandler を使う(追加 2〜3日)

  • SDK経由で permissionHandler コールバックを実装
  • ACPの request_permission と完全互換の動的権限制御が可能
  • adapter.ts が SDK 依存になる

工数見積もり

スコープ工数
方法A(事前許可、stream-json直接)1〜2日
方法B(動的権限、Agent SDK使用)3〜5日

参考情報

注意事項

  • Anthropicが2026-04-04に発表したClaude Codeサブスク利用制限の適用範囲に依存する
  • サブプロセス起動ごとに約50Kトークン消費するという報告あり(MCP設定等の再注入コスト)

extent analysis

TL;DR

Create a standalone ACP ↔ stream-json adapter script to enable Claude Code subscription authentication.

Guidance

  1. Develop the adapter script: Create a thin adapter script (1 file, 200-300 lines) that converts between ACP protocol and Claude Code stream-json format.
  2. Implement ACP to stream-json conversion: Map ACP inputs to stream-json format, e.g., session/prompt to {"type":"user","message":"..."}.
  3. Handle Claude Code output: Convert Claude Code output to ACP events, e.g., assistant (text) to agent_message_chunk.
  4. Configure OpenClaw: Set the agents.claude-native.command config to use the adapter script, e.g., npx -y claude-code-acp-adapter.

Example

# Configure OpenClaw to use the adapter script
acpx config set agents.claude-native.command "npx -y claude-code-acp-adapter"

Notes

  • The adapter script will need to handle permission requests, either by using --permission-mode bypassPermissions or implementing a permissionHandler using the Claude Agent SDK.
  • The estimated development time for the adapter script is 1-2 days for method A (pre-authorization) or 3-5 days for method B (dynamic permissions).

Recommendation

Apply workaround by creating the standalone ACP ↔ stream-json adapter script, as it enables Claude Code subscription authentication and provides a flexible solution for handling permission requests.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - 💡(How to fix) Fix Investigation: ACP ↔ Claude Code CLI stream-json adapter for subscription auth [1 comments, 2 participants]