Dev.to AI πŸ€– Ai πŸ‘ 2 πŸ“– 7 min read

How to Keep Multi-Agent Delegation Cheap with Codex and DeepSeek

A note on how this was written: I drafted this from my own test logs and the runs are reproducible. The prose was edited with AI assistance, per dev.to's guidance on AI-assisted articles. The measurements and the failure

How to Keep Multi-Agent Delegation Cheap with Codex and DeepSeek

A note on how this was written: I drafted this from my own test logs and the runs are reproducible. The prose was edited with AI assistance, per dev.to's guidance on AI-assisted articles. The measurements and the failure modes are mine.

I ran Codex as a solo agent on a medium-sized request for a few weeks. Then I looked at the usage numbers and rebuilt the pipeline. This is what changed and what it cost.

The measurement that made me rebuild it

One complete delegation, deduplicated, single node, single session:

  • Uncached input: 24 tokens
  • Cache write: 225,504 tokens
  • Cache read: 343,842 tokens
  • Output: 5,837 tokens
  • Cache hit rate: 60.39%

Priced at DeepSeek's official V4-Flash rates, that is about Β₯0.028 of input and Β₯0.026 of output. Under six cents per delegation.

The ratio is the interesting part. 343,842 against 24. That is not a tuning artifact. It falls out of the architecture, and the architecture is the whole point.

Why the bill grows

Codex's judgment is the expensive thing you are paying for. On a complex request, though, most of its time goes somewhere else.

It reads a dozen files. It walks the call chain. It edits three or five modules. It runs the tests. A test fails, so it reads the logs, edits again, runs again, and finds another edge case. By the end the context is stuffed with code fragments and stack traces.

None of that is easy work. All of it is work that consumes patience and context capacity rather than judgment. And once the context is full of it, every later decision gets worse, because the thread that should be holding the architecture is busy holding a stack trace.

I did the arithmetic on a 60-million-token workload at official prices. The bill is large enough to make you stop and think. The slice of it that genuinely needed Codex to decide something was small.

Four layers, one job each

Codex main thread. Decomposes the request, creates sub-agents, reviews results, sends work back, owns delivery. Accountable for the outcome and nothing else.

Codex sub-agent. A traceable node in the conversation tree, not a chat window. It carries a task file and calls the delegation script.

Claude Code CLI. The execution layer. Reads files, edits code, runs verification, returns a structured report.

The backing model. Whatever Claude Code points at. Point it at DeepSeek and it absorbs the repeated context.

The six artifact types one delegation leaves behind

The change is not that there is more AI in the loop. It is that the main thread stops swallowing noise. It receives conclusions instead of intermediate state.

What you need installed

Four things. The pipeline does not run without all four.

  • Codex. The main thread.
  • Claude Code CLI. The execution layer, callable from a terminal.
  • CC Switch. Points Claude Code's backend at DeepSeek.
  • A target project. Something with enough scale to be worth reading. A two-line change does not justify the setup.

Plugin version should be 1.0.10. The workflow root is skills/codex-with-cc inside the install directory, not the plugin root. One level off and none of the scripts resolve.

Set up the API key

The authentication method decides whether every later call works, so it gets its own section.

Create the key in the console and store it in an environment variable. Do not put it in source. The Codex integration guide covers the endpoint, the model identifier format, and how key permissions and quotas are scoped.

Then confirm the key works before you build anything on top of it. Ask the execution layer one ordinary question, with three flags set together.

claude -p "Describe this project in one sentence" --output-format json --max-turns 4

A response with is_error set to false plus a normal text block means the path is live. --max-turns 4 stops it from expanding scope on its own. --output-format json is what makes usage readable later.

If your endpoint is Anthropic-compatible, point the execution layer at it. Switching models changes only the model name.

https://api.crazyrouter.com

Running it

1. Install the plugin

The repo moved from copied scripts to a plugin marketplace, so the old path no longer works.

codex plugin marketplace add aiskyhub/aiskyhub
codex plugin add codex-with-cc@aiskyhub
codex plugin list

The line should read installed, enabled.

2. Run the self-check

python skills/codex-with-cc/scripts/test_delegate_session_pool.py

You want delegate session pool tests passed.

On Windows the runtime self-check throws UnicodeDecodeError, because the script decodes subprocess output as UTF-8. Real delegation is unaffected.

3. Write the task file

Sub-agents accept only structured task files. Six sections, none optional. Placeholders get rejected at validation time. The last section is the one people forget: the report headings must cover eight fixed items.

Put the file under .codex/codex_with_cc/tasks/ in the project.

4. Validate

python skills/codex-with-cc/scripts/validate_delegate_task.py -TaskFile <task-file> -Role researcher

Task validation passed means all six sections are present.

5. Dry run

Run the full delegation command without invoking the model, to confirm where artifacts land. The last line reads Dry run enabled; Claude Code was not invoked.

Artifacts must land in .codex/codex_with_cc/claude-delegate/ inside the project. If they land in the plugin cache directory, you will not find them per project later.

6. Delegate for real

Drop -DryRun. Do not skip any of the eight parameters.

CODEX_CLAUDE_CHILD_THREAD=1 python skills/codex-with-cc/scripts/delegate_to_claude.py \
  -TaskFile <task-file> -WorkflowId <workflow-name> -TaskId <subtask-name> \
  -Role researcher -SessionKey <session-key> -Scope <scope-files> \
  -Model <model-name> -BypassPermissions

-Model is mandatory. Its default is sonnet. Leave it out and a backend configured for something else makes no difference, because the bill is still settled at Sonnet rates.

7. Check status

Success is "status": "completed" and "exitCode": 0 in the status file. My run took about three minutes and produced an 8,369-byte report.

What you get back

Six file types per run.

config records the model, the scope, the session key, and every path. The first field to read is model. status records state, exit code, retry count, and the reason for each failure. prompt is the full text actually sent to the execution layer, which is where you look when you want to know why it behaved a certain way instead of guessing. stream is raw JSONL, one record per line, and all usage lives there. trace is a condensed human-readable path. claude is the report the sub-agent delivered.

Status file showing state and retry history

The report follows an eight-section structure with real content in each. Mine traced slugify's main function pipeline from argument validation through counter cleanup, with line numbers, and volunteered that it could not run runtime probes because it had not installed dependencies, so its performance conclusions were inference only. Flagging the uncertain part is more useful than a clean set of conclusions.

Why the cost drops this far

Per-delegation cost, priced at official rates

Cache read 343,842 against uncached input of 24. DeepSeek's cache is designed for repeatedly reading the same stable prefix, and delegation fits that shape exactly. Sub-agents re-read the same files, rebuild the same mental model of the project, and work inside the same context over and over. All of the repeat work hits cache.

So the saving is not from hunting a cheaper model. It comes from routing repeat labor to whichever layer handles it cheapest, and keeping judgment where judgment is worth paying for.

You can check current per-model pricing and multiply by your own volume. The cache-read and uncached rates differ a lot. Mixing them is the fastest way to a wrong answer.

Three traps

-Model defaults to sonnet. The delegation script hardcodes default="sonnet". Skip it and the bill settles at Sonnet rates no matter what you configured elsewhere.

DeepSeek does not complete inside the delegation chain. I tried three times: 570k, 77k, and 41k tokens of input. Output was zero every time, stuck in the multi-turn tool loop. The same model, called directly, completes a single turn in 14 seconds and a turn with one tool call in 24. Sonnet was the only configuration that finished reliably.

Session keys will block you. -SessionKey controls session reuse, and the same key tries to continue the same conversation. My first run was rejected for reusing a previous session ID, and the script opened a new session on its own.

When this fits

It fits large-scale code reading, multi-file implementation, comparing several approaches, separating implementation from review, migrations, and test backfill. The common thread is that no single step is hard, but the whole thing is context-hungry.

It does not fit a one-line change, where delegation overhead exceeds the benefit. It does not fit requirements still in motion, where you should settle scope in the main thread first. And it does not fit work with heavy file conflicts, since parallel agents editing the same region step on each other. Parallelism needs clean task boundaries, not more agents.

What I have not verified

Single node, single session. The real payoff of parallel sub-agents is untested, and so is the contention and reclamation behavior when several run at once. On hit rate, 60.39% is my measurement; I could not reproduce the 98.5% figure that circulates, and the difference is task shape rather than the product. Cache-write billing is the other open question. Chinese official pricing does not list it separately, so I counted it as uncached input, and I have not reconciled the actual charge in the console.

References

  • codex_with_cc repository: github.com/aiskyhub/codex_with_cc
  • Original article, "Codexη©·ι¬Όε€§ζ•‘ζ˜Ÿ" by 小呆呆666: juejin.cn/post/7635467758865235968
  • DeepSeek official pricing: api-docs.deepseek.com/quick_start/pricing
  • Crazyrouter API guide: crazyrouter.com/en/guide
πŸ“° Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.