gemini-use-claude-acp

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Gemini → Claude via ACP

Gemini 通过 ACP 调用 Claude

Spawn a Claude Code ACP adapter subprocess, send a prompt, stream the response to stdout, and terminate cleanly. No persistent session — one prompt, one response.
启动一个Claude Code ACP适配器子进程,发送提示词,将响应流式传输到标准输出,然后干净地终止进程。无持久会话——一次提示词对应一次响应。

When to use

使用场景

  • The task requires complex multi-step agentic coding with MCP tool access
  • You want Claude's reasoning on a specific problem
  • The user says "ask Claude", "use Claude for this", etc.
  • You want a second opinion from a different model
  • 任务需要具备MCP工具访问权限的复杂多步骤智能体编码
  • 你希望Claude针对特定问题进行推理
  • 用户提出“询问Claude”、“用Claude处理这个”等需求
  • 你希望从不同模型获取第二意见

Setup (first use only)

首次使用设置

bash
cd ~/.gemini/skills/gemini-use-claude-acp/scripts
pnpm install
This installs
@agentclientprotocol/sdk
into the local
node_modules/
. Subsequent runs skip this step.
bash
cd ~/.gemini/skills/gemini-use-claude-acp/scripts
pnpm install
此操作会将
@agentclientprotocol/sdk
安装到本地
node_modules/
目录中。后续运行可跳过此步骤。

Usage

使用方法

bash
CLAUDE_MODEL=claude-sonnet-4-6 \
TARGET_CWD=/path/to/project \
node ~/.gemini/skills/gemini-use-claude-acp/scripts/claude-delegate.mjs \
  "Refactor the auth module to use JWT tokens. The code is in src/auth/."
The response streams to stdout as Claude generates it. Capture it:
bash
response=$(node ~/.gemini/skills/gemini-use-claude-acp/scripts/claude-delegate.mjs "your prompt")
bash
CLAUDE_MODEL=claude-sonnet-4-6 \
TARGET_CWD=/path/to/project \
node ~/.gemini/skills/gemini-use-claude-acp/scripts/claude-delegate.mjs \
  "重构认证模块以使用JWT令牌。代码位于src/auth/目录下。"
Claude生成响应时会将其流式传输到标准输出。你可以捕获响应:
bash
response=$(node ~/.gemini/skills/gemini-use-claude-acp/scripts/claude-delegate.mjs "你的提示词")

Environment variables

环境变量

VariableDefaultDescription
CLAUDE_MODEL
claude-sonnet-4-6
Model to use (applied via ACP
unstable_setSessionModel
)
TARGET_CWD
current working dirWorking directory passed to the Claude session
变量名默认值描述
CLAUDE_MODEL
claude-sonnet-4-6
使用的模型(通过ACP的
unstable_setSessionModel
设置)
TARGET_CWD
当前工作目录传递给Claude会话的工作目录

How it works

工作原理

  1. Spawns
    pnpm dlx @zed-industries/claude-code-acp
    with:
    • CLAUDE_CODE_SKIP_PERMISSIONS=1
      — auto-approves all tool calls
    • TERM=dumb
      — prevents ANSI escape sequences in output
    • CLAUDECODE
      unset — prevents the adapter refusing to start inside another Claude session
    • ~/.local/bin
      prepended to
      PATH
      — ensures the
      claude
      binary is found
  2. Connects via
    @agentclientprotocol/sdk
    's
    ClientSideConnection
    +
    ndJsonStream
  3. Sends
    initialize
    newSession
    unstable_setSessionModel
    prompt
    over ACP
  4. Streams
    agent_message_chunk
    deltas to stdout as they arrive
  5. Terminates the subprocess once the prompt response completes
  1. 启动
    pnpm dlx @zed-industries/claude-code-acp
    ,并设置以下环境变量:
    • CLAUDE_CODE_SKIP_PERMISSIONS=1
      —— 自动批准所有工具调用
    • TERM=dumb
      —— 防止输出中出现ANSI转义序列
    • 取消设置
      CLAUDECODE
      —— 避免适配器在另一个Claude会话内拒绝启动
    • ~/.local/bin
      添加到
      PATH
      最前面 —— 确保能找到
      claude
      二进制文件
  2. 通过
    @agentclientprotocol/sdk
    ClientSideConnection
    +
    ndJsonStream
    建立连接
  3. 通过ACP依次发送
    initialize
    newSession
    unstable_setSessionModel
    prompt
    指令
  4. agent_message_chunk
    增量到达时,将其流式传输到标准输出
  5. 提示词响应完成后终止子进程

Prompt construction tips

提示词构建技巧

  • Include all relevant context in the prompt string — this is a fresh session with no prior history
  • Reference files by absolute path if you want Claude to read/edit them
  • Keep prompts focused: one clear task per invocation
  • Claude can use its MCP tools (filesystem, shell, etc.) during the session
  • 在提示词字符串中包含所有相关上下文——这是一个无历史记录的全新会话
  • 如果希望Claude读取/编辑文件,请使用绝对路径引用文件
  • 提示词要聚焦:每次调用对应一个明确的任务
  • Claude在会话期间可以使用其MCP工具(文件系统、Shell等)

Error handling

错误处理

If the script exits non-zero, check stderr for:
  • pnpm dlx
    download failures (network, auth)
  • Claude auth errors — ensure
    claude
    CLI is authenticated
  • CLAUDECODE
    environment variable being set (indicates you're running inside Claude Code; the adapter refuses to nest)
  • ACP initialization failures
The script does not retry — surface the error to the user and suggest re-running after fixing the root cause.
如果脚本非零退出,请检查标准错误输出以排查:
  • pnpm dlx
    下载失败(网络、认证问题)
  • Claude认证错误——确保
    claude
    CLI已完成认证
  • CLAUDECODE
    环境变量已设置(表明你正在Claude Code内部运行;适配器拒绝嵌套运行)
  • ACP初始化失败
脚本不会重试——请向用户显示错误信息,并建议修复根本原因后重新运行。