2026-01-02 15:40:03 -08:00
---
name: coding-agent
2026-01-03 17:21:17 +01:00
description: Run Codex CLI, Claude Code, OpenCode, or Pi Coding Agent via background process for programmatic control.
2026-01-04 14:32:47 +00:00
metadata: {"clawdbot":{"emoji":"🧩","requires":{"anyBins":["claude","codex","opencode","pi"]}}}
2026-01-02 15:40:03 -08:00
---
2026-01-03 00:00:37 +00:00
# Coding Agent (background-first)
2026-01-02 15:40:03 -08:00
2026-01-03 17:31:26 +01:00
Use **bash background mode** for non-interactive coding work. For interactive coding sessions, use the **tmux** skill (always, except very simple one-shot prompts).
2026-01-02 15:40:03 -08:00
2026-01-03 00:00:37 +00:00
## The Pattern: workdir + background
2026-01-02 15:40:03 -08:00
```bash
2026-01-03 00:35:51 +00:00
# Create temp space for chats/scratch work
SCRATCH=$(mktemp -d)
2026-01-02 23:58:33 +00:00
# Start agent in target directory ("little box" - only sees relevant files)
2026-01-03 00:35:51 +00:00
bash workdir:$SCRATCH background:true command:"< agent command > "
# Or for project work:
2026-01-03 00:00:37 +00:00
bash workdir:~/project/folder background:true command:"< agent command > "
# Returns sessionId for tracking
2026-01-02 15:40:03 -08:00
2026-01-02 23:58:33 +00:00
# Monitor progress
2026-01-03 00:00:37 +00:00
process action:log sessionId:XXX
2026-01-03 00:11:21 +00:00
# Check if done
2026-01-03 00:00:37 +00:00
process action:poll sessionId:XXX
# Send input (if agent asks a question)
process action:write sessionId:XXX data:"y"
2026-01-02 15:40:03 -08:00
2026-01-03 00:00:37 +00:00
# Kill if needed
process action:kill sessionId:XXX
2026-01-02 15:40:03 -08:00
```
2026-01-03 00:11:21 +00:00
**Why workdir matters:** Agent wakes up in a focused directory, doesn't wander off reading unrelated files (like your soul.md 😅).
2026-01-02 15:40:03 -08:00
2026-01-02 23:58:33 +00:00
---
2026-01-02 15:40:03 -08:00
## Codex CLI
2026-01-03 00:11:21 +00:00
**Model:** `gpt-5.2-codex` is the default (set in ~/.codex/config.toml)
2026-01-03 19:45:11 +00:00
### Building/Creating (use --full-auto or --yolo)
2026-01-03 00:11:21 +00:00
```bash
2026-01-03 19:45:11 +00:00
# --full-auto: sandboxed but auto-approves in workspace
2026-01-03 00:11:21 +00:00
bash workdir:~/project background:true command:"codex exec --full-auto \"Build a snake game with dark theme\""
2026-01-03 19:45:11 +00:00
# --yolo: NO sandbox, NO approvals (fastest, most dangerous)
bash workdir:~/project background:true command:"codex --yolo \"Build a snake game with dark theme\""
# Note: --yolo is a shortcut for --dangerously-bypass-approvals-and-sandbox
2026-01-03 00:11:21 +00:00
```
2026-01-03 00:24:34 +00:00
### Reviewing PRs (vanilla, no flags)
2026-01-03 12:49:03 +00:00
2026-01-04 14:32:47 +00:00
**⚠️ CRITICAL: Never review PRs in Clawdbot's own project folder!**
- Either use the project where the PR is submitted (if it's NOT ~/Projects/clawdbot)
2026-01-03 12:49:03 +00:00
- Or clone to a temp folder first
2026-01-02 23:56:01 +00:00
```bash
2026-01-04 14:32:47 +00:00
# Option 1: Review in the actual project (if NOT clawdbot)
2026-01-03 12:49:03 +00:00
bash workdir:~/Projects/some-other-repo background:true command:"codex review --base main"
2026-01-04 14:32:47 +00:00
# Option 2: Clone to temp folder for safe review (REQUIRED for clawdbot PRs!)
2026-01-03 12:49:03 +00:00
REVIEW_DIR=$(mktemp -d)
2026-01-04 14:32:47 +00:00
git clone https://github.com/clawdbot/clawdbot.git $REVIEW_DIR
2026-01-03 12:49:03 +00:00
cd $REVIEW_DIR & & gh pr checkout 130
bash workdir:$REVIEW_DIR background:true command:"codex review --base origin/main"
# Clean up after: rm -rf $REVIEW_DIR
# Option 3: Use git worktree (keeps main intact)
git worktree add /tmp/pr-130-review pr-130-branch
bash workdir:/tmp/pr-130-review background:true command:"codex review --base main"
2026-01-03 00:11:21 +00:00
```
2026-01-04 14:32:47 +00:00
**Why?** Checking out branches in the running Clawdbot repo can break the live instance!
2026-01-03 12:49:03 +00:00
2026-01-03 00:24:34 +00:00
### Batch PR Reviews (parallel army!)
2026-01-03 00:11:21 +00:00
```bash
2026-01-03 00:24:34 +00:00
# Fetch all PR refs first
git fetch origin '+refs/pull/*/head:refs/remotes/origin/pr/*'
# Deploy the army - one Codex per PR!
bash workdir:~/project background:true command:"codex exec \"Review PR #86 . git diff origin/main...origin/pr/86\""
bash workdir:~/project background:true command:"codex exec \"Review PR #87 . git diff origin/main...origin/pr/87\""
bash workdir:~/project background:true command:"codex exec \"Review PR #95 . git diff origin/main...origin/pr/95\""
# ... repeat for all PRs
2026-01-03 00:11:21 +00:00
2026-01-03 00:24:34 +00:00
# Monitor all
2026-01-03 00:11:21 +00:00
process action:list
2026-01-03 00:24:34 +00:00
# Get results and post to GitHub
process action:log sessionId:XXX
gh pr comment < PR # > --body "< review content > "
2026-01-02 23:58:33 +00:00
```
2026-01-02 23:56:01 +00:00
2026-01-03 00:24:34 +00:00
### Tips for PR Reviews
- **Fetch refs first:** `git fetch origin '+refs/pull/*/head:refs/remotes/origin/pr/*'`
- **Use git diff:** Tell Codex to use `git diff origin/main...origin/pr/XX`
- **Don't checkout:** Multiple parallel reviews = don't let them change branches
- **Post results:** Use `gh pr comment` to post reviews to GitHub
2026-01-02 23:58:33 +00:00
---
## Claude Code
```bash
2026-01-03 00:00:37 +00:00
bash workdir:~/project background:true command:"claude \"Your task\""
2026-01-02 23:56:01 +00:00
```
2026-01-02 23:58:33 +00:00
---
2026-01-02 23:56:01 +00:00
2026-01-02 15:40:03 -08:00
## OpenCode
2026-01-02 23:58:33 +00:00
```bash
2026-01-03 00:00:37 +00:00
bash workdir:~/project background:true command:"opencode run \"Your task\""
2026-01-02 23:58:33 +00:00
```
2026-01-02 15:40:03 -08:00
2026-01-02 23:58:33 +00:00
---
2026-01-02 23:56:01 +00:00
2026-01-03 17:21:17 +01:00
## Pi Coding Agent
```bash
# Install: npm install -g @mariozechner/pi-coding-agent
bash workdir:~/project background:true command:"pi \"Your task\""
```
---
## Pi flags (common)
- `--print` / `-p` : non-interactive; runs prompt and exits.
- `--provider <name>` : pick provider (default: google).
- `--model <id>` : pick model (default: gemini-2.5-flash).
- `--api-key <key>` : override API key (defaults to env vars).
Examples:
```bash
# Set provider + model, non-interactive
bash workdir:~/project background:true command:"pi --provider openai --model gpt-4o-mini -p \"Summarize src/\""
```
---
2026-01-03 17:31:26 +01:00
## tmux (interactive sessions)
2026-01-03 17:21:17 +01:00
2026-01-03 17:31:26 +01:00
Use the tmux skill for interactive coding sessions (always, except very simple one-shot prompts). Prefer bash background mode for non-interactive runs.
2026-01-03 17:21:17 +01:00
---
2026-01-03 19:45:11 +00:00
## Parallel Issue Fixing with git worktrees + tmux
For fixing multiple issues in parallel, use git worktrees (isolated branches) + tmux sessions:
```bash
# 1. Clone repo to temp location
cd /tmp && git clone git@github .com:user/repo.git repo-worktrees
cd repo-worktrees
# 2. Create worktrees for each issue (isolated branches!)
git worktree add -b fix/issue-78 /tmp/issue-78 main
git worktree add -b fix/issue-99 /tmp/issue-99 main
# 3. Set up tmux sessions
SOCKET="${TMPDIR:-/tmp}/codex-fixes.sock"
tmux -S "$SOCKET" new-session -d -s fix-78
tmux -S "$SOCKET" new-session -d -s fix-99
# 4. Launch Codex in each (after pnpm install!)
tmux -S "$SOCKET" send-keys -t fix-78 "cd /tmp/issue-78 && pnpm install && codex --yolo 'Fix issue #78: < description > . Commit and push.'" Enter
tmux -S "$SOCKET" send-keys -t fix-99 "cd /tmp/issue-99 && pnpm install && codex --yolo 'Fix issue #99: < description > . Commit and push.'" Enter
# 5. Monitor progress
tmux -S "$SOCKET" capture-pane -p -t fix-78 -S -30
tmux -S "$SOCKET" capture-pane -p -t fix-99 -S -30
# 6. Check if done (prompt returned)
tmux -S "$SOCKET" capture-pane -p -t fix-78 -S -3 | grep -q "❯ " & & echo "Done!"
# 7. Create PRs after fixes
cd /tmp/issue-78 & & git push -u origin fix/issue-78
gh pr create --repo user/repo --head fix/issue-78 --title "fix: ..." --body "..."
# 8. Cleanup
tmux -S "$SOCKET" kill-server
git worktree remove /tmp/issue-78
git worktree remove /tmp/issue-99
```
**Why worktrees?** Each Codex works in isolated branch, no conflicts. Can run 5+ parallel fixes!
**Why tmux over bash background?** Codex is interactive — needs TTY for proper output. tmux provides persistent sessions with full history capture.
---
2026-01-02 23:58:33 +00:00
## ⚠️ Rules
2026-01-02 23:56:01 +00:00
2026-01-03 00:11:21 +00:00
1. **Respect tool choice** — if user asks for Codex, use Codex. NEVER offer to build it yourself!
2026-01-02 23:58:33 +00:00
2. **Be patient** — don't kill sessions because they're "slow"
2026-01-03 00:00:37 +00:00
3. **Monitor with process:log** — check progress without interfering
2026-01-03 00:11:21 +00:00
4. ** --full-auto for building** — auto-approves changes
5. **vanilla for reviewing** — no special flags needed
2026-01-03 00:24:34 +00:00
6. **Parallel is OK** — run many Codex processes at once for batch work
2026-01-03 00:35:51 +00:00
7. **NEVER start Codex in ~/clawd/** — it'll read your soul docs and get weird ideas about the org chart! Use the target project dir or /tmp for blank slate chats
2026-01-04 14:32:47 +00:00
8. **NEVER checkout branches in ~/Projects/clawdbot/** — that's the LIVE Clawdbot instance! Clone to /tmp or use git worktree for PR reviews
2026-01-04 03:19:02 +01:00
---
## PR Template (The Razor Standard)
When submitting PRs to external repos, use this format for quality & maintainer-friendliness:
2026-01-04 14:30:43 +01:00
````markdown
2026-01-04 03:19:02 +01:00
## Original Prompt
[Exact request/problem statement]
## What this does
[High-level description]
**Features:**
- [Key feature 1]
- [Key feature 2]
**Example usage:**
```bash
# Example
command example
```
## Feature intent (maintainer-friendly)
[Why useful, how it fits, workflows it enables]
## Prompt history (timestamped)
- YYYY-MM-DD HH:MM UTC: [Step 1]
- YYYY-MM-DD HH:MM UTC: [Step 2]
## How I tested
**Manual verification:**
1. [Test step] - Output: `[result]`
2. [Test step] - Result: [result]
**Files tested:**
- [Detail]
- [Edge cases]
## Session logs (implementation)
- [What was researched]
- [What was discovered]
- [Time spent]
## Implementation details
**New files:**
- `path/file.ts` - [description]
**Modified files:**
- `path/file.ts` - [change]
**Technical notes:**
- [Detail 1]
- [Detail 2]
---
*Submitted by Razor 🥷 - Mariano's AI agent*
2026-01-05 06:55:22 +00:00
````
2026-01-04 03:19:02 +01:00
**Key principles:**
1. Human-written description (no AI slop)
2. Feature intent for maintainers
3. Timestamped prompt history
4. Session logs if using Codex/agent
**Example:** https://github.com/steipete/bird/pull/22