From sentinel
Invoke OpenAI Codex CLI (GPT-5.4) non-interactively to get a second opinion, critique, or real-time web search from within a Claude Code session. Use when the user says "ask codex", "call codex", "get codex's opinion", "second opinion from codex", "codex review", or wants to consult Codex on code, architecture, or any technical question. CRITICAL ROUTING RULE: When the user wants Codex to perform a web search (current info, latest versions, recent news), ALWAYS use this skill (--search flag) — never codex:rescue, which cannot do web search. Input: natural-language question, optionally with code context, via stdin heredoc. Output: plain-text analysis from a temp file (or structured JSON via --output-schema). Requires codex-cli installed (`codex` binary in PATH, auth via `codex login`).
How this skill is triggered — by the user, by Claude, or both
Slash command
/sentinel:call-codexThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Invoke OpenAI Codex CLI non-interactively to get a second opinion or critique, then present the result.
Invoke OpenAI Codex CLI non-interactively to get a second opinion or critique, then present the result.
Each invocation MUST use mktemp for atomic unique path creation and restrict permissions:
umask 077
CODEX_OUT=$(mktemp /tmp/codex_output_XXXXXXXX)
cat <<'PROMPT' | codex exec --full-auto --skip-git-repo-check --ephemeral -o "$CODEX_OUT" -
<your prompt here>
Do NOT modify any files. Do NOT run any shell commands. Only output your analysis as text.
PROMPT
When the prompt explicitly requires current or real-time information (news, latest versions, recent events), place --search before the exec subcommand:
cat <<'PROMPT' | codex --search exec --full-auto --skip-git-repo-check --ephemeral -o "$CODEX_OUT" -
<your prompt here>
Do NOT modify any files. Do NOT run any shell commands. Only output your analysis as text.
PROMPT
Important: --search is a top-level codex flag, NOT an exec flag. It must come before exec.
When the caller wants structured JSON output, write a JSON Schema to a temp file and pass it via --output-schema:
SCHEMA_FILE=$(mktemp /tmp/codex_schema_XXXXXXXX)
cat > "$SCHEMA_FILE" <<'SCHEMA'
{ "type": "object", "properties": { ... }, "required": [ ... ] }
SCHEMA
cat <<'PROMPT' | codex exec --full-auto --skip-git-repo-check --ephemeral --output-schema "$SCHEMA_FILE" -o "$CODEX_OUT" -
<your prompt here>
Do NOT modify any files. Do NOT run any shell commands.
PROMPT
rm -f "$SCHEMA_FILE"
Then read $CODEX_OUT for the clean response.
Construct the prompt. Combine the user's request with relevant context (file contents, code snippets, error messages). Always append: Do NOT modify any files. Do NOT run any shell commands. Only output your analysis as text.
Determine invocation mode:
Generate a secure unique output path. Use mktemp with umask 077:
umask 077
CODEX_OUT=$(mktemp /tmp/codex_output_XXXXXXXX)
Run the command with timeout. Wrap the invocation with a timeout supervisor (180s default). On macOS, use a background watchdog pattern since GNU timeout is not available:
TIMEOUT_SECS=180
(
cat <<'PROMPT' | codex exec --full-auto --skip-git-repo-check --ephemeral -o "$CODEX_OUT" -
<prompt>
PROMPT
) &
CODEX_PID=$!
( sleep "$TIMEOUT_SECS" && kill -TERM "$CODEX_PID" 2>/dev/null ) &
WATCHDOG_PID=$!
wait "$CODEX_PID" 2>/dev/null
CODEX_RC=$?
kill "$WATCHDOG_PID" 2>/dev/null
wait "$WATCHDOG_PID" 2>/dev/null 2>&1
IMPORTANT: Do NOT use run_in_background. The output file must be fully written before reading.
Classify the result. Use the error classification table below.
Retry if eligible. If the failure is transient (empty/missing output only), retry once with a fresh mktemp path. Preserve the first attempt's exit code and stderr for diagnostics. Do NOT retry non-zero exits from codex itself — those indicate deterministic failures.
Read the output. Read the file at $CODEX_OUT for Codex's response. The -o file contains only the agent's final message (stdout includes session metadata).
Clean up. Remove the temp output file after reading:
rm -f "$CODEX_OUT"
Present the result. Summarize or relay Codex's response to the user. If the user asked for a comparison, contrast Codex's view with your own.
After running codex, classify the outcome:
| Condition | Category | Retryable? | Action |
|---|---|---|---|
command -v codex fails | codex-not-installed | No | Tell user: install with brew install codex or see OpenAI docs |
| Exit code 137/143 or watchdog killed | timed-out | No | Report timeout, suggest increasing TIMEOUT_SECS or simplifying prompt |
$CODEX_OUT does not exist | empty-output | Yes (once) | Retry with fresh mktemp path |
$CODEX_OUT exists but is empty (0 bytes) | empty-output | Yes (once) | Retry with fresh mktemp path |
| Non-zero exit + stderr contains "auth" or "login" or "unauthorized" | auth-failed (best-effort) | No | Tell user to run codex login or check credentials |
| Any other non-zero exit | exec-error | No | Report exit code and stderr to user for diagnosis |
| Exit 0 + non-empty output | success | N/A | Present result |
Retry rules:
empty-output conditions — these are plausibly transientmktemp path for the retry attempt| Flag | Purpose |
|---|---|
exec | Non-interactive subcommand (required for scripted use) |
--full-auto | Skips confirmation prompts (alias for -a on-request --sandbox workspace-write) |
--skip-git-repo-check | Run outside or independent of current git repo |
--ephemeral | No persistent session state on disk (stateless by design) |
-o "$CODEX_OUT" | Write final message to unique file for clean reading |
- (trailing) | Read prompt from stdin (avoids shell quoting issues) |
--search | Top-level flag (before exec): enable native web search tool |
--output-schema <FILE> | Path to JSON Schema file for structured output validation |
-m <model> to override the default model (default: gpt-5.4)-C /path to set a different working directory for CodexUser asks: "Ask codex to review my sort function in utils.py"
utils.py to get the sort function codeumask 077
CODEX_OUT=$(mktemp /tmp/codex_output_XXXXXXXX)
cat <<'PROMPT' | codex exec --full-auto --skip-git-repo-check --ephemeral -o "$CODEX_OUT" -
Review the following Python sort function for correctness, efficiency, and style:
<contents of the sort function>
Do NOT modify any files. Do NOT run any shell commands. Only output your critique as text.
PROMPT
$CODEX_OUT (the unique path from mktemp)rm -f "$CODEX_OUT"User asks: "Ask codex what the latest React version is and what changed"
umask 077
CODEX_OUT=$(mktemp /tmp/codex_output_XXXXXXXX)
cat <<'PROMPT' | codex --search exec --full-auto --skip-git-repo-check --ephemeral -o "$CODEX_OUT" -
What is the latest stable version of React? What are the key changes in this release?
Do NOT modify any files. Do NOT run any shell commands. Only output your analysis as text.
PROMPT
/tmp/codex_output.md. Always use mktemp for atomic unique file creation.run_in_background for the codex command. The output file must be fully written before you read it. Running in background causes a race condition.umask 077 before mktemp to restrict temp file permissions (owner read/write only). This prevents other users from reading prompt content or responses.--full-auto grants write access to the sandbox.'PROMPT' to prevent $variable expansion and `backtick` execution in the prompt text.--ephemeral to avoid accumulating session state on disk for one-shot analysis calls.codex is not found, inform the user to install it (brew install codex or see OpenAI docs).mktemp path, and re-run.--search flag goes before exec, not after. codex --search exec ... is correct; codex exec --search ... is NOT.npx claudepluginhub touricks/fanshi_personal_skills --plugin sentinelRuns OpenAI Codex CLI as a subagent for second opinions, code reviews, and questions. Useful when you want a different AI model's perspective.
Consults OpenAI Codex (GPT-5) via CLI for code investigation, debugging, or review. Runs read-only with full project access; activates on 'ask codex' phrases or /ask-codex.
Use when the user asks to run Codex CLI (codex exec, codex resume) or references OpenAI Codex for code analysis, refactoring, or automated editing