A Paperclip adapter that integrates Gemini CLI as an autonomous AI agent runtime, analogously to the built-in Claude Code adapter.
This adapter enables Paperclip to orchestrate Google's Gemini CLI as a coding agent. It handles prompt construction, token usage reporting, and environment validation.
Gemini CLI enters headless mode automatically when spawned without a TTY (as Paperclip does), so no additional flags are required for unattended operation.
- Node.js 18 or later
- Gemini CLI installed and available on
PATH:npm install -g @google/gemini-cli
- A Gemini API key — set as
GEMINI_API_KEY(orGOOGLE_API_KEY) - A running Paperclip instance
Build the adapter:
cd /path/to/gemini-code-adapter
pnpm install # or: bun install
pnpm build # or: bun run buildRegister it with Paperclip by adding the path to ~/.paperclip/adapter-plugins.json:
["/path/to/gemini-code-adapter"]Restart Paperclip to load the adapter.
Create an agent in the Paperclip UI under Settings → Agents, selecting Gemini Code (local) as the adapter type.
| Field | Type | Default | Description |
|---|---|---|---|
cwd |
string | process cwd | Absolute working directory for the agent process |
model |
string | gemini-2.5-flash |
Model identifier |
timeoutSec |
number | 0 (no limit) |
Maximum run duration in seconds |
graceSec |
number | 20 |
SIGTERM grace period in seconds |
extraArgs |
string[] | — | Additional arguments forwarded verbatim to the CLI |
env |
object | — | Environment variables injected into the agent process |
command |
string | gemini |
Override the CLI binary name or path |
promptTemplate |
string | built-in | Handlebars-style prompt template |
gemini-2.5-flash(default — fast and balanced)gemini-2.5-progemini-2.5-flash-litegemini-2.0-flash
{
"cwd": "/path/to/project",
"model": "gemini-2.5-pro",
"timeoutSec": 600,
"graceSec": 30,
"env": {
"GEMINI_API_KEY": "AIza..."
}
}On each heartbeat, Paperclip calls the adapter's execute function. The adapter:
- Resolves the working directory and builds the runtime environment.
- Constructs a prompt from the configured template, session handoff notes, and wake context.
- Spawns Gemini CLI with
--output-format json(headless mode activates automatically). - Parses the JSON output to extract the response content and token usage.
- Returns the result to Paperclip.
Unlike Claude Code or Qwen Code, Gemini CLI does not support native session resume — each heartbeat starts a fresh context. Use the promptTemplate and Paperclip's session handoff mechanism to maintain continuity across runs.
Run the environment test from Settings → Adapters in the Paperclip UI. The test verifies:
- Working directory exists and is accessible
- Gemini CLI is on
PATHand executable - At least one API key is present (
GEMINI_API_KEYorGOOGLE_API_KEY) - A live hello-probe (
--prompt "Respond with hello") completes successfully
src/
├── index.ts # Adapter metadata and model list
├── utils.ts # Pure utility functions (also unit-tested)
└── server/
├── index.ts # Factory function (createServerAdapter)
├── execute.ts # Core execution logic
└── test.ts # Environment validation
The project works with both pnpm and Bun.
# pnpm
pnpm install # Install dependencies
pnpm build # Compile TypeScript
pnpm typecheck # Type-check without emitting
pnpm test # Run unit tests (vitest)
pnpm test:watch # Run tests in watch mode
pnpm clean # Remove dist/
# Bun
bun install # Install dependencies
bun run build # Compile TypeScript
bun run typecheck
bun run test # Run unit tests via vitest
bun test # Run unit tests via Bun's native runner
bun run cleanUnit tests cover all pure utility functions in src/utils.ts and require no external services or mocks. They run identically under both vitest and Bun's native test runner:
pnpm test # or: bun run test (vitest)
bun test # Bun native runner"Command is not executable" — Install Gemini CLI (npm install -g @google/gemini-cli) and verify which gemini resolves correctly.
"API authentication is not ready" — Set GEMINI_API_KEY in your shell environment or in the agent's env configuration field. You can obtain a key from Google AI Studio.
Agent times out — Increase timeoutSec, or test manually with gemini --output-format json --prompt "Respond with hello" to check responsiveness.
No session continuity — Gemini CLI does not support --resume. Configure a meaningful promptTemplate and rely on Paperclip's session handoff notes to carry context between heartbeats.
MIT — see LICENSE.