Codex Guard is a small interactive terminal frontend for a Codex App Server process that it starts and owns. It watches the included quota and the account credit balance, steers a running turn near thresholds, and interrupts when the session's paid-credit budget is reached.
⬇ Download Codex Guard for Windows
⬇ Download Codex Guard for Linux
Native executables for each platform, from the latest release. No repository clone, Rust, cargo, administrator privileges or platform flag is needed. Download links become available when the first release is published.
SHA-256 checksums are included with every release. The Guard executable is standalone; Codex CLI is a separate requirement and is not bundled.
Requirements: a recent OpenAI Codex CLI installed and authenticated with your Codex/ChatGPT account, and an interactive terminal.
- Download
codex-guard-windows-x86_64.exeand execute it once, preferably from a terminal in your project directory. - Guard installs itself to
%LOCALAPPDATA%\CodexGuard\bin, adds that directory to your user PATH, and continues running immediately. No administrator privileges are needed. - Open a new terminal, go to any project, and run either command:
cd C:\Projects\my-app
cg
# codex-guard works tooThe current terminal does not receive the persistent PATH change; the first execution supplies it to the installed process itself. These binaries are not signed, so Windows SmartScreen may show a warning for a downloaded executable.
- Download
codex-guard-linux-x86_64. Browser downloads commonly need the executable bit set. - From a terminal, make it executable and run it once (adjust the downloaded file's path if needed):
chmod +x ./codex-guard-linux-x86_64
./codex-guard-linux-x86_64- Guard installs to
~/.local/bin/codex-guard, creates~/.local/bin/cg -> codex-guard, and continues running immediately. - Open a new terminal and run:
cd ~/Projects/my-app
cg
# codex-guard works tooIf ~/.local/bin is already on PATH, no shell configuration is changed. Otherwise Guard uses $SHELL to append an idempotent PATH entry to Bash's ~/.bashrc, Zsh's ~/.zshrc (or $ZDOTDIR/.zshrc), or Fish's ~/.config/fish/config.fish (respecting $XDG_CONFIG_HOME). Fish uses fish_add_path --path, rather than Bash syntax. An unknown shell or a configuration error produces a clear message and still allows the current execution to continue.
Codex Guard always uses the directory from which it was launched as the Codex workspace. In both project examples above, that project directory is the workspace, regardless of where Guard is installed. To use a project on the first downloaded execution, change to the project and invoke the download by its absolute path. Launching via a file manager uses the cwd supplied by that file manager.
The cwd is captured before installation and preserved through reexecution. Guard explicitly sets the App Server process cwd and sends the same workspace in thread/start.cwd and turn/start.cwd. Installation paths never select a workspace.
To update manually, download and run a newer release executable. It replaces the canonical installation and continues with the new copy, preserving cwd and arguments. On Windows, close running Guard sessions before updating so their executables are not locked. Running codex-guard or cg from its installed location does not recopy the binary. An unrelated existing ~/.local/bin/cg is preserved and reported; binaries or aliases elsewhere on PATH are never removed. If another cg takes precedence in PATH, use codex-guard.
--help, --version, config path, config show, and profiles are inspection commands: they do not self-install or start an App Server. A copy or PATH error is reported without deleting the download; Guard continues with the downloaded or installed executable when possible. Global commands may require fixing the reported installation issue.
codex-guard --version
codex-guard 0.1.0
On Windows, the Guard finds the native codex.exe inside a standard global npm installation even when only npm's codex.cmd/codex.ps1 shims are on PATH; it does not launch those shims through a shell. Native codex.exe on PATH also works. For a nonstandard installation, set CODEX_GUARD_CODEX_PATH to the full native executable path (on Linux, to the codex binary path). It uses the documented stdio App Server protocol.
Codex Guard always runs Codex in YOLO mode, with no sandbox and no approvals. Guard controls financial limits and process supervision for long unattended tasks. Permission handling is fixed at the process, thread and turn levels; financial protection remains active.
codex-guard [OPTIONS] [PROMPT...] opens an inline TUI. With no prompt, it starts in READY: the App Server is initialized, but no thread or turn is created until you type a prompt and submit with Ctrl+D or F2. A CLI prompt is an optional shortcut that starts a turn in the same TUI. For example: codex-guard, codex-guard -p conservative, codex-guard -c 5, codex-guard "Fix the backend issue", or codex-guard -p conservative "Review this".
The session stays in the terminal's normal buffer, without alternate screen. Prompts, tool activity, Guard notices and agent messages append to the transcript. The terminal provides scrollback, mouse-wheel scrolling, selection and copy; the transcript remains visible after exit. A persistent bottom pane anchors the composer and its one-line footer to the terminal bottom. New transcript entries are inserted above it. The footer shows lifecycle, model, reasoning effort, session credit spend and remaining quota, reducing detail at smaller widths. The input is a multiline tui-textarea editor. Enter inserts a newline; Ctrl+D submits the prompt or command. F2 is a submit alternative for terminals that do not report Ctrl+D reliably. Cursor keys, Home/End, Backspace and Delete edit at the cursor, and long prompts scroll inside the composer, which grows up to roughly 40% of terminal height. Bracketed paste inserts the entire clipboard text, including newlines, without submitting it. Some Windows terminals/Crossterm combinations deliver paste as ordinary key events instead; Enter still only inserts a newline in that case, so paste cannot start a task. The real terminal cursor follows the editor.
Typing / opens command suggestions immediately above the composer. Matches filter by prefix in stable order, with exact matches first. Up/Down selects a suggestion; Tab completes it without executing. /steer and /budget completion add a trailing space for the argument. Esc dismisses suggestions while preserving the draft. Enter still adds a newline, and Ctrl+D/F2 still submits. Suggestions stay out of the transcript.
/model opens a two-step model and reasoning-effort picker in the bottom pane. Up/Down navigates, Enter selects, and Esc cancels both steps without changing the current selection. The catalog comes from model/list after App Server initialization, with includeHidden=false and every nextCursor page fetched. Models, names, descriptions and supported efforts come from that catalog. Exactly one visible isDefault model is selected initially; if there is no unique default, Guard uses the first visible model. It uses the model's supported defaultReasoningEffort, falling back to its first supported effort if needed; models with no listed efforts omit the effort override. Repeated pagination cursors are rejected, and catalog reads are bounded by timeouts.
If the catalog read fails or returns no visible models, Guard continues using App Server defaults. The footer shows model: default, and /model reports that the catalog is unavailable. The catalog is not an entitlement check: the App Server still determines whether a chosen model can run. Model changes are allowed in READY and COMPLETED; RUNNING and STOPPING refuse /model. A known selection is sent as thread/start.model, and every turn—including follow-ups in the same thread—uses the current turn/start.model and turn/start.effort. /status shows the friendly model name, catalog ID, model slug and reasoning effort.
codex-guard config path prints the platform config location. On Linux this is normally ~/.config/codex-guard/config.toml; on Windows it is under the user's roaming application config directory. The file is optional. Values merge in this order: built-in defaults, top-level config sections, selected profile sections, CLI overrides.
default_profile = "default"
default_mode = "unattended"
[profiles.default.runtime]
max = "4h"
interrupt_grace = "8s"
terminate_grace = "4s"
[profiles.default.quota]
wrap_remaining_percent = 15
critical_remaining_percent = 5
hard_stop = false
[profiles.default.credits]
max_spend = 20.0
finalize_at = 0.75
urgent_finalize_at = 0.90
reserve = 20.0
[profiles.default.monitor]
poll_interval = "60s"
wrap_poll_interval = "30s"
paid_poll_interval = "10s"
critical_poll_interval = "5s"
retry_interval = "5s"
max_consecutive_failures = 2
bell = true
[profiles.default.burn_rate]
window = "10m"
max_credit_spend = 5.0
action = "warn"
[profiles.conservative.runtime]
max = "2h"
[profiles.conservative.credits]
max_spend = 5.0
finalize_at = 0.60
urgent_finalize_at = 0.85codex-guard config show prints the effective profile. codex-guard profiles lists configured profiles. -p, -c/--credits, -t/--time, and --attended override one execution. The default mode is unattended. Examples: codex-guard, codex-guard -p conservative, codex-guard -c 5. Every execution explicitly launches the native process with codex --yolo app-server --stdio, creates threads with approvalPolicy=never and sandbox=danger-full-access, and starts turns with approvalPolicy=never and sandboxPolicy.type=dangerFullAccess. No PowerShell alias or function is consulted. The old Codex mode choice and Guard permission overrides have been removed from the config schema; obsolete global/profile Codex and session sections are ignored for compatibility and cannot re-enable sandboxing or approvals. --attended remains partial: it changes the displayed mode and does not provide interactive approval handling. All modes retain Guard quota monitoring, steering, burn-rate checks, credit budget, hard stop, runtime limits and process supervision.
Commands in the TUI: /help, /status, /model, /logs, /steer TEXT, /budget NUMBER, /profile, /clear, /interrupt, /kill, /quit. /status adds detailed session, quota, billing and agent information to the transcript. /logs prints the last 25 recent log entries there, and /help prints the same centralized command list used by suggestions. No log panel reserves permanent screen space. Slash commands are interpreted only on explicit submit (Ctrl+D or F2), not while pasting or editing. Interrupt requires y; kill requires typing kill; quit with an active turn requires typing quit and interrupts the turn. Exiting prints a compact session summary.
Normal text in READY or COMPLETED starts a turn. A follow-up reuses the existing thread and appends another exchange to the transcript; normal text while a turn is active is rejected, so steering requires /steer TEXT. /interrupt without an active turn reports that no turn exists; /quit without a turn closes normally. /budget without a value shows the session budget.
/clear abandons the current thread/context and appends a new-thread boundary to the transcript. It does not erase the terminal scrollback or JSONL log. The next prompt creates a new thread. During a turn, type clear at the confirmation prompt: Guard interrupts the turn using its normal escalation, then clears the thread only after completion. The App Server stays alive if interruption completes normally. The paid-credit budget, spend ledger, balance baseline, burn-rate history, and session runtime remain unchanged across /clear. Unlike /quit, /clear starts a fresh conversation within the same financially bounded Guard session.
src/app_server.rs: minimal JSONL request/response transport. Critical lifecycle and agent events use a nonblocking queue; tool activity uses a bounded lossy queue. High-frequency deltas are ignored, and rate-limit updates are coalesced. RPC responses remain independent of event backpressure. Rate-limit and optional thread-usage reads time out after 5 seconds; other requests after 15 seconds.turn/steerincludesexpectedTurnId.src/config.rs: persistent profile merge and input validation.src/policy.rs: task ledger, quota and credit state, one-shot steering, burn-rate window.src/supervisor/: Unix session/process group with signals; Windows Job Object withKILL_ON_JOB_CLOSE, plus console Ctrl+Break for a graceful attempt.src/install/: immutable process context, canonical installation detection, staged binary replacement, platform PATH setup,cg, and reexecution. Windows uses only Registry APIs forHKCU\Environment\Pathand broadcastsWM_SETTINGCHANGE; existing entries and string types are preserved. Linux writes shell configuration only when the installation directory is absent from the inherited PATH. Unix replaces the process withexec; Windows waits for the installed child to keep the terminal attached and propagate its exit status.src/app_server/models.rs: typed model catalog, pagination and model/effort selection defaults.src/commands.rs: shared command names, help, descriptions and availability.src/tui.rsandsrc/tui/: anchored inline output, bottom pane, composer, command popup, model picker, transcript and status presentation.- Session-start JSONL includes
workspace,executable_path(Guard),installed_path,version,platform, cwd, inherited PATH, fixed YOLO permissions, resolved Codex executable and App Server arguments for environment diagnosis. Catalog reads and model selections are logged. src/logging.rs: one JSONL event log per run, including a final summary.codex-guardprints the path on exit.
The Guard records the initial credit balance, sums positive decreases on later samples, and retains that sum across turns, quota resets, and balance top-ups. The hard paid-credit budget is for the entire Guard session, not each turn. READY uses normal polling and refreshes the baseline; a fresh account/rateLimits/read is required before every turn/start. Decreases on the same account while idle are conservatively counted, including late charges from a prior turn; top-ups and idle account switches do not erase cumulative spend. A reported hasCredits=false, unlimited=false, and null balance is treated as a finite zero. If credits are available but the balance is unknown, the next turn cannot start. Unlimited balances remain unsupported because a balance-decrease budget cannot be enforced. A failed rate-limit read interrupts immediately while paid or near a threshold. With ample included quota, up to max_consecutive_failures failures are retried at retry_interval; then the turn is interrupted. The credit balance is account-level, so concurrent Codex use on the same account can be counted against this session. Credit charges between samples can exceed a threshold before the Guard observes them. This is a circuit breaker with finite observation latency, not a transactional spending cap.
account/usage/read with the thread id supplies estimated thread credits, USD cost, and model/token breakdown when available. The TUI and JSONL log show this complementary telemetry. It never replaces account-balance decreases for the hard paid-credit budget; failure to fetch it does not stop the task.
Quota steering uses only a reported 300-minute window; weekly display uses only a reported 10080-minute window. If those windows are unavailable, the TUI displays unavailable and the corresponding quota steer does not fire. The quota has no default hard stop. With quota.hard_stop=true, an already exhausted quota prevents turn start, and an exhausted-quota or first paid-debit observation triggers interruption before the policy enters its paid phase. Observation latency means the first charge can still occur before interruption. A 5-hour window reset clears only quota steer debounce for the new window. Financial spend and financial steer debounce remain.
The shutdown sequence sends the turn/interrupt request without awaiting its response in the supervisor loop. interrupt_grace starts when the stop is detected, not when that RPC completes. The Guard then sends a process-level graceful signal/event and, after terminate_grace, forcibly terminates the process tree. A normal turn/completed ends this sequence. On Windows, Job Object assignment happens immediately after spawn. There is a small pre-assignment race, and hosts that forbid assignment to a nested Job Object cause startup to fail. A suspended Windows launch would close that race in a later revision.
The TUI intentionally does not recreate all Codex UI features. Interactive user-input requests from the server are not yet supported: the Guard rejects unsupported requests and interrupts the turn to avoid repeated failed attempts. The App Server's stderr is summarized in the event log. No external web dashboard, cloud telemetry, or semantic loop detection is included.
Contributors need Rust. Build and test commands do not install Guard or start Codex:
cargo fmt --all -- --check
cargo check --all-targets
cargo test --all-targets
cargo build --releaseNormal interactive execution of a built binary also self-installs. Inspection commands such as cargo run -- --version do not.
The tag-only release workflow requires v plus the Cargo.toml version (for example, v0.1.0). It runs Windows and Linux builds independently, tests all host targets and the Linux musl target, and publishes only after both builds pass. Windows uses windows-latest with x86_64-pc-windows-msvc and a statically linked CRT; Linux uses ubuntu-latest with x86_64-unknown-linux-musl and checks that no dynamic loader or shared libraries are required. The current dependency graph does not need a glibc fallback. The workflow installs musl-tools on its Linux runner.
Assets always have stable names: codex-guard-windows-x86_64.exe, codex-guard-linux-x86_64, and SHA256SUMS.txt. The publishing job computes SHA-256 over both final binaries, uploads to a draft, downloads and verifies all assets, then publishes the complete release. An upload or verification failure leaves an unpublished draft for a retry. A normal push to main does not trigger a release. GitHub/browser downloads do not reliably preserve Linux executable permissions; use chmod +x as shown above. No remote auto-update or package-manager installer is included.
Before publishing, use disposable Windows/Linux user accounts to check first installation, a second launch without installation, a downloaded update, PATH behavior in newly opened terminals, and cg name conflicts. Cover Bash, Zsh, Fish and an unknown shell; existing PATH entries, spaces/non-ASCII in paths, unwritable destinations and Windows executables locked by a running session. Confirm that original arguments and the project cwd survive reexecution. On Windows, also check a browser download/SmartScreen and launches from a file manager. On Linux, exercise the musl binary on multiple distributions.
Installation tests use pure functions or temporary mock homes and never write the real Registry or shell configuration. Process builder tests inspect cwd and arguments without launching Codex.
For optional interactive validation after installation:
On Linux:
cd ~/Projects/my-app
cg "Summarize this repository"On Windows (PowerShell):
cd C:\Projects\my-app
cg "Summarize this repository"Before using paid credits, validate the balance fields shown by your installed Codex version, then manually exercise /steer, /interrupt, /kill, quota reset handling, and a deliberately low credit budget with a controlled short task. Do not use a long or expensive task for initial validation.
Also validate the bottom pane in Windows Terminal and a Linux terminal: repeated resize, multiline paste, native scrollback/selection/copy, popup opening and dismissal, long transcripts and terminal restoration after shutdown/error. With a real App Server, confirm the visible catalog and effort choices, cancel each picker step, switch models between follow-ups, refuse /model during an active turn, and verify the selected model/effort in the JSONL turn parameters. Local unit tests use synthetic catalog pages and Ratatui's test backend; they do not launch Codex or consume quota.