WhoBuilt

Hacking Subagents Into Codex CLI

Nov 24, 2025· 14 min· 7.2K views·Watch on YouTube

Speaker

Brian John, a principal full-stack engineer at BetterUp, explains how he added subagents to Codex CLI in a talk for AI Engineer.

Why add subagents to Codex

John wanted to use Codex CLI and its models without giving up the subagent workflows he uses in Claude Code. Subagents can handle a task in a separate context and return only their answer, keeping that work out of the main agent’s context window.

How the wrapper works

A wrapper script chooses an agent, builds its prompt, and starts a child `codex exec` process. The child does the work and writes its answer to a file; the wrapper reads that file and returns the result to the parent session.

Permissions and security tradeoffs

Getting the setup to work within Codex’s sandbox required careful permission choices. John says the parent and child need workspace-write access, and the child needs the rollout recorder disabled to avoid filesystem access problems; he also discusses the risks of handling proprietary code and allowing external communication.

Configure and run agents

John uses `AGENTS.md` to explain how Codex should invoke the wrapper, when to use subagents, and which agents are available. The demo defines agents with a name, reasoning effort, and prompt, including a word counter and a file writer. It writes the agent name and query to files so the command stays consistent and only needs approval once.

Demo results and limitations

In the demo, Codex runs the word counter and file writer through the wrapper, with the second invocation reusing the approved command. Calls run serially, and John says large codebase tasks can take 10 minutes or sometimes 20, so the wrapper’s timeout may need to be increased.

Takeaways

  • Use a separate Codex process to isolate subagent context and return only the result to the parent.
  • Document invocation rules, agent purposes, and when to delegate in `AGENTS.md`.
  • Write changing inputs to files if Codex’s permission system requires a stable command for repeated approvals.
  • Set sandbox permissions deliberately and assess the risks of private code access and external API communication.
  • Expect serial execution and allow longer timeouts for tasks that scan large codebases.

Mentioned in this talk

Search inside this talk

What was claimed 5

  • works at
    Principal Full-Stack Engineer (joined as Senior Full-Stack Engineer)
    “I'm a principal full-stack engineer.”
    YouTube
    Verified2 sources· Talk, Web· archived
  • uses
    “I wanted to be able to use other tools, particularly the Codex CLI”
    YouTube
    Unverified1 source· Talk
  • uses
    “I've been using Claude Code as my daily driver”
    YouTube
    Unverified1 source· Talk
  • feature
    subagents: Keep delegated work context out of the main agent’s context window
    “All the context used by the subagent doesn't end up in your main context window”
    YouTube
    Unverified1 source· Talk
  • feature
    Codex: Subagents run serially in the demonstrated setup
    “Codex does not have the ability to run things asynchronously like Claude does”
    YouTube
    Unverified1 source· Talk

Related talks