
codexsaver-cost-router
Route low-risk coding tasks to cheaper LLMs while keeping Codex for high-risk decisions, using MCP tools for cost-aware delegation
- Installs
- 266
- Last 24h
- —
- Trending rank
- —
- Security
- Not audited
Install
Works with every agent the skills CLI supports.
npx skills add https://github.com/reason-machines/codex-skills --skill codexsaver-cost-router- 01
Install
Run the command in your project. The CLI asks which agents to install for.
- 02
Describe the task
Ask your agent for something this skill covers. It loads codexsaver-cost-router automatically when relevant.
- 03
Review the result
The agent follows the SKILL.md steps, scripts and references bundled with the skill.
SKILL.md
The instructions your agent reads when the skill is triggered.
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
# Clone repository
git clone https://github.com/fendouai/CodexSaver.git
cd CodexSaver
# Install globally
pip install -e .
# Initialize config
codexsaver init
# Add to Codex MCP config (~/.config/codex/mcp.json or workspace .codex/mcp.json)
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"],
"risk_threshold": "medium"
}
}
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 delegatefiles(optional): List of file paths for contextmode(optional):previeworexecute(default:execute)
Example call from Codex:
# Codex calls this internally via MCP
{
"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 goalfiles(optional): Context filesallowed_files(required): Globs for writable filesforbidden_paths(optional): Protected pathsacceptance_criteria(required): Success conditionsallowed_commands(required): Verification commandsmax_iterations(optional): Default 3max_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 taskfiles(optional): Context filesmode(optional):previeworexecute
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
# Readonly specialists (fastest, most reliable)
codexsaver orchestrate "Explain installer flow and review performance" \
--files codexsaver/install.py
# Mixed graph (docs + explain)
codexsaver orchestrate "Document API and explain usage patterns" \
--files codexsaver/api.py
# Dry run
codexsaver orchestrate "Implement login and add tests" \
--files src/auth.py \
--dry-run
Run Single Specialist
# Explainer
codexsaver specialist explainer "Explain this module" \
--files codexsaver/router.py
# Performance Reviewer
codexsaver specialist perf_reviewer "Review performance" \
--files codexsaver/delegate.py
Install Project Guidance
# Basic: AGENTS.md guidance only
codexsaver superpower install --profile basic --workspace .
# Full: AGENTS.md + hooks + local config
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()
# Check if task is safe to delegate
decision = router.should_delegate(
task_description="Write unit tests",
files=["src/utils.py"]
)
print(f"Route: {decision['route']}") # 'deepseek' or 'codex'
print(f"Risk: {decision['risk_level']}") # 'low', 'medium', 'high'
print(f"Task type: {decision['task_type']}") # 'write_tests', 'explain', etc.
Common Patterns
Pattern 1: Low-Risk Documentation Work
When to use: Adding or updating docs, docstrings, README sections
# Via MCP tool
{
"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 trimmingmedium: Remove verbose explanations, keep factshigh: 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:
# Verify MCP server config
cat ~/.config/codex/mcp.json
# Test MCP server manually
python -m codexsaver.mcp_server
# Restart Codex after config changes
Worker Provider Authentication Failed
Symptom: Authentication error: DEEPSEEK_API_KEY not found
Fix:
# Set environment variable
export DEEPSEEK_API_KEY="sk-..."
# Verify config
cat ~/.codexsaver/config.json
# Test provider directly
codexsaver preview "test task" --files README.md
Sandbox Verification Failed
Symptom: Work packet returns verification_failed
Fix:
# Check allowed commands are valid
codexsaver work-packet \
"test task" \
--allowed-command "python -c 'import sys; sys.exit(0)'" \
--acceptance "passes basic check" \
--workspace . \
--verbose
# Increase max iterations
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_pathsconfig - Enable compression for faster Codex review of delegated output
Environment Variables
# Required for DeepSeek (default provider)
export DEEPSEEK_API_KEY="sk-..."
# Optional alternative providers
export OPENAI_API_KEY="sk-..."
export ANTHROPIC_API_KEY="sk-ant-..."
export GEMINI_API_KEY="..."
export QWEN_API_KEY="..."
# Optional: override config path
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
FAQ
What does the codexsaver-cost-router skill do?
Route low-risk coding tasks to cheaper LLMs while keeping Codex for high-risk decisions, using MCP tools for cost-aware delegation
How do I install codexsaver-cost-router?
Run npx skills add https://github.com/reason-machines/codex-skills --skill codexsaver-cost-router in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/codexsaver-cost-router/ (personal) or .claude/skills/codexsaver-cost-router/ (project).
Which AI agents can use codexsaver-cost-router?
Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.
Is codexsaver-cost-router safe to install?
No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.
Who maintains codexsaver-cost-router?
It is published by reason-machines in reason-machines/codex-skills. It has 266 recorded installs.
More from reason-machines/codex-skills
academic-research-skills-codex
reason-machines/codex-skills
Open the skill to read its SKILL.md instructions.
codexplusplus-launcher
reason-machines/codex-skills
Enhanced launcher for Codex App that unlocks plugins, enables session deletion, exports conversations, and syncs provider sessions via CDP injection
codex-plugin-claude-code
reason-machines/codex-skills
Open the skill to read its SKILL.md instructions.
awesome-codex-subagents
reason-machines/codex-skills
A curated collection of 136+ specialized Codex subagents for development tasks across 10 categories
oh-my-codex-workflow
reason-machines/codex-skills
Expert in Oh My Codex (OMX) - workflow layer for OpenAI Codex CLI with agents, skills, and team coordination
codexbar-menubar-ai-usage-tracker
reason-machines/codex-skills
Monitor AI coding assistant usage limits and token resets in the macOS menu bar with CodexBar
Popular ai & agents skills
google-agents-cli-publish
google/agents-cli
This skill should be used when the user wants to "publish an agent", "publish my ADK agent", "register an agent with Gemini", "publish to Gemini" (formerly Gemini Enterprise), or needs guidance on the agents-cli publish gemini command. Also use when the user wants to "manage agents in Agent Registry", "list/update/delete registered agents", or "register an MCP server". Covers ADK vs A2A registration modes, programmatic and interactive usage, flag reference, auto-detection from deployment metadata, Agent Registry fleet management, and troubleshooting. Part of the agents-cli skills suite. Do NOT use for deployment (use google-agents-cli-deploy).
google-agents-cli-eval
google/agents-cli
This skill should be used when the user wants to "run an evaluation", "evaluate my agent", "evaluate my ADK agent", "write an eval dataset", "analyze eval failures", "compare eval results", "optimize agent", or needs guidance on the Gemini platform eval methodology and the Quality Flywheel. Covers eval metrics, dataset schema, LLM-as-judge scoring, and common failure causes. Applies to any agents-cli project, whatever framework the agent is written in. Do NOT use for agent API code patterns (ADK: use google-agents-cli-adk-code), deployment (use google-agents-cli-deploy), or project scaffolding (use google-agents-cli-scaffold).
skill-creator
anthropics/skills
Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy.
codex-pet
prime-skills/runcomfy-agent-skills
Codex Pet generator on RunComfy. Build a Codex-compatible Codex Pet spritesheet.webp + pet.json from a single reference image, drop it into ${CODEXHOME:-$HOME/.codex}/pets/ / and Codex picks it up as a custom Codex Pet next to the 8 built-ins. This skill produces the exact Codex Pet atlas Codex expects (1536x1872 PNG/WebP, 8 cols x 9 rows, 192x208 cells, 9 animation states — idle, running-right, running-left, waving, jumping, failed, waiting, running, review). Calls OpenAI GPT Image 2 edit ONCE via the local RunComfy CLI as runcomfy run openai/gpt-image-2/edit to produce a canonical Codex Pet pose, then assembles all 9 animation rows programmatically with ImageMagick micro-transforms — no Codex Pro, no $imagegen, no OPENAIAPIKEY required, only RUNCOMFYTOKEN. Triggers on "codex pet", "create codex pet", "make codex pet", "hatch codex pet", "/hatch image", "desktop pet codex", "codex pets", "spritesheet.webp", or any explicit ask to build a custom pet for OpenAI Codex.
full-output-enforcement
leonxlnx/taste-skill
Overrides default LLM truncation behavior. Enforces complete code generation, bans placeholder patterns, and handles token-limit splits cleanly. Apply to any task requiring exhaustive, unabridged output.
executing-plans
obra/superpowers
Use when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available