OpenClaw LogoOpenClaw AI

coding-agent

Run Codex CLI, Claude Code, OpenCode, or Pi Coding Agent via background process for programmatic control.80

Coding Agent (bash-first)

Use bash (with optional background mode) for all coding agent work. Simple and effective.

⚠️ PTY Mode Required!

Coding agents (Codex, Claude Code, Pi) are interactive terminal applications that need a pseudo-terminal (PTY) to work correctly. Without PTY, you'll get broken output, missing colors, or the agent may hang.

Always usepty:true when running coding agents:

Bash Tool Parameters

ParameterTypeDescription
commandstringThe shell command to run
ptybooleanUse for coding agents! Allocates a pseudo-terminal for interactive CLIs
workdirstringWorking directory (agent sees only this folder's context)
backgroundbooleanRun in background, returns sessionId for monitoring
timeoutnumberTimeout in seconds (kills process on expiry)
elevatedbooleanRun on host instead of sandbox (if allowed)

Process Tool Actions (for background sessions)

ActionDescription
listList all running/recent sessions
pollCheck if session is still running
logGet session output (with optional offset/limit)
writeSend raw data to stdin
submitSend data + newline (like typing and pressing Enter)
send-keysSend key tokens or hex bytes
pastePaste text (with optional bracketed mode)
killTerminate the session

Quick Start: One-Shot Tasks

For quick prompts/chats, create a temp git repo and run:

Why git init? Codex refuses to run outside a trusted git directory. Creating a temp repo solves this for scratch work.


The Pattern: workdir + background + pty

For longer tasks, use background mode with PTY:

Why workdir matters: Agent wakes up in a focused directory, doesn't wander off reading unrelated files (like your soul.md πŸ˜…).


Codex CLI

Model: gpt-5.2-codex is the default (set in ~/.codex/config.toml)

Flags

FlagEffect
exec "prompt"One-shot execution, exits when done
--full-autoSandboxed but auto-approves in workspace
--yoloNO sandbox, NO approvals (fastest, most dangerous)

Building/Creating

Reviewing PRs

⚠️ CRITICAL: Never review PRs in OpenClaw's own project folder! Clone to temp folder or use git worktree.

Batch PR Reviews (parallel army!)


Claude Code


OpenCode


Pi Coding Agent

Note: Pi now has Anthropic prompt caching enabled (PR #584, merged Jan 2026)!


Parallel Issue Fixing with git worktrees

For fixing multiple issues in parallel, use git worktrees:


⚠️ Rules

  1. Always use pty:true - coding agents need a terminal!
  2. Respect tool choice - if user asks for Codex, use Codex.
    • Orchestrator mode: do NOT hand-code patches yourself.
    • If an agent fails/hangs, respawn it or ask the user for direction, but don't silently take over.
  3. Be patient - don't kill sessions because they're "slow"
  4. Monitor with process:log - check progress without interfering
  5. --full-auto for building - auto-approves changes
  6. vanilla for reviewing - no special flags needed
  7. Parallel is OK - run many Codex processes at once for batch work
  8. NEVER start Codex in ~/clawd/ - it'll read your soul docs and get weird ideas about the org chart!
  9. NEVER checkout branches in ~/Projects/openclaw/ - that's the LIVE OpenClaw instance!

Progress Updates (Critical)

When you spawn coding agents in the background, keep the user in the loop.

  • Send 1 short message when you start (what's running + where).
  • Then only update again when something changes:
    • a milestone completes (build finished, tests passed)
    • the agent asks a question / needs input
    • you hit an error or need user action
    • the agent finishes (include what changed + where)
  • If you kill a session, immediately say you killed it and why.

This prevents the user from seeing only "Agent failed before reply" and having no idea what happened.


Auto-Notify on Completion

For long-running background tasks, append a wake trigger to your prompt so OpenClaw gets notified immediately when the agent finishes (instead of waiting for the next heartbeat):

Example:

This triggers an immediate wake event β€” Skippy gets pinged in seconds, not 10 minutes.


Learnings (Jan 2026)

  • PTY is essential: Coding agents are interactive terminal apps. Without pty:true, output breaks or agent hangs.
  • Git repo required: Codex won't run outside a git directory. Use mktemp -d && git init for scratch work.
  • exec is your friend: codex exec "prompt" runs and exits cleanly - perfect for one-shots.
  • submit vs write: Use submit to send input + Enter, write for raw data without newline.
  • Sass works: Codex responds well to playful prompts. Asked it to write a haiku about being second fiddle to a space lobster, got: "Second chair, I code / Space lobster sets the tempo / Keys glow, I follow" 🦞