CodexSaver
Make Codex cheaper without making it dumber.
中文文档

CodexSaver is an MCP tool that turns Codex into a cost-aware router.
Its current product story is intentionally narrow:
win first on readonly specialists such as explanation, search, and review
win second on bounded, verifiable patch work
keep risky judgment and final review in Codex
Lower-cost execution for tests, docs, search, and explanation work
Codex stays responsible for architecture, security, protected domains, and final review
Global-by-default Codex install, so every workspace can use the same MCP tool
Pi Agent is the default v3 worker, with automatic discovery for other local Agent Card workers
DeepSeek and other LLM providers remain available for legacy v1/v2 provider-backed delegation
One-time local provider setup in ~/.codexsaver/config.json
Optional worker-output compression for shorter, review-friendly delegated results
Verified with tests, Pi Agent routing smoke checks, historical DeepSeek calls, and end-to-end MCP launcher checks
At A Glance
CodexSaver is not trying to replace Codex.
It is trying to shrink expensive Codex work without losing engineering judgment.
Current repo-local evidence:
| Dimension |
What CodexSaver already proves |
| Cost |
v2 benchmark reached 45% to 100% estimated savings on 5 bounded tasks |
| Speed |
v2 5-task run completed successful tasks in 0.03s to 14.95s; v3 readonly swarm succeeded in 6.45s |
| Quality |
v2 bounded work packets passed verifier gates; v3 readonly swarm produced 10 findings with 0.75 quality score |
| Safety |
protected paths, allowlisted commands, sandboxed patch apply, and Codex fallback are built in |
The current shape is simple:
- v2 is the mature lane for single bounded tasks
- v3 is the orchestration lane
- the clearest proven v3 advantage today is readonly specialist orchestration
- the next proven v3 advantage is higher patch success through verified repair
Where CodexSaver Wins
CodexSaver is strongest when work is low-risk, easy to verify, and expensive for Codex but cheap for a smaller worker.
In practice, the strongest lanes are:
- code explanation
- repository scanning
- performance hinting
- docstrings and README maintenance
- bounded test generation
- small bounded refactors with explicit file scope
It is not strongest at:
- auth, security, payment, permissions
- destructive migrations
- ambiguous architecture decisions
- multi-file behavioral changes with weak verification
- anything that still needs Codex-level judgment at every step
The current product thesis is:
CodexSaver wins first on readonly specialist orchestration.
CodexSaver wins second on bounded, verifiable patch work.
Codex remains the judge for everything risky or unclear.
That ordering matches both the implementation and the benchmark data.
Why It Works
CodexSaver improves cost, speed, and quality through a small but strict split of responsibilities:
1. Lower Cost
Codex is used for judgment, not repetitive throughput work. Cheap workers handle:
- explanation
- docs
- tests
- small bounded implementation tasks
This keeps the expensive model away from routine throughput.
2. Higher Speed
When the task is decomposable, CodexSaver can parallelize specialist work:
- one specialist explains
- one specialist reviews performance
- one specialist writes docs or tests
For these tasks, total latency starts to look like:
max(single specialist runtime) + orchestration overhead
instead of:
sum(all subtask runtimes)
3. Better Quality
CodexSaver does not trust worker output blindly. It improves quality with hard boundaries:
- router decides whether the task is safe enough
- work packet limits the write scope
- sandbox applies patch in isolation
- verifier checks changed files, diff size, commands, and failures
- Codex still reviews the result
That is why CodexSaver can be cheaper without becoming a "YOLO auto-edit bot."
Core Split
Most coding sessions mix expensive thinking with cheap execution.
CodexSaver splits them on purpose:
Codex handles reasoning, ambiguity, protected domains, and approval
- a configured worker provider handles low-risk throughput work
The practical rule is:
Use the expensive model for judgment.
Use the cheaper model for volume.
Never confuse the two.
What It Feels Like
When CodexSaver is active, tool responses are not silent blobs of JSON.
They include an interaction block that makes the routing decision visible:
{
"interaction": {
"tool": "codexsaver.delegate_task",
"mode": "delegated_execution",
"headline": "CodexSaver delegated this task to the configured worker provider.",
"route_label": "[CodexSaver] route=pi_agent task_type=write_tests risk=low",
"next_step": "Review the worker result and apply it only if the patch looks safe."
}
}
Three states matter:
preview: routing preview only, no external model call
delegated_execution: delegated run completed
codex_takeover: task stayed with Codex because risk was too high or the task was ambiguous
When worker-output compression is enabled, the same interaction block includes
the active compression level so Codex can see why delegated replies are terser.
V2: Bounded Work Packets
CodexSaver v2 adds a stricter delegation lane for work that should be safe but
still deserves proof. Instead of asking the worker to "just do the task", Codex
hands it a bounded work packet:
- exact goal
- allowed files or globs
- forbidden paths
- acceptance criteria
- allowlisted commands
- maximum iterations and diff size
The worker can propose patches, but CodexSaver applies them only inside a
temporary sandbox. The patch is accepted only when it stays within policy and
the allowlisted checks pass. If the task is already satisfied, v2 returns a
preflight_satisfied=true result without spending a worker model call.
CLI example:
codexsaver work-packet \
"Create docs/v2-smoke.md with one sentence." \
--files README.md \
--allowed-file docs/v2-smoke.md \
--acceptance "docs/v2-smoke.md exists in sandbox" \
--allowed-command "python -c \"from pathlib import Path; assert Path('docs/v2-smoke.md').exists()\"" \
--workspace .
MCP tool:
codexsaver.delegate_work_packet
V3: Orchestrated Specialists
CodexSaver v3 extends v2 from a single bounded worker into a small orchestrated specialist system.
The important shift is architectural:
- Codex still owns judgment and final review
- CodexSaver plans a work graph
- readonly specialists can run in parallel
- bounded patch specialists reuse the v2 sandbox + verifier path
- patch aggregation is conservative and falls back to Codex on overlap
Current v3 status in this repo:
explainer and perf_reviewer can execute as a real readonly_swarm
- mixed graphs can execute bounded patch nodes through the v2 work-packet runtime
- overlapping
changed_files across the same patch batch return needs_codex
- v3.4 adds action-level risk policy, partial handoff, and worker participation metrics
- v3.5 adds verified patch orchestration with strict patch output, lint, and node-level repair
- v3.6 adds Agent Card discovery, weighted worker routing, and task lifecycle metadata
- v3 is implemented as a CodexSaver-owned orchestration layer, not as a fragile Codex-native subagent config dependency
Primary references:
Current benchmark status:
readonly_swarm: now live-tested through Pi Agent + DeepSeek V4 Flash on 5 repo tasks
impl + tests: exercised, but still conservative and may return needs_codex
impl + docs + explain: completed successfully in the 2026-05-14 fixture run
This means v3 is already real and testable, but still in an honest early stage rather than a full replacement for every v2 workflow.
V3.4: Action-Level Delegation And Handoff
v3.4 changes the router from "does this task contain a risky word?" to "which actions inside this task are safe to delegate?"
Examples:
schema + readonly inspection can go to Pi Agent
schema + dry-run validation plan can go to Pi Agent
schema + execute migration stays in Codex
database + destructive rebuild is split into safe prep nodes plus blocked Codex-only actions
This is what lets Pi Agent and other local workers carry more of the work without crossing the line into writes, migrations, secrets, auth, payment, or deployment execution. CodexSaver now returns a handoff object with delegated work done, blocked actions, and Codex next actions, so Codex can continue smoothly instead of starting over.
V3.5: Verified Patch Orchestration
v3.5 makes patch-producing nodes stricter before CodexSaver tries to aggregate them.
Patch workers must now return a structured result:
intent
changed_files
patch
verification_plan
rollback_notes
Before aggregation, CodexSaver runs patch lint:
- rejects empty patches
- checks that
changed_files exactly matches the diff
- rejects duplicate file writes in the same batch
- verifies the patch stays inside allowed files
- applies the patch in a sandbox before materializing it
If a patch node fails, v3.5 retries that node with repair context instead of throwing away the whole graph immediately.
Repairable patch-lint failures now get the same node-local treatment: CodexSaver can repair a bad changed_files declaration, a missing verification_plan, or a weak test_writer verification plan before returning needs_codex.
test_writer also has stronger hard checks now:
- it must change at least one
tests/test_*.py file for Python
verification_plan must mention the exact generated test file in a pytest command
rollback_notes must explain how to delete or revert the generated test file
Worker metrics now include repair_count, so benchmark reports can show whether patch success came from first-pass output or bounded repair.
V3.6: Agent Card Registry And Weighted Routing
v3.6 moves CodexSaver from hardcoded DeepSeek worker assumptions toward Pi Agent-first dynamic worker discovery.
Workers can be described by .agent-card.json files under .pi-agents/, .pi/agents/,
or ~/.codexsaver/agents:
{
"id": "pi-agent-default",
"name": "Pi Agent Worker",
"type": "pi",
"status": "online",
"capabilities": ["code_generation", "testing", "docs"],
"languages": ["python", "javascript"],
"endpoint": "local:pi-side-agents",
"command": ["pi", "--provider", "deepseek", "--model", "deepseek-v4-flash", "--mode", "json", "--no-session", "-p"],
"worktree_path": ".pi-worktrees/pi-agent",
"permissions_config": ".pi/permissions.json",
"cost_weight": 0.1
}
CodexSaver scores discovered workers instead of using a brittle if/else tree:
| Dimension |
Weight |
| Capability match |
0.40 |
| Historical success |
0.25 |
| Cost weight |
0.20 |
| Current load |
0.10 |
| Context fit |
0.05 |
The orchestration dry-run now includes the discovered Agent Cards and the selected Pi/local worker for every node. Real execution results include selected_worker and an A2A-compatible task lifecycle:
submitted -> running -> completed
-> failed
-> timed_out
CLI:
codexsaver agents list --workspace .
codexsaver agents init --workspace .
codexsaver orchestrate "Explain config loader logic and review performance" --files codexsaver/config.py --dry-run
v3.6 smoke test results: