gemini-use-claude-acp
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGemini → 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 installThis installs into the local . Subsequent runs skip this step.
@agentclientprotocol/sdknode_modules/bash
cd ~/.gemini/skills/gemini-use-claude-acp/scripts
pnpm install此操作会将安装到本地目录中。后续运行可跳过此步骤。
@agentclientprotocol/sdknode_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
环境变量
| Variable | Default | Description |
|---|---|---|
| | Model to use (applied via ACP |
| current working dir | Working directory passed to the Claude session |
| 变量名 | 默认值 | 描述 |
|---|---|---|
| | 使用的模型(通过ACP的 |
| 当前工作目录 | 传递给Claude会话的工作目录 |
How it works
工作原理
- Spawns with:
pnpm dlx @zed-industries/claude-code-acp- — auto-approves all tool calls
CLAUDE_CODE_SKIP_PERMISSIONS=1 - — prevents ANSI escape sequences in output
TERM=dumb - unset — prevents the adapter refusing to start inside another Claude session
CLAUDECODE - prepended to
~/.local/bin— ensures thePATHbinary is foundclaude
- Connects via 's
@agentclientprotocol/sdk+ClientSideConnectionndJsonStream - Sends →
initialize→newSession→unstable_setSessionModelover ACPprompt - Streams deltas to stdout as they arrive
agent_message_chunk - Terminates the subprocess once the prompt response completes
- 启动,并设置以下环境变量:
pnpm dlx @zed-industries/claude-code-acp- —— 自动批准所有工具调用
CLAUDE_CODE_SKIP_PERMISSIONS=1 - —— 防止输出中出现ANSI转义序列
TERM=dumb - 取消设置—— 避免适配器在另一个Claude会话内拒绝启动
CLAUDECODE - 将添加到
~/.local/bin最前面 —— 确保能找到PATH二进制文件claude
- 通过的
@agentclientprotocol/sdk+ClientSideConnection建立连接ndJsonStream - 通过ACP依次发送→
initialize→newSession→unstable_setSessionModel指令prompt - 当增量到达时,将其流式传输到标准输出
agent_message_chunk - 提示词响应完成后终止子进程
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:
- download failures (network, auth)
pnpm dlx - Claude auth errors — ensure CLI is authenticated
claude - environment variable being set (indicates you're running inside Claude Code; the adapter refuses to nest)
CLAUDECODE - 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认证错误——确保CLI已完成认证
claude - 环境变量已设置(表明你正在Claude Code内部运行;适配器拒绝嵌套运行)
CLAUDECODE - ACP初始化失败
脚本不会重试——请向用户显示错误信息,并建议修复根本原因后重新运行。