| name | codexsaver-cost-router |
| description | Route low-risk coding tasks to cheaper LLMs while keeping Codex for high-risk decisions, using MCP tools for cost-aware delegation |
| triggers | ["use codexsaver to reduce costs","delegate this task to a cheaper model","route low-risk work to deepseek","create a bounded work packet for this","orchestrate specialists for this task","set up codexsaver mcp tool","configure codexsaver worker provider","run codexsaver benchmarks"] |
CodexSaver Cost Router
Skill by ara.so — Codex Skills collection.
CodexSaver is an MCP tool that makes Codex cost-aware by routing low-risk development work (tests, docs, search, explanation) to cheaper worker LLMs while keeping Codex responsible for architecture, security, and final review. It supports DeepSeek by default with presets for OpenAI, Anthropic, Gemini, Qwen, Ollama, and LM Studio.
Core Concepts
CodexSaver operates in three modes:
- Preview Mode: Shows routing decision without executing
- V2 Bounded Work Packets: Single-task delegation with sandboxed patch application and verification
- V3 Orchestrated Specialists: Parallel readonly specialists (explainer, perf_reviewer) and mixed graphs for docs/tests/impl
Key principle: Codex handles judgment and risk, worker models handle volume and repetition.
Installation
Global MCP Tool Setup
git clone https://github.com/fendouai/CodexSaver.git
cd CodexSaver
pip install -e .
codexsaver init
Add to mcp.json:
{
"mcpServers": {
"codexsaver": {
"command": "python",
"args": ["-m", "codexsaver.mcp_server"],
"env": {}
}
}
}
Configuration
Edit ~/.codexsaver/config.json:
{
"provider": "deepseek",
"deepseek": {
"api_key_env": "DEEPSEEK_API_KEY",
"model": "deepseek-chat",
"base_url": "https://api.deepseek.com"
},
"openai": {
"api_key_env": "OPENAI_API_KEY",
"model": "gpt-4o-mini"
},
"worker_compression": {
"enabled": true,
"level": "medium"
},
"routing": {
"protected_paths": ["src/auth/", "payment/", ".env"]
Set environment variable:
export DEEPSEEK_API_KEY="your-key-here"
MCP Tools Reference
1. codexsaver.delegate_task
Route a task to the worker model with automatic risk assessment.
Parameters:
task_description (required): Task to delegate
files (optional): List of file paths for context
mode (optional): preview or execute (default: execute)
Example call from Codex:
{
"tool": "codexsaver.delegate_task",
"arguments": {
"task_description": "Write docstrings for all public functions",
"files": ["src/utils.py"],
"mode": "execute"
}
}
Response structure:
{
"interaction": {
"tool": "codexsaver.delegate_task",
"mode": "delegated_execution",
"headline": "CodexSaver delegated this task to DeepSeek",
"route_label": "[CodexSaver] route=deepseek task_type=write_docs risk=low",
"next_step": "Review the worker result and apply if safe"
},
"result": "Delegated task output...",
"cost_savings": "45%",
"provider": "deepseek"
}
2. codexsaver.delegate_work_packet
V2: Execute bounded work with sandbox verification.
Parameters:
goal (required): Clear task goal
files (optional): Context files
allowed_files (required): Globs for writable files
forbidden_paths (optional): Protected paths
acceptance_criteria (required): Success conditions
allowed_commands (required): Verification commands
max_iterations (optional): Default 3
max_diff_lines (optional): Default 500
Example:
{
"tool": "codexsaver.delegate_work_packet",
"arguments": {
"goal": "Add type hints to config loader",
"files": ["codexsaver/config.py"],
"allowed_files": ["codexsaver/config.py"],
"forbidden_paths": ["codexsaver/auth/"],
"acceptance_criteria": "All public functions have type hints",
"allowed_commands": ["mypy codexsaver/config.py"],
"max_iterations": 3,
"max_diff_lines": 200
}
}
3. codexsaver.orchestrate
V3: Orchestrate specialists for complex tasks.
Parameters:
task_description (required): High-level task
files (optional): Context files
mode (optional): preview or execute
Example:
{
"tool": "codexsaver.orchestrate",
"arguments": {
"task_description": "Explain config module and review performance",
"files": ["codexsaver/config.py"],
"mode": "execute"
}
}
Response for readonly_swarm:
{
"status": "success",
"graph_type": "readonly_swarm",
"findings": 10,
"quality_score": 0.75,
"latency_seconds": 6.45,
"cost_savings": "52%",
"results": {
"explainer": "Config module loads from ~/.codexsaver/config.json...",
"perf_reviewer": "No blocking I/O, caching recommended..."
}
}
CLI Commands
Initialize Configuration
codexsaver init
Creates ~/.codexsaver/config.json with DeepSeek defaults.
Preview Routing Decision
codexsaver preview "Write unit tests for auth module" --files src/auth.py
Shows routing decision without executing.
Execute Work Packet
codexsaver work-packet \
"Add docstrings to public functions" \
--files src/utils.py \
--allowed-file src/utils.py \
--acceptance "All functions have docstrings" \
--allowed-command "python -m pydoc src.utils" \
--workspace .
Orchestrate Specialists
codexsaver orchestrate "Explain installer flow and review performance" \
--files codexsaver/install.py
codexsaver orchestrate "Document API and explain usage patterns" \
--files codexsaver/api.py
codexsaver orchestrate "Implement login and add tests" \
--files src/auth.py \
--dry-run
Run Single Specialist
codexsaver specialist explainer "Explain this module" \
--files codexsaver/router.py
codexsaver specialist perf_reviewer "Review performance" \
--files codexsaver/delegate.py
Install Project Guidance
codexsaver superpower install --profile basic --workspace .
codexsaver superpower install --profile full --workspace .
Python API
Direct Delegation
from codexsaver.delegate import delegate_task
result = delegate_task(
task_description="Write docstrings for utils module",
files=["src/utils.py"],
mode="execute"
)
print(result["interaction"]["route_label"])
print(result["result"])
Work Packet Execution
from codexsaver.work_packet import execute_work_packet
result = execute_work_packet(
goal="Add type hints to config loader",
files=["codexsaver/config.py"],
allowed_files=["codexsaver/config.py"],
acceptance_criteria="All functions have type hints",
allowed_commands=["mypy codexsaver/config.py"],
workspace_root="."
)
if result["status"] == "success":
print(f"Patch applied: {result['changed_files']}")
elif result["preflight_satisfied"]:
print("Task already satisfied, no work needed")
Specialist Orchestration
from codexsaver.orchestrate import orchestrate_task
result = orchestrate_task(
task_description="Explain config module and review performance",
files=["codexsaver/config.py"],
mode="execute"
)
if result["status"] == "success":
print(f"Graph type: {result['graph_type']}")
print(f"Findings: {result['findings']}")
print(f"Quality score: {result['quality_score']}")
for specialist, output in result["results"].items():
print(f"\n{specialist}:\n{output}")
Router Configuration
from codexsaver.router import Router
router = Router()
decision = router.should_delegate(
task_description="Write unit tests",
files=["src/utils.py"]
)
print(f"Route: {decision['route']}")
print(f"Risk: {decision['risk_level']}")
print(f"Task type: {decision['task_type']}")
Common Patterns
Pattern 1: Low-Risk Documentation Work
When to use: Adding or updating docs, docstrings, README sections
{
"tool": "codexsaver.delegate_task",
"arguments": {
"task_description": "Add docstrings to all public functions in utils",
"files": ["src/utils.py"],
"mode": "execute"
}
}
Expected route: deepseek (low risk, high volume)
Pattern 2: Bounded Test Generation
When to use: Creating tests for well-defined modules
codexsaver work-packet \
"Write pytest tests for config loader" \
--files codexsaver/config.py \
--allowed-file tests/test_config.py \
--acceptance "tests/test_config.py exists and pytest passes" \
--allowed-command "pytest tests/test_config.py -v" \
--workspace .
Expected route: deepseek with sandbox verification
Pattern 3: Readonly Analysis
When to use: Code explanation, performance hints, security scan (no patches)
codexsaver orchestrate "Explain auth flow and review performance" \
--files src/auth.py
Expected route: readonly_swarm (parallel explainer + perf_reviewer)
Pattern 4: Codex Takeover for High-Risk Work
When to use: Auth, payment, destructive migrations, ambiguous architecture
{
"tool": "codexsaver.delegate_task",
"arguments": {
"task_description": "Refactor authentication middleware",
"files": ["src/auth/middleware.py"],
"mode": "execute"
}
}
Expected route: codex (protected path detected)
Response includes:
{
"interaction": {
"mode": "codex_takeover",
"headline": "CodexSaver kept this task with Codex",
"route_label": "[CodexSaver] route=codex reason=protected_path"
}
}
Pattern 5: Mixed Graph Orchestration
When to use: Docs + explanation + small impl changes
codexsaver orchestrate "Document API, explain usage, and add examples" \
--files codexsaver/api.py
Expected graph: docs + explain (mixed readonly + bounded patch)
Risk Assessment Rules
CodexSaver routes tasks based on:
Automatic Codex Takeover
- Files match
protected_paths (auth, payment, .env)
- Task mentions security, permissions, migration
- Ambiguous requirements
- Multi-file behavioral changes without verification
Safe Delegation to Worker
- Task type:
write_tests, write_docs, explain, search
- Files outside protected paths
- Clear acceptance criteria
- Bounded scope with verification commands
Configuration Override
{
"routing": {
"protected_paths": ["src/auth/", "billing/", "*.key"],
"risk_threshold": "medium",
"force_codex_patterns": ["payment", "security", "migrate"]
}
}
Worker Output Compression
Reduce delegated output length for faster Codex review:
{
"worker_compression": {
"enabled": true,
"level": "medium"
}
}
Levels:
low: Minor trimming
medium: Remove verbose explanations, keep facts
high: Maximum compression, essential info only
Response includes compression notice:
{
"interaction": {
"compression": {
"active": true,
"level": "medium",
"notice": "Worker output compressed to medium level"
}
}
}
Troubleshooting
MCP Tool Not Found
Symptom: Codex doesn't recognize codexsaver.* tools
Fix:
cat ~/.config/codex/mcp.json
python -m codexsaver.mcp_server
Worker Provider Authentication Failed
Symptom: Authentication error: DEEPSEEK_API_KEY not found
Fix:
export DEEPSEEK_API_KEY="sk-..."
cat ~/.codexsaver/config.json
codexsaver preview "test task" --files README.md
Sandbox Verification Failed
Symptom: Work packet returns verification_failed
Fix:
codexsaver work-packet \
"test task" \
--allowed-command "python -c 'import sys; sys.exit(0)'" \
--acceptance "passes basic check" \
--workspace . \
--verbose
codexsaver work-packet \
"complex task" \
--max-iterations 5 \
--workspace .
All Tasks Route to Codex
Symptom: No cost savings, everything stays with Codex
Fix:
{
"routing": {
"risk_threshold": "low",
"protected_paths": []
}
}
Or use explicit work packets for guaranteed delegation.
V3 Orchestration Returns needs_codex
Symptom: Complex graphs fall back conservatively
Expected behavior: V3 patch orchestration is still maturing. Use for:
- ✅ Readonly specialist swarms (established)
- ✅ Single bounded patches (v2 mature)
- ⚠️ Multi-patch graphs (promising but conservative)
Workaround: Break complex tasks into separate work packets.
Best Practices
- Start with preview mode to understand routing decisions
- Use work packets for implementation to get sandbox verification
- Use orchestration for analysis (readonly swarms are fastest)
- Keep Codex for ambiguity - don't force delegation on unclear tasks
- Monitor cost savings - review interaction blocks in responses
- Set realistic acceptance criteria - make verification commands specific
- Protect sensitive paths - add to
protected_paths config
- Enable compression for faster Codex review of delegated output
Environment Variables
export DEEPSEEK_API_KEY="sk-..."
export OPENAI_API_KEY="sk-..."
export ANTHROPIC_API_KEY="sk-ant-..."
export GEMINI_API_KEY="..."
export QWEN_API_KEY="..."
export CODEXSAVER_CONFIG_PATH="/custom/path/config.json"
Provider Presets
Switch providers in ~/.codexsaver/config.json:
{
"provider": "openai",
"openai": {
"api_key_env": "OPENAI_API_KEY",
"model": "gpt-4o-mini"
}
}
Supported: deepseek, openai, anthropic, gemini, qwen, ollama, lmstudio