---
name: ask-codex
description: Delegate to Codex CLI via `cdx exec` — second opinion, review, diagnosis, research, implementation. Triggers on /ask-codex, "ask codex", "ask gpt", "second opinion from codex/gpt-5", "have codex review/implement/investigate this". Optional model/effort spec; calls cdx exec directly, never through a dispatched subagent.
---

# Ask Codex — Delegate Tasks to Codex CLI

Audience: AI coding agents first. Optimize for model activation, not human readability.

Delegate tasks to Codex (OpenAI coding agent) non-interactively via `cdx exec`, called directly — never via a dispatched Agent/subagent whose only job is to shell out to it.
Use for: research, advice, code review, implementation — anything suited to a subagent or advisor call.

## Invocation

```
/ask-codex [model/effort] <task>
```

`model/effort` is optional first token. Everything after (or everything if no spec) = task prompt.

## Step 1 — Parse model/effort

Match first token against pattern `<model-or-shorthand>/<effort>`. If no match → use defaults.

**Model expansion:**
| Input | Resolved |
|---|---|
| `5.6-terra` | `gpt-5.6-terra` | (default effort: medium)
| `5.6-sol` | `gpt-5.6-sol` | (default effort: low)
| `5.6-luna` | `gpt-5.6-luna` | (default effort: high)
| already `gpt-*` | pass through |
| *(omitted)* | `gpt-5.6-luna` ← default |

Rule: bare version number `5.X[-suffix]` → prepend `gpt-`. Anything starting `gpt-` → unchanged.

**Effort expansion:**
| Input | Resolved |
|---|---|
| `low` | `low` |
| `med` | `medium` |
| `medium` | `medium` |
| `high` | `high` |
| *(omitted)* | use default effort |

**Default effort:**
| Model         | Effort
`gpt-5.6-sol`   | low
`gpt-5.6-terra` | medium
`gpt-5.6-luna`  | high
 
gpt-5.6-luna Effort levels includes: xhigh, max (never use with other models)

## Step 2 — Build prompt

Compose a self-contained prompt for Codex. Include:
- The user's task (verbatim + rephrased if ambiguous)
- Relevant context from current conversation: file paths, code snippets, error messages, constraints
- Expected output shape (analysis, code diff, answer, review findings, etc.)

NEVER pass a bare one-liner if context is available. Codex has no conversation history — front-load everything it needs.

**Orchestration stays in main loop.** Strip invocation wrapper, model/effort, account/profile, and orchestration wording from delegated task. NEVER tell Codex to invoke `/ask-codex`, `cdx`, another coding agent, or delegate implementation. Codex executes task directly; main loop orchestrates and reviews.

```text
# DO NOT — leaks orchestration into implementer prompt
User asked: "use /ask-codex gpt-5.6-luna/max to fix queue retries"

# Target
Fix queue retries in <repo>. Inspect <files>, implement <behavior>, add tests, run <gates>.
```

Exception: include a repo-required skill command only when target repository instructions explicitly require that implementer to load it. A required local skill is execution context, not delegation.

## Step 3 — Run (ONE call, auto-logged)

Call directly from the main loop — do NOT dispatch an Agent/subagent just to shell out to this:

```bash
cdx exec -m "<resolved-model>" -c "model_reasoning_effort=<resolved-effort>" "<prompt>"
```

`cdx exec` auto-captures codex's full stdout+stderr to a logfile and prints ONLY that logfile path on stdout — nothing else, nothing truncatable. Run it ONCE. NEVER re-run to capture output, NEVER pipe/tee/redirect yourself — the wrapper already does it. Logfile lives under `~/.systray-ai/logs/cdx/`, NEVER `/tmp`.

**`cdx exec` is SYNCHRONOUS. It BLOCKS until codex exits. When the Bash call returns, the run is ALREADY COMPLETE.** It is not a fire-and-forget dispatcher, despite the terse stdout. On return it prints a completion banner to **stderr**:

```
cdx: codex exec finished — exit=0 in 22m15s. The run is COMPLETE; do not wait or poll for it.
cdx: log /home/user/.systray-ai/logs/cdx/20260728-223838-528741.log (128.0 KB)
```

**NEVER write a wait/poll loop after `cdx exec`.** DO NOT:

```bash
# reject: waits for a job that already finished; also matches unrelated daemons
cdx exec -m gpt-5.6-sol "..." && while pgrep -f "codex exec" >/dev/null; do sleep 30; done
```

A `pgrep`/`pidof` liveness test on a shared process name matches long-lived daemons (`codex-code-mode-host`) and other repos' runs, so the loop can never exit. Cost of this exact mistake: 8h40m idle on an already-finished run. Canonical: memory `feedback_never_poll_for_completion`.

Judging a genuinely-async job (a background agent) → probe **output growth**, NEVER process existence: `age=$(( $(date +%s) - $(stat -c %Y "$LOG") ))`. A live PID proves nothing — a crash-looping agent holds one for its full timeout while writing zero bytes. Every wait MUST carry a deadline.

NEVER use bare `codex exec`/`codex review`/`codex e` — the deny-gate blocks that exact token (`tools.json` rule `codex-review-raw`). `cdx` is the sanctioned account-routing wrapper (see `tools.json` rule `codex-auth-symlink-mutate`) and does not match the blocked pattern.

**Wrapper OWNS the plumbing flags — do NOT pass them.** For every `exec`, `cdx` injects `--sandbox danger-full-access` (full read/write + network) and `--skip-git-repo-check`. A `-s workspace-write`/`-s read-only` you pass is force-overridden to `danger-full-access` (workspace-write EROFSes the cpu-guard→local-gate shim). So never pass `-s`/`--sandbox`/`--skip-git-repo-check`.

Pass only:
- `-m "<model>" -c "model_reasoning_effort=<effort>"` — pins resolved model/effort; omit → codex silently uses its own config default.

Do NOT add `</dev/null` — `cdx exec` sets stdin to `/dev/null` itself. (Interactive `cdx` subcommands still inherit stdio; only `exec` is captured.)

Optional: `-C <dir>` before the prompt sets codex's working directory. To pin a specific codex account, add `--account=<slug>` (or `--profile=<slug>`) as the first arg after `cdx`, before `exec`.

Full command example:
```bash
cdx exec -m "gpt-5.6-terra" -c "model_reasoning_effort=low" "Review the auth middleware in src/middleware/auth.ts for security issues. Focus on token validation and session handling."
```

## Step 4 — Present result

- The single stdout line IS the logfile path. `Read` that file to get codex's full response.
- Check `cdx`'s exit code — it is codex's own exit code. Non-zero → codex failed (quota, crash, sandbox refusal). Read the logfile for the failure and report it — do NOT present a failed run as a result.
- Show Codex response directly.
- If long: lead with key findings/decisions, then full output.
- Clearly label what is Codex output vs your (Claude) synthesis/additions.
- If Codex made file changes: summarize what changed and verify against user intent before reporting done.

## Quick reference

| Invocation | Model | Effort |
|---|---|---|
| `/ask-codex <task>` | `gpt-5.6-terra` | `low` |
| `/ask-codex 5.6-terra/med <task>` | `gpt-5.6-terra` | `medium` |
| `/ask-codex 5.6-sol/high <task>` | `gpt-5.6-sol` | `high` |
| `/ask-codex gpt-5.6-luna/med <task>` | `gpt-5.6-luna` | `medium` |
| `/ask-codex 5.6-luna/low <task>` | `gpt-5.6-luna` | `low` |
