Codex Gemini Subagents For Claude Code
ASecurityRoutes Claude Code subagent work to Codex CLI, Gemini CLI, or Antigravity CLI per chat instead of spending Claude quota, enforced by a PreToolUse guard hook that blocks unintended Claude subagents. Claude subagents run only when the active engine (and configured fallback) has a verified quota-ceiling marker or when a task requires a connector that exists only in Claude Code on this machine, found by setup. Use when the user wants to use Codex or Gemini for Claude Code helpers or subagents, sw...
- 14 stars
- 0 votes
- 0 copies
- 0 views
- Added November 26, 2026
Works with
Security analysis
100/100Pro scans all 19 files and shows the line behind each finding
npx -y skills add mestrecs/skills --skill codex-gemini-subagents-for-claude-code --agent claude-codeAre you the author of Codex Gemini Subagents For Claude Code?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/mestrecs-codex-gemini-subagents-for-claude-code)---
name: codex-gemini-subagents-for-claude-code
description: Routes Claude Code subagent work to Codex CLI, Gemini CLI, or Antigravity CLI per chat instead of spending Claude quota, enforced by a PreToolUse guard hook that blocks unintended Claude subagents. Claude subagents run only when the active engine (and configured fallback) has a verified quota-ceiling marker or when a task requires a connector that exists only in Claude Code on this machine, found by setup. Use when the user wants to use Codex or Gemini for Claude Code helpers or subagents, switch helper engines per chat, save Claude quota, enforce subagent routing with a hook, or configure automatic fallback at quota limits.
license: MIT
compatibility: Needs Node.js 20 or newer and Claude Code (for the PreToolUse guard hook). Scripts have zero npm dependencies and run on Windows, macOS and Linux. Helper runners require at least one configured CLI (codex, gemini, or agy).
---
# Codex and Gemini Subagents for Claude Code
Run helper (subagent) tasks from Claude Code on Codex CLI, Gemini CLI, or Antigravity CLI (`agy`) instead of spending Claude quota. The choice is stored **per chat** and enforced by a `PreToolUse` guard hook so a chat configured for Codex or Gemini cannot silently spawn Claude subagents.
- The main Claude chat only **writes the request file and verifies the result**.
- The helper executes the bounded task in its own worktree and writes a short answer file.
- The guard permits recognized Claude launches with a verified quota-ceiling fallback (`CLAUDE-ONLY: ceiling`) or a configured Claude-only connector (`CLAUDE-ONLY: tool <name>` — a connector that exists only in Claude Code on this machine, found by setup), and every exception is logged for audit.
## When to use
Use this skill when:
- You want subagents in a Claude Code session to run on Codex or Gemini instead of Claude.
- You say `"use codex helpers"`, `"use gemini helpers"`, `"use claude helpers"`, or `"reconfigure"`.
- You want a hard guard hook preventing accidental Claude subagent, `fork`, named agent, `Workflow`, or `Bash` `claude -p` launches, with an audit trail for exceptions.
`scripts/` below refers to this skill's directory (for example `~/.claude/skills/codex-gemini-subagents-for-claude-code/scripts/`). Always invoke scripts with `node <skill-dir>/scripts/<name>.cjs`.
## First-run setup
On first use or when the user asks to reconfigure, run the setup interview and retain their existing answers. Full questions, defaults, and config schema are in `references/setup.md`.
1. Run `node scripts/detect.cjs` (read-only). Show the detected CLIs (`claude`, `codex`, `gemini`, `agy`), versions, login state, and detected connectors (`claude`, `codex`, `gemini`, `agy`, `claudeOnly`) in plain words for the user to confirm or correct. Give official install/sign-in instructions for any missing tool; never ask for keys or tokens.
2. Ask Round 1 and Round 2 questions (engines, default per role, opt-in vs all-chats default, fallback chain, quota ceilings and watchdog behavior, ceiling marker validity, models/effort, concurrency, shared-account share %, allowed Claude-only named agents, Claude-only connector exceptions from `connectors.claudeOnly`, audit log path).
3. Follow the finish steps in `references/setup.md` to install the restricted agent when connector exceptions are configured, save and validate `~/.engine-switch/config.json`, and set up and verify the guard hook.
Optional Codex account rotation uses `codex.accounts` in the user config. Sign in to each separate Codex home yourself using the commands in `references/setup.md`. The skill never signs in or handles credentials.
Use only accounts you are allowed to use, and follow your provider's terms of use. Rotation spreads work across your own seats; it is not a way around a provider's limits on a single account.
## Per-chat engine switch
When the user says:
- `"use codex helpers"` -> `node scripts/engine-switch.cjs --chat <session-id> helper codex "user request"`
- `"use gemini helpers"` -> `node scripts/engine-switch.cjs --chat <session-id> helper gemini "user request"`
- `"use claude helpers"` -> `node scripts/engine-switch.cjs --chat <session-id> helper claude "user request"`
Reply in one line with what the script printed. To inspect the current chat's key without changing it:
```bash
node scripts/engine-switch.cjs --chat <session-id>
```
How to find `<session-id>`: check the `session_id` passed to hooks, the current conversation/transcript folder UUID, or `~/.engine-switch/chats/`. Without a chat file, `engine-switch.cjs` falls back to `defaults.helper` in `~/.engine-switch/config.json` (used in `all-chats` mode. In `opt-in` mode an unset helper stays on `claude`).
## How to delegate a helper task
1. **Give the helper its own git worktree**:
```bash
git worktree add -b helper/<slug> ../<repo>-wt/<slug> origin/main
```
2. **Write a complete request file** and keep it, the answer, logs, and other temporary files outside the worktree. The helper cannot see your chat history, so include:
- Goal and exact scope
- Files allowed to read/modify, and what **not** to touch
- How to prove the change (exact test file or check command)
- Answer format: at most 10 lines
- Hard rules: only edit inside the assigned directory, never push directly, never `--no-verify`, never run broad test suites, never print or commit secrets or environment variables (the runners also append these rules automatically)
- For a coding task, finish the request with [the failure cases checklist](references/failure-cases.md), including for direct or fallback Claude helpers. The Codex, Gemini and Antigravity runners append it themselves, so give those runners the request body without a second copy.
3. **Run the helper in the background** and wait for completion:
```bash
# Codex (write mode: sandboxed, no network)
node scripts/run-codex.cjs <dir> <request.md> <answer.txt>
# Codex (delivery mode: network + git push enabled)
node scripts/run-codex.cjs <dir> <request.md> <answer.txt> --deliver
# Gemini / Antigravity CLI (write mode: sandboxed)
node scripts/run-gemini.cjs <dir> <request.md> <answer.txt>
# Gemini / Antigravity CLI (delivery mode: no --sandbox)
node scripts/run-gemini.cjs <dir> <request.md> <answer.txt> --deliver
```
Run **at most one Gemini helper at a time per chat** (default `gemini.maxConcurrent: 1`) so shared reviewer or parallel quota is not exhausted.
4. **Verify the result yourself**: read `answer.txt`, run `git -C <dir> diff`, and run the touched test file yourself. Treat a helper's answer as a lead, not proof.
## Write mode vs delivery mode
- **Write mode (default)**: Codex runs with `-s workspace-write` and `network_access=false` (plus `--add-dir` for a linked worktree's shared Git directory); Gemini/agy runs with `--sandbox` and Antigravity receives a temporary request file.
- **Delivery mode (`--deliver`)**: disables the network/write sandbox (`danger-full-access` for Codex, omits `--sandbox` for Gemini/agy) so a bounded delivery or PR script can push. Keep direct `git push` prohibited in the prompt; delegate delivery through a dedicated delivery script.
## Quota ceilings, fallback chain, and valid Claude exceptions
"At ceiling" means **either**:
1. `~/.engine-switch/quota-<engine>.json` (`{"windowPct", "weekPct", "at"}`, ignored if older than 15 minutes) meets or exceeds `maxWindowPct` or `maxWeekPct` (checked before start and every 60 seconds mid-run by the watchdog when `stopMidRun` is true), **or**
2. The CLI fails with a rate-limit/quota error matching `/rate.?limit|quota|429|usage limit/i`.
When that happens, the runner writes `~/.engine-switch/ceilings/<engine>.json` (valid for 30 minutes by default) and exits with **code 3**. Check quota beforehand with `--quota-only`.
For Codex with account rotation enabled, each attempt uses its own quota file and ceiling marker. The runner retries on the next eligible account in the same worktree, where any edits from the previous attempt remain. It writes the engine-level marker and exits 3 only when every configured account is at ceiling.
**Fallback chain:**
- Chat on `codex` (default fallback `["codex", "claude"]`): Codex exit 3 -> Claude helper is allowed with `CLAUDE-ONLY: ceiling`.
- Chat on `gemini` (default fallback `["codex", "claude"]`): Gemini exit 3 -> run Codex next; only if Codex also exits 3 (so **both** recent ceiling markers exist) does the hook allow Claude with `CLAUDE-ONLY: ceiling`.
**The only two valid exceptions** when the chat key is `codex` or `gemini` (searched across the entire serialized `tool_input`):
1. `CLAUDE-ONLY: ceiling` — exact line, valid only when the required recent ceiling marker(s) exist on disk.
2. For a configured Claude-only connector, call Agent or Task with `subagent_type: "claude-only-tool"` and put `CLAUDE-ONLY: tool <name>` on its own line in the prompt. A user-allow-listed named agent still uses its own name on that line.
Allowed exceptions are appended to `~/.engine-switch/claude-exceptions.jsonl`. Any other `Agent`, `Task`, `fork`, named agent not in `guard.allowAgents`, `Workflow`, or `Bash` `claude -p` / `claude --print` call is denied by the hook. See `references/guard-hook.md` and `references/engines.md` for details.
Files in this skill
- SKILL.md
- examples/engine-switch.config.json
- references/engines.md
- references/guard-hook.md
- references/setup.md
- scripts/ceiling.cjs
- scripts/cli-process.cjs
- scripts/config.cjs
- scripts/detect.cjs
- scripts/engine-switch.cjs
- scripts/hooks/engine-guard.cjs
- scripts/run-codex.cjs
- scripts/run-gemini.cjs
- scripts/test/ceiling.test.cjs
- scripts/test/config.test.cjs
- scripts/test/engine-guard.test.cjs
- scripts/test/engine-switch.test.cjs
- scripts/test/index.js
- scripts/test/runners.test.cjs
Attribution
Related skills
View all in ai-agents →Comments
Loading comments…
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.