Delegate Coding Tasks to OpenAI Codex CLI

Delegate coding tasks such as building features, refactoring, PR reviews and batch issue fixing to OpenAI's Codex CLI through the Hermes terminal.

Hermes Intermediate Copied: 0
1 resource

Requirements

  • Requires the codex CLI and a git repository.
  • Codex installed: npm install -g @openai/codex
  • OpenAI auth must be configured, either via inline_2 or Codex OAuth credentials.
  • Alternatively, Codex OAuth credentials can come from the Codex CLI login flow.
  • Must run inside a git repository — Codex refuses to run outside one.
  • For Hermes itself, inline_4 uses Hermes-managed Codex OAuth from inline_5 after inline_6. For the standalone Codex CLI, a valid CLI OAuth session may live under inline_7; do not treat a missing inline_2 alone as proof that Codex auth is missing.

How to use

Use inline_3 in terminal calls — Codex is an interactive terminal app.

Codex installed: npm install -g @openai/codex

Use inline_3 in terminal calls — Codex is an interactive terminal app and hangs without a PTY.

For Hermes itself, inline_4 uses Hermes-managed Codex OAuth from inline_5 after inline_6; for the standalone Codex CLI, a valid CLI OAuth session may live under inline_7, so a missing inline_2 alone is not proof that Codex auth is missing.

Run one-shot coding tasks with Codex exec in a project workdir with a PTY.

terminal(command="codex exec 'Add dark mode toggle to settings'", workdir="~/project", pty=true)

For scratch work, create a temp directory, init a git repo, and run a one-shot Codex task there (Codex needs a git repo).

terminal(command="cd $(mktemp -d) && git init && codex exec 'Build a snake game in Python'", pty=true)

Run long tasks in background mode: start Codex in the background with a PTY, poll and read logs to monitor progress, submit input if Codex asks a question, and kill the session if needed.

# Start in background with PTY
terminal(command="codex exec --sandbox workspace-write 'Refactor the auth module'", workdir="~/project", background=true, pty=true)
# Returns session_id

# Monitor progress
process(action="poll", session_id="<id>")
process(action="log", session_id="<id>")

# Send input if Codex asks a question
process(action="submit", session_id="<id>", data="yes")

# Kill if needed
process(action="kill", session_id="<id>")

Flag effects: inline_8 runs one-shot and exits when done; inline_9 (inline_10) is sandboxed but auto-approves file changes in the workspace (the recommended auto-build mode); inline_11 removes sandbox and approvals (fastest, most dangerous; inline_12 still works as a hidden alias); inline_13 removes the Codex sandbox, useful when the host service context breaks bubblewrap.

Deprecated: inline_14 still works but the live CLI warns to use inline_9 instead.

Hermes gateway caveat: when invoking Codex from a Hermes gateway/service context, Codex inline_15 sandboxing may fail even when the same command works in the user's interactive shell.

Typical symptoms are bubblewrap/user-namespace errors such as inline_16 or inline_17.

In that context, prefer:

codex exec --sandbox danger-full-access "<task>"

Use process boundaries as the safety layer instead: explicit inline_18, clean git status before launch, narrow task prompts, inline_19 review, targeted tests, and human/agent confirmation before committing broad changes.

Run PR reviews.

Clone the repo to a temp directory for safe review, check out the PR, and run Codex review against a base branch.

terminal(command="REVIEW=$(mktemp -d) && git clone https://github.com/user/repo.git $REVIEW && cd $REVIEW && gh pr checkout 42 && codex review --base origin/main", pty=true)

Fix parallel issues with git worktrees: create a worktree per issue, launch Codex in each with background and PTY, monitor, then push and create PRs after completion and clean up the worktrees.

# Create worktrees
terminal(command="git worktree add -b fix/issue-78 /tmp/issue-78 main", workdir="~/project")
terminal(command="git worktree add -b fix/issue-99 /tmp/issue-99 main", workdir="~/project")

# Launch Codex in each
terminal(command="codex --sandbox workspace-write exec 'Fix issue #78: <description>. Commit when done.'", workdir="/tmp/issue-78", background=true, pty=true)
terminal(command="codex --sandbox workspace-write exec 'Fix issue #99: <description>. Commit when done.'", workdir="/tmp/issue-99", background=true, pty=true)

# Monitor
process(action="list")

# After completion, push and create PRs
terminal(command="cd /tmp/issue-78 && git push -u origin fix/issue-78")
terminal(command="gh pr create --repo user/repo --head fix/issue-78 --title 'fix: ...' --body '...'")

# Cleanup
terminal(command="git worktree remove /tmp/issue-78", workdir="~/project")

Batch PR reviews: fetch PR refs, launch parallel Codex review sessions with background and PTY, then post results as PR comments.

# Fetch all PR refs
terminal(command="git fetch origin '+refs/pull/*/head:refs/remotes/origin/pr/*'", workdir="~/project")

# Review multiple PRs in parallel
terminal(command="codex exec 'Review PR #86. git diff origin/main...origin/pr/86'", workdir="~/project", background=true, pty=true)
terminal(command="codex exec 'Review PR #87. git diff origin/main...origin/pr/87'", workdir="~/project", background=true, pty=true)

# Post results
terminal(command="gh pr comment 86 --body '<review>'", workdir="~/project")

Always use inline_3 — Codex is an interactive terminal app and hangs without a PTY.

Git repo required — Codex won't run outside a git directory; use inline_20 for scratch work.

Use inline_21 for one-shots — inline_22 runs and exits cleanly.

Use inline_9 for building — it auto-approves changes within the sandbox (inline_14 is deprecated for this).

Use background for long tasks: run with inline_23 and monitor with the inline_24 tool.

Don't interfere — monitor with inline_25/inline_26 and be patient with long-running tasks.

Parallel is fine — run multiple Codex processes at once for batch work.

Source: nousresearch/hermes-agent and its contributors. License: MIT.

Copyright (c) 2025 Nous Research

Translation and editorial adaptation by ClawCases.

>Resources

>Related Use Cases

>More at this level: Intermediate