Agent skill

session-codex

Use when delegating a task to Codex CLI with session persistence across turns.

Stars 7
Forks 1

Install this agent skill to your Project

npx add-skill https://github.com/vre/flow-state/tree/main/session-codex

SKILL.md

Codex Session

Direct (review, analysis, quick edits — no git)

First run:

bash
codex exec --json --full-auto "prompt"

Following runs:

bash
codex exec resume --json --full-auto ${THREAD_ID} "follow-up prompt"

Worktree (implementation — sandboxed with git)

Claude prepares worktree with .git rename to bypass Codex's hardcoded .git denylist:

  1. git worktree add .worktrees/${NAME} -b ${NAME} main
  2. Copy .env* files, run uv sync where needed
  3. Rename git directory and create pointer:
bash
mv .worktrees/${NAME}/.git .worktrees/${NAME}/.git-codex-sandbox-workaround
printf 'gitdir: .git-codex-sandbox-workaround\n' > .worktrees/${NAME}/.git

Prepend to every prompt: "IMPORTANT: Git data is at .git-codex-sandbox-workaround. Prefix ALL git commands with GIT_DIR=.git-codex-sandbox-workaround."

First run:

bash
codex exec --json -s workspace-write -c 'approval_policy="never"' -C .worktrees/${NAME} "${PROMPT}"

Following runs (resume does not support -s/-C, use -c for config overrides):

bash
codex exec resume --json -c 'sandbox_permissions=["disk-full-read-access","disk-write-access"]' -c 'approval_policy="never"' ${THREAD_ID} "${PROMPT}"

Response parsing

Parse first JSONL line: {"type":"thread.started","thread_id":"<id>"} → set ${THREAD_ID}. Response: lines where item.type == "agent_message"item.text.

If Codex returns error or empty output: show stderr, STOP. Use Bash timeout >= 300000 for long-running tasks.

Security

workspace-write sandbox is kernel-enforced (Seatbelt/Landlock): writes restricted to CWD + subdirs, network blocked. The .git rename bypasses the hardcoded denylist while keeping filesystem isolation. This is safer than danger-full-access which has no restrictions at all.

Didn't find tool you were looking for?

Be as detailed as possible for better results