BundledAutonomous AI AgentsVersion 1.0.1

Using OpenAI Codex CLI with Hermes Agent for Autonomous Coding

Delegate coding to OpenAI Codex CLI (features, PRs).

Written by Neura Market from the official Hermes Agent documentation for Codex. Commands, paths, and version numbers are reproduced from the source unchanged.

Read the official documentation

The Codex skill lets you hand coding tasks to OpenAI's Codex CLI directly from Hermes Agent terminal calls. You describe the work in natural language, and Codex writes, edits, and commits code inside a git repository. This is useful when you want an autonomous agent to handle feature work, refactoring, PR reviews, or batch issue fixes without you sitting at the keyboard.

What it does

Codex runs as a subprocess inside a Hermes terminal session. You give it a prompt like "Add dark mode toggle to settings", and it plans, writes, and applies the changes. It can work in one-shot mode (run and exit) or background mode (long-running tasks you monitor and interact with). The skill supports sandboxed execution to limit file access, and it can review pull requests or fix multiple issues in parallel using git worktrees.

Before you start

  • Install Codex globally: npm install -g @openai/codex
  • Configure authentication: set OPENAI_API_KEY as an environment variable, or complete the Codex CLI OAuth login flow (which stores credentials in ~/.codex/auth.json).
  • You must run Codex inside a git repository. It refuses to operate outside one. For scratch work, create a temp directory and initialize a git repo.
  • Always use pty=true in terminal calls. Codex is an interactive terminal application and will hang without a pseudo-terminal.
  • If you are using Hermes-managed Codex OAuth, set model.provider: openai-codex and authenticate via hermes auth add openai-codex. This stores credentials in ~/.hermes/auth.json. Do not assume that a missing OPENAI_API_KEY means Codex auth is unavailable; the OAuth session may still be valid.

One-Shot Tasks

For a single, self-contained task, use codex exec with your prompt:

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

Codex runs the prompt, makes changes, and exits. The workdir should point to your git repository.

For scratch work where you don't have an existing repo, create one on the fly:

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

Background Mode (Long Tasks)

For tasks that take minutes or require interaction, start Codex in the background:

# 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>")

Use poll to check if the process is still running, log to see its output, submit to answer any questions Codex asks, and kill to stop it.

Key Flags

FlagEffect
exec "prompt"One-shot execution, exits when done
--sandbox workspace-write (-s)Sandboxed but auto-approves file changes in the workspace (the recommended auto-build mode)
--dangerously-bypass-approvals-and-sandboxNo sandbox, no approvals (fastest, most dangerous; --yolo still works as a hidden alias)
--sandbox danger-full-accessNo Codex sandbox; useful when the host service context breaks bubblewrap

Deprecated: --full-auto still works but the live CLI warns to use --sandbox workspace-write instead.

Hermes Gateway Caveat

When invoking the Codex CLI from a Hermes gateway/service context (for example, Telegram-driven agent sessions), Codex workspace-write sandboxing may fail even when the same command works in the user's interactive shell. A typical symptom is bubblewrap/user-namespace errors such as setting up uid map: Permission denied or loopback: Failed RTM_NEWADDR: Operation not permitted.

In that context, prefer:

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

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

PR Reviews

Clone to a temp directory for safe review:

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)

Parallel Issue Fixing with Worktrees

Use git worktrees to work on multiple issues simultaneously:

# 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

Review multiple PRs in parallel without cloning each one:

# 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")

Rules

  1. Always use pty=true, Codex is an interactive terminal app and hangs without a PTY
  2. Git repo required, Codex won't run outside a git directory. Use mktemp -d && git init for scratch
  3. Use exec for one-shots, codex exec "prompt" runs and exits cleanly
  4. --sandbox workspace-write for building, auto-approves changes within the sandbox (--full-auto is deprecated for this)
  5. Background for long tasks, use background=true and monitor with process tool
  6. Don't interfere, monitor with poll/log, be patient with long-running tasks
  7. Parallel is fine, run multiple Codex processes at once for batch work

When not to use it

If you need a coding agent that does not require a git repository, or if you cannot install Node.js and npm, this skill is not for you. For alternatives, see the related skills claude-code and hermes-agent.

Limits and gotchas

  • Codex requires a git repository. For one-off scripts, you must create a temp repo.
  • The workspace-write sandbox may fail in gateway/service contexts due to bubblewrap/user-namespace restrictions. Use danger-full-access and rely on process-level safety instead.
  • The --full-auto flag is deprecated; use --sandbox workspace-write.
  • Always use pty=true; Codex will hang without it.

Related skills

  • claude-code: Another autonomous coding agent skill for Hermes.
  • hermes-agent: The base Hermes agent skill for general autonomous tasks.

Skills the docs pair this with

More Autonomous AI Agents skills