agy-codex
Invokes the OpenAI Codex CLI to execute coding tasks in a target workspace, with configurable sandbox policy, model/reasoning effort, session resumption, timeout handling, and changed-file reporting.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@agy-codex ask Codex to refactor the auth module and report changed files"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Agy Codex
Google Antigravity 原生 OpenAI Codex(GPT-6.2 Astra)协同插件
简体中文 | English
致谢并延续 GuDaStudio/codexmcp(MIT License)的核心 MCP 思路,面向 Google Antigravity 原生插件体系重新架构,提供本地
uv虚拟环境启动、Windows 原生 + WSL 双模式、/teamwork 能力路由协同 与/codex日常直调。
目录
Related MCP server: agent-mcp-hub
一、核心定位与协同架构
在多模型协作开发里,强行按「前端 / 后端目录」切分模型往往低效——真正能拉开工程质量差距的是按模型能力优势分工。
Agy Codex 将 OpenAI Codex CLI(主力模型 GPT-6.2 Astra) 作为一等公民接入 Antigravity,提供两条互补入口:
/teamwork自动按能力分工:Antigravity 负责架构规划、接口契约、UI/视觉与浏览器实机验收;命中 Codex 擅长的高逻辑密度实现、疑难根因排查、跨文件重构、测试补齐或异构 Code Review 时,自动经由轻量调度子智能体codex-worker或 MCP 工具委派给 Codex,传入专属 git worktreecd,并通过changed_files与SESSION_ID完成验收与原地返工闭环。/codex日常单对话直调:随时在任意对话输入/codex <问题或需求>,主 Agent 携带当前完整上下文直调 Codex,按意图自动切换read-only/workspace-write与推理深度,改完按需验证并保留SESSION_ID供连续追问。
flowchart LR
User["开发者 / 对话窗口"] --> Slash["/codex 日常直调\n(skills/codex)"]
User --> TW["/teamwork 总控编排\n(rules/AGENTS.md + codex-teamwork)"]
TW --> AGY["Antigravity (Gemini)\n架构 / 契约 / UI / 浏览器验收"]
TW --> Worker["codex-worker 子智能体\n(model: flash)"]
Slash --> MCP["agy-codex MCP Server\n(本地 uv .venv / asyncio.to_thread)"]
Worker --> MCP
MCP --> Mode{"运行模式"}
Mode -- "Windows 原生" --> Win["codex.exe / cmd.exe /d /c codex.cmd\nUTF-8 stdin (-) + taskkill /T /F"]
Mode -- "WSL 桥接" --> WSL["wsl.exe [-d distro] -- codex\nC:\\ / D:/ 自动转 /mnt/<drive>/..."]
Win --> CLI["OpenAI Codex CLI\n(GPT-6.2 Astra · approval_policy=never)"]
WSL --> CLI
CLI --> WT["目标工作区 / Git Worktree (cd)"]
WT --> Out["返回: agent_messages + SESSION_ID\n+ changed_files (git status --short)"]
Out -- "验收不通过 / 追问续改\n复用 SESSION_ID" --> MCP与官方 Codex MCP / 原版 codexmcp 对比
能力维度 | 官方 Codex MCP | 原版 | Agy Codex(本项目) |
Antigravity 原生插件全套资产(Plugin / Rules / Skills / Subagent / Hook) | × | × | √ |
| × | × | √ |
本地 | × | × | √ |
Windows 原生 | × | 部分( | √ |
WSL 桥接模式 + 自动 Windows → | × | × | √ |
无人值守 | × | × | √ |
GPT-6.2 Astra | × | 仅 | √ |
超时控制 + Windows 整棵子进程树强杀( | × | 仅主进程 | √ |
并发非阻塞执行( | × | 阻塞事件循环 | √ |
自动返回精简 | × | × | √ |
二、Antigravity × GPT-6.2 Astra 能力分工矩阵
基于 GPT-6.2 Astra 的核心工程特性(1.05M 上下文窗口、强数学/约束/算法求解、长周期跨文件重构与终端沙箱闭环、低误报深度 Code Review,以及缓存 token 60% 成本折扣),插件内置了以下自动路由策略:
优先委托 Codex(GPT-6.2 Astra)的 4 类高价值任务
任务类型 | 推荐 | 推荐 | 典型场景 |
1. 疑难 Bug 根因排查与测试-修复闭环 |
|
| 跨文件报错堆栈定位、并发/偶发竞态排查、给定失败单测或复现命令自主迭代至全绿 |
2. 异构模型深度 Code Review |
|
| 关键 PR / |
3. 高逻辑密度 / 严约束核心实现 |
|
| 算法与调度优化、复杂状态机、协议与解析器、并发锁/数据库事务与迁移、后端核心服务、复杂类型系统/SDK/构建脚本 |
4. 保不变量的跨文件重构与完备补测 |
|
| 严格保持外部契约不变的多文件解耦、依赖/API 迁移、覆盖边界与异常路径的单元/集成测试编写 |
留在 Antigravity 自身完成的任务
全局架构规划、接口契约定义、需求澄清、外部文档/网页检索与
/teamwork总控编排;前端视觉设计、UI/UX 交互打磨与内置浏览器子智能体实机验收;
轻量改动:单行小修、注释/文档/文案与简单配置调整(避免为低复杂度改动引入冷启动延迟与无谓消耗 Astra 配额)。
面向 GPT-6.2 Astra 的 3 条工程纪律(已固化进 rules/AGENTS.md)
边界显式化:高推理深度下若提示词范围模糊,模型容易自行脑补前置条件或越界改动;所有派单必须写清「契约不变量」「允许修改的文件范围」「禁止触碰范围」「验收测试命令」。
推理深度分级:日常局部任务优先
medium,深层根因/架构重构/安全与并发审查用high,仅极端算法或系统级难题再显式使用xhigh,兼顾速度与滑动窗口配额。返工必带
SESSION_ID:验收或 Review 打回时原地续改,既保留完整代码理解上下文,又充分复用缓存 token 折扣。
三、插件目录结构与生命周期
agy-codex/
├── plugin.json # Antigravity 原生插件清单(name / logo / suggestedPrompts)
├── mcp_config.json # Stdio MCP 配置(${PLUGIN_ROOT} 本地 uv 虚拟环境启动)
├── hooks.json # 可选 PreToolUse 路径门禁(默认 enabled: false)
├── assets/
│ └── logo.png # 高对比度双主题自适应透明插件图标(Antigravity × Codex)
├── rules/
│ └── AGENTS.md # Always-on 协作规则(纯 Markdown,无 frontmatter)
├── agents/
│ └── codex-worker.md # /teamwork 轻量调度与验收子智能体(model: flash)
├── skills/
│ ├── codex/SKILL.md # 注册 /codex 斜杠命令(日常直调)
│ └── codex-teamwork/SKILL.md # /teamwork 拆单、worktree 隔离、返工与排障 SOP
├── scripts/
│ ├── guard-codex-paths.py # hooks.json 配套 PreToolUse 路径拦截脚本
│ └── sync-plugin.ps1 # Windows 一键同步至全局插件目录并构建 .venv
├── src/codexmcp/
│ ├── __init__.py # 版本信息(0.8.0)
│ ├── cli.py # 命令行入口 codexmcp
│ └── server.py # FastMCP Server 核心实现(双模式 / UTF-8 / 超时 / git 变更)
├── tests/
│ ├── test_server.py # MCP Server 命令构建、路径转换、超时、UTF-8、changed_files 单测
│ ├── test_guard_hook.py # PreToolUse 路径门禁逻辑与 stdin/stdout 契约单测
│ └── test_plugin_bundle.py # 插件清单、MCP 配置、Hook、规则、Skill、Subagent 与图标校验
├── docs/
│ └── README_EN.md # 完整英文文档
├── pyproject.toml # 项目元数据与依赖定义
├── uv.lock # 锁定的依赖版本
└── LICENSE # MIT License(完整保留 Copyright (c) 2025 guda.studio)四、安装、鉴权与全局挂载
1. 前置依赖
Python >= 3.12、Git 与 uv
OpenAI Codex CLI:
npm install -g @openai/codex codex --version
2. Codex CLI 鉴权与主力模型配置
在你将要运行 Codex 的环境(Windows 终端,或 WSL 模式下对应的 WSL 发行版终端)中完成二选一鉴权:
方式 A(推荐):ChatGPT 订阅账号登录
codex login方式 B:API Key 环境变量
# PowerShell 示例(或写入系统环境变量) $env:OPENAI_API_KEY = "sk-..."
如需默认启用 GPT-6.2 Astra,推荐在 ~/.codex/config.toml 中配置(也可改用插件环境变量 CODEX_DEFAULT_MODEL):
model = "gpt-6.2-astra"
model_reasoning_effort = "high"3. 安装本地开发与运行依赖
git clone https://github.com/Aoike123/agy-codex.git
cd agy-codex
uv sync --group dev4. 接入 Antigravity 全局插件目录
Windows 重要说明:实测 Antigravity 在 Windows 下扫描 ~/.gemini/config/plugins/ 时会跳过 NTFS 目录联接(Junction / Symlink)。因此请使用仓库内置的一键同步脚本将源码同步为真实目录并初始化目标目录 .venv(全量同步约 1–2 秒)。
# Windows (PowerShell):同步源码并自动安装运行环境 .venv
powershell -NoProfile -ExecutionPolicy Bypass -File .\scripts\sync-plugin.ps1
# 后续仅修改了规则/文档/Skill/脚本(未变更依赖)时,毫秒级增量同步:
powershell -NoProfile -ExecutionPolicy Bypass -File .\scripts\sync-plugin.ps1 -SkipUvSyncmacOS / Linux 可直接软链或复制同步:
ln -s /path/to/agy-codex ~/.gemini/config/plugins/agy-codex接入后无需重启,打开 Antigravity 左侧 Skills & Customizations 即可看到 Agy Codex(含图标、/codex、/codex-teamwork、codex-worker、rules/AGENTS.md、hooks.json 与 agy-codex MCP Server),下一轮对话即刻生效。
五、Windows 原生与 WSL 双模式详解
1. 环境变量一览
优先级固定为:单次工具调用显式传参 > 环境变量(mcp_config.json 或系统环境) > 代码兜底默认值。
环境变量 | 默认值 | 说明 |
| 自动探测 | 自定义 Codex 路径。Windows 如 |
|
| 设为 |
| 默认发行版 | WSL 模式下通过 |
| 插件默认 | 调用未显式传 |
| 沿用 | 可选默认模型覆盖(如 |
| 沿用 CLI 默认 | 可选默认推理深度: |
|
| 单次执行超时时间(秒);超时立即清理整棵子进程树 |
|
| 仅当 |
提示:插件默认
mcp_config.json刻意不写入空字符串的CODEX_BIN/CODEX_USE_WSL/CODEX_WSL_DISTRO,确保你在操作系统环境变量中配置的值可直接继承而不会被覆盖。
2. 跨平台可靠性机制
.cmd/.bat包装脚本安全启动:Windows 原生模式下若解析到.cmd或.bat(如 npm 全局安装的codex.cmd),自动包装为COMSPEC /d /c <path>;若是.exe则直接拉起,无多余 shell 开销。UTF-8 stdin(
-)传参:Prompt 始终由独立守护线程写入子进程 UTF-8stdin并立即关闭流,命令尾部传-(新会话:exec ... -;续聊:exec ... resume <SESSION_ID> -)。彻底根除cmd.exe特殊字符(&、|、%、"、换行)破坏、中文乱码与 32KB 命令行长度上限。超时与进程树清理:Windows 使用
CREATE_NEW_PROCESS_GROUP | CREATE_NO_WINDOW启动,超时或turn.completed优雅退出超时后调用taskkill /PID <pid> /T /F彻底清掉cmd.exe/wsl.exe/node.exe子孙进程,杜绝文件占锁;POSIX 下使用start_new_session=True+os.killpg。
3. WSL 自动路径转换规则(同时作用于 --cd 与 --image)
输入路径(Windows / 混合格式) | WSL 转换结果 |
|
|
|
|
|
|
|
|
|
|
|
|
| 原样保留 |
4. mcp_config.json 双模式配置模板
{
"mcpServers": {
"agy-codex": {
"command": "uv",
"args": [
"run",
"--project",
"${PLUGIN_ROOT}",
"--no-sync",
"codexmcp"
],
"env": {
"CODEX_DEFAULT_SANDBOX": "workspace-write",
"CODEX_TIMEOUT_SECONDS": "600",
"PYTHONUTF8": "1"
}
}
}
}如需指定自定义二进制路径或固定默认模型,可在 env 中追加:
"CODEX_BIN": "C:\\Users\\YourName\\AppData\\Roaming\\npm\\codex.cmd",
"CODEX_DEFAULT_MODEL": "gpt-6.2-astra",
"CODEX_DEFAULT_REASONING_EFFORT": "high"{
"mcpServers": {
"agy-codex": {
"command": "uv",
"args": [
"run",
"--project",
"${PLUGIN_ROOT}",
"--no-sync",
"codexmcp"
],
"env": {
"CODEX_USE_WSL": "true",
"CODEX_WSL_DISTRO": "Ubuntu",
"CODEX_DEFAULT_SANDBOX": "workspace-write",
"CODEX_DEFAULT_MODEL": "gpt-6.2-astra",
"CODEX_TIMEOUT_SECONDS": "600",
"PYTHONUTF8": "1"
}
}
}
}六、MCP 工具 codex 完整接口参考
输入参数(共 12 项)
参数名 | 类型 | 必填 | 默认值 / 兜底来源 | 说明 |
|
| ✅ | — | 发送给 Codex 的任务指令(经 UTF-8 stdin 传递) |
|
| ✅ | — | 工作区或 |
|
| ❌ |
| 沙箱权限策略;调用显式传参优先级高于环境变量 |
|
| ❌ |
| 传入历史会话 ID 原地续聊 / 返工 |
|
| ❌ |
| 允许在非 Git 目录执行 |
|
| ❌ |
| 为 |
|
| ❌ |
| 附带图片路径列表(WSL 模式下自动转换路径) |
|
| ❌ |
| 模型覆盖,例如 |
|
| ❌ |
| 推理深度覆盖( |
|
| ❌ |
| 单次执行超时秒数 |
|
| ❌ |
| 透传 |
|
| ❌ |
| 指定 |
返回值结构
成功返回:
{
"success": true,
"SESSION_ID": "019a7c2e-8b4d-7000-a1b2-3c4d5e6f7890",
"agent_messages": "已完成并发队列死锁修复,并在 tests/test_queue.py 补充回归用例...",
"changed_files": [
"M src/core/queue.py",
"?? tests/test_queue.py"
],
"sandbox": "workspace-write",
"mode": "windows"
}失败或超时返回(仍保留 changed_files 与已获取到的 SESSION_ID,方便排查残留改动或续修):
{
"success": false,
"error": "Codex execution timed out after 600s.",
"changed_files": [
"M src/core/queue.py"
],
"mode": "windows",
"SESSION_ID": "019a7c2e-8b4d-7000-a1b2-3c4d5e6f7890",
"timed_out": true
}七、实战用法:/codex 与 /teamwork
1. 日常直调:/codex
触发后由当前主 Agent 直接调用 agy-codex MCP(不经子智能体转手,完整保留对话上下文):
排错分析 / Code Review(自动
read-only):/codex 分析 src/scheduler/pool.py 在高并发取消任务时为什么出现僵尸协程,先只读定位根因 /codex 对当前 git diff 做一次深度 Code Review,重点看事务边界、竞态和异常恢复代码实现 / 修复 / 重构(自动
workspace-write):/codex 修复 tests/test_parser.py 里的边界超时失败,保持对外 API 兼容并跑通单测 /codex 重构重试调度器为显式状态机,补齐异常路径单元测试多轮追问续改:
紧接着回复“按刚才的修复再补一个网络闪断重试的用例”,主 Agent 自动携带上一轮
SESSION_ID原地续改,并按需跑快速测试汇报结果。
2. /teamwork 自动协同闭环
在 /teamwork 中无需手工写提示词分配模型,插件的 rules/AGENTS.md、skills/codex-teamwork/SKILL.md 与 agents/codex-worker.md 自动串联:
架构拆单:Antigravity 制定接口契约并拆出独立工作流与 git worktree。
能力派发:UI/交互/浏览器联调由 Antigravity 与
browser完成;高逻辑核心模块、疑难 Debug、跨文件重构与补测自动派发给codex-worker(flash模型低开销调度),严格传入该任务的 worktreecd。范围核对 + 异构审查:检查
changed_files未越界,核心改动合入前可由 Codex 以sandbox="read-only"做异构模型 Code Review。独立验收 +
SESSION_ID返工:Verifier 跑真实测试;若失败,携带同一SESSION_ID与精确报错堆栈打回 Codex 原地修正直至全绿。
八、可选路径门禁 Hook(hooks.json)
默认依靠 rules/AGENTS.md 与 codex-worker 做软路由(hooks.json 中 "enabled": false)。
当某个仓库希望硬性阻止 Antigravity 直接手改特定核心目录(强制经 Codex 修改)时:
打开插件根目录的 hooks.json,将
"enabled": false改为"enabled": true(若修改的是源码仓库,记得运行.\scripts\sync-plugin.ps1 -SkipUvSync同步到全局插件目录):{ "codex-path-guard": { "enabled": true, "PreToolUse": [ { "matcher": "edit_file|write_file|replace_file_content|multi_replace_file_content|write_to_file", "hooks": [ { "type": "command", "command": "python ./scripts/guard-codex-paths.py", "timeout": 10 } ] } ] } }(可选)通过环境变量
CODEX_GUARD_DIRS自定义受保护目录列表(默认backend,server,api,migrations):支持逗号或分号分隔:
CODEX_GUARD_DIRS=core,engine;src/scheduler支持多级相对前缀(如
src/core只拦截src/core/...,不拦截frontend/core.ts)仅匹配目录段,不会误杀非受保护目录下的同名文件(例如
frontend/backend.ts放行)Windows 下自动大小写不敏感;若设为空字符串则放行所有路径
严格遵守 Antigravity
PreToolUsecamelCase 输入契约,输出{"decision": "allow"}或{"decision": "deny", "reason": "..."},异常输入安全降级放行(fail-open)。
九、排障手册与 FAQ
现象 | 原因 | 解决方法 |
Windows 下挂载 Junction 后在 Antigravity 里看不到插件 | Antigravity 目录扫描会跳过 NTFS Reparse Point | 运行 |
| 未安装 | 安装 |
WSL 下找不到工作目录或发行版不对 | 默认 WSL 发行版未装 Codex | 在 |
报错 401 / 未登录 / Token 过期 | Codex CLI 尚未鉴权 | 在对应运行环境(Windows 或 WSL)执行 |
返回 | 大规模重构或 | 单次调用传更大 |
触发 | 手动开启了 | 改用 |
多个 | 串行事件循环或共用同一目录导致冲突 | 本插件使用 |
十、开发测试、致谢与许可证
本地测试与冒烟验证
# 1. 运行全量单元测试(覆盖双模式命令构建、路径转换、超时杀进程、UTF-8、changed_files、Hook 契约与插件合规)
uv run --no-sync pytest -v
# 2. 同步最新改动至全局插件目录
powershell -NoProfile -ExecutionPolicy Bypass -File .\scripts\sync-plugin.ps1
# 3. 验证本地 MCP Server stdio JSON-RPC(initialize + tools/list)
uv run --project . --no-sync codexmcp致谢与许可证
本项目源自并致谢 GuDaStudio/codexmcp 的开源贡献,完整保留原作者版权声明与 MIT License。
Copyright (c) 2025 guda.studio
Available Tools
1 toolcodexA
Executes a non-interactive OpenAI Codex CLI session (including GPT-6.2 Astra) in a target workspace or git worktree.
Supports both Windows native execution and WSL bridging via environment variables, unattended approval policy,
session resumption (`SESSION_ID`), reasoning effort tuning, and git `changed_files` reporting.
**Best-Fit Tasks:**
- Deep root-cause debugging and closed-loop test-fix cycles.
- Cross-model code review (`sandbox="read-only"`) for concurrency, edge cases, invariants, and security.
- High-logic / high-correctness implementation (algorithms, state machines, protocols, concurrency, data/backend logic).
- Multi-file refactoring preserving strict invariants and comprehensive test coverage.
**Collaboration Best Practices:**
- Always pass `cd` pointing to the active workspace or `/teamwork` git worktree root.
- Use `sandbox="read-only"` for analysis/reviews and `sandbox="workspace-write"` for edits/fixes.
- Reuse `SESSION_ID` on rework/follow-ups to preserve context and token cache.
- Inspect `changed_files` in the response to verify scope before finalizing.
Inputs: cd (required), PROMPT (required), yolo, image, +8 more. Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 1 tool
There is only one tool, so there is no possibility of misselection or overlap with siblings. Its purpose—running a non-interactive Codex CLI session—is stated explicitly and unambiguously.
The single name `codex` is lowercase and readable, but it is a bare noun rather than a verb_noun action name like `run_codex` or `execute_codex`. With only one tool there is no internal inconsistency, just a slightly underspecified convention.
One tool is thin for a surface that spans execution, sandbox modes, session resumption, and changed-file reporting, but it plausibly matches the underlying CLI's single-command nature. It sits at the borderline of the rubric's '1-2 tools feels thin' band rather than being an extreme mismatch.
Execution, resumption, and scope verification are covered, but there is no way to list or inspect existing sessions, cancel/abort a running session, or query status—dead ends for lifecycle management. For a single-tool CLI bridge this is workable but notably gapped.
Maintenance
Related MCP Connectors
A paid remote MCP for OpenAI Codex agent coordination MCP, built to return verdicts, receipts, usage
Shared memory MCP server for Claude Code, Codex, Gemini CLI and Cursor. Cited, editable.
A paid remote MCP for OpenAI Codex context compressor, built to return verdicts, receipts, usage log
Connect ChatGPT, Claude, Cursor or VS Code to your Windows PC: files, terminal, browser, apps.
Related MCP Servers
- AlicenseBqualityBmaintenanceAn MCP bridge that lets Codex delegate long-running agent work to the Antigravity CLI, providing observable and resumable tool-based execution with project scoping.14249 PyPI17MIT
- AlicenseAqualityBmaintenanceBridges multiple CLI coding agents (Codex, Cursor, OpenCode, Claude, Antigravity) into any MCP client, enabling delegation of prompts, parallel execution, and code review workflows.668 npmMozilla Public 2.0
- AlicenseNot gradedqualityCmaintenanceEnables Antigravity/Gemini to draft structured task briefs, dispatch them to a local OpenAI Codex agent, monitor logs and git diffs, and independently review or test results with bounded rework loops. It also supports parallel worktree runs, session-scoped collaboration boards, and on-demand trace inspection.MIT
- AlicenseNot gradedqualityBmaintenanceConnects AI coding agents to a local OpenAI Codex CLI, enabling prompt execution, git diff review, live quota-aware routing, resumable background jobs, and multimodal input through MCP.2MIT