claude-use-gemini-acp
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseClaude → Gemini via ACP
通过ACP从Claude调用Gemini
Spawn a Gemini CLI subprocess in ACP mode, send a prompt, stream the response to stdout, and terminate cleanly. No persistent session — one prompt, one response.
以ACP模式启动Gemini CLI子进程,发送提示,将响应流式传输到标准输出,并干净地终止进程。无持久会话——一个提示对应一个响应。
When to use
使用场景
- The task requires more context than fits in Claude's window
- You want real-time Google Search grounding
- You want a second opinion from a different model
- The user says "ask Gemini", "use Gemini for this", etc.
- 任务所需上下文超出Claude的窗口容量
- 你需要实时基于谷歌搜索的支持
- 你希望从不同模型获取第二意见
- 用户要求“询问Gemini”“用Gemini处理这个”等
Setup (first use only)
首次使用设置
bash
cd ~/.claude/skills/claude-use-gemini-acp/scripts
pnpm installThis installs into the local . Subsequent runs skip this step — pnpm caches the result.
@agentclientprotocol/sdknode_modules/bash
cd ~/.claude/skills/claude-use-gemini-acp/scripts
pnpm install这会将安装到本地目录。后续运行可跳过此步骤——pnpm会缓存结果。
@agentclientprotocol/sdknode_modules/Usage
使用方法
bash
GEMINI_MODEL=gemini-2.5-pro \
TARGET_CWD=/path/to/project \
node ~/.claude/skills/claude-use-gemini-acp/scripts/gemini-delegate.mjs \
"Summarize the architecture in ARCHITECTURE.md and list the top 3 risks"The response streams to stdout as Gemini generates it. Capture it for use in your response:
bash
response=$(node ~/.claude/skills/claude-use-gemini-acp/scripts/gemini-delegate.mjs "your prompt")bash
GEMINI_MODEL=gemini-2.5-pro \
TARGET_CWD=/path/to/project \
node ~/.claude/skills/claude-use-gemini-acp/scripts/gemini-delegate.mjs \
"总结ARCHITECTURE.md中的架构并列出前3个风险"Gemini生成响应时会将其流式传输到标准输出。你可以捕获响应用于后续处理:
bash
response=$(node ~/.claude/skills/claude-use-gemini-acp/scripts/gemini-delegate.mjs "你的提示内容")Environment variables
环境变量
| Variable | Default | Description |
|---|---|---|
| | Model to use |
| | gemini-cli package version ( |
| current working dir | Working directory passed to the Gemini session |
| 变量名 | 默认值 | 描述 |
|---|---|---|
| | 使用的模型 |
| | gemini-cli包版本( |
| 当前工作目录 | 传递给Gemini会话的工作目录 |
How it works
工作原理
- Spawns
pnpm dlx @google/gemini-cli@<version> --acp --yolo --model <model> - Connects via 's
@agentclientprotocol/sdk+ClientSideConnectionndJsonStream - Sends →
initialize→newSessionover the ACP sessionprompt - Streams deltas to stdout as they arrive
agent_message_chunk - Terminates the subprocess once the prompt response completes
The flag () auto-approves all tool calls inside Gemini's session.
--yolo-y- 启动子进程
pnpm dlx @google/gemini-cli@<version> --acp --yolo --model <model> - 通过的
@agentclientprotocol/sdk+ClientSideConnection建立连接ndJsonStream - 在ACP会话上依次发送→
initialize→newSession指令prompt - 当增量到达时,将其流式传输到标准输出
agent_message_chunk - 提示响应完成后终止子进程
--yolo-yPrompt 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 Gemini to read them (it can use its filesystem tools)
- Keep prompts focused: one clear task per invocation
- For multi-step work, do multiple sequential invocations rather than one sprawling prompt
- 在提示字符串中包含所有相关上下文——这是一个无历史记录的全新会话
- 如果希望Gemini读取文件,请使用绝对路径引用(它可以使用文件系统工具)
- 提示要聚焦:每次调用对应一个明确任务
- 对于多步骤工作,多次连续调用而非使用一个冗长的提示
Error handling
错误处理
If the script exits non-zero, check stderr for:
- download failures (network, auth)
pnpm dlx - Gemini auth errors (may be needed)
gemini auth login - ACP initialization failures (version mismatch)
The script does not retry — if something fails, surface the error to the user and suggest re-running after fixing the root cause.
如果脚本非零退出,请检查标准错误输出以排查:
- 下载失败(网络、权限问题)
pnpm dlx - Gemini认证错误(可能需要执行)
gemini auth login - ACP初始化失败(版本不匹配)
脚本不会重试——如果出现故障,请向用户显示错误并建议修复根本原因后重新运行。