How to Run the Codex Security CLI Before You Commit

How to Run the Codex Security CLI Before You Commit

Aident AI

A glowing amber irregularity is revealed inside a cobalt slab before it crosses a coral threshold.

How to Run the Codex Security CLI Before You Commit

To scan local changes before you commit, run a Codex Security dry run first, then scan the Git working tree against HEAD with results stored in a private directory outside the repository. Review both report.md and coverage.json. A clean finding count is not enough if coverage is partial or unknown.

The shortest safe sequence on macOS or Linux is:

node --version
python3 --version
npx @openai/codex-security@latest --version

SCAN_DIR="$(mktemp -d)"
chmod 700 "$SCAN_DIR"

npx @openai/codex-security@latest scan . \
  --working-tree \
  --base HEAD \
  --output-dir "$SCAN_DIR/results" \
  --max-cost 5 \
  --dry-run

npx @openai/codex-security@latest login

npx @openai/codex-security@latest scan . \
  --working-tree \
  --base HEAD \
  --output-dir "$SCAN_DIR/results" \
  --max-cost 5

The CLI is in beta and requires Codex Security access. Only scan repositories you own or have permission to assess.

Prerequisites

OpenAI's current package requires one of these Node.js versions:

  • Node.js 22.13.0 or later in the Node 22 line;

  • Node.js 24;

  • Node.js 26.

Running a scan or exporting findings also requires Python 3.10 or later. You also need a Git repository, access to Codex Security, and a writable private output directory outside the checkout.

Check the environment before signing in:

node --version
python3 --version
git rev-parse --show-toplevel
npx @openai/codex-security@latest --version
npx @openai/codex-security@latest scan --help

Expected result: Node and Python meet the supported versions, Git prints the current worktree root, and the CLI prints its version and scan options. If Git prints a different root than you expected, change to that directory before using --working-tree or --diff.

Step 1: Create a Private Results Directory

Codex Security results can contain source excerpts and vulnerability details. Keep them outside the repository and restrict access.

On macOS or Linux:

SCAN_DIR="$(mktemp -d)"
chmod 700 "$SCAN_DIR"
printf '%s\n' "$SCAN_DIR"

On Windows PowerShell:

$ScanDir = Join-Path $env:TEMP ("codex-security-" + [guid]::NewGuid())
New-Item -ItemType Directory -Path $ScanDir | Out-Null
$ScanDir

Expected result: the command prints a new directory outside the repository. Do not point --output-dir at a tracked folder. On macOS and Linux, an existing output directory must be private to the current user.

Step 2: Validate the Scan Without Spending or Loading Credentials

Run the working-tree scan with --dry-run:

npx @openai/codex-security@latest scan . \
  --working-tree \
  --base HEAD \
  --output-dir "$SCAN_DIR/results" \
  --max-cost 5 \
  --dry-run

The dry run checks the repository, selected scope, output directory, and isolated Codex configuration. OpenAI documents that it does not load credentials, start Codex, or probe the plugin's Python interpreter.

Expected result: the CLI accepts the repository root, HEAD, and output location without starting a scan. Fix path, revision, or permission errors now. Do not respond to a bad output path by making the whole repository world-writable.

Step 3: Sign In Explicitly

For a local interactive scan, sign in with ChatGPT:

npx @openai/codex-security@latest login
npx @openai/codex-security@latest login status

For a headless machine, use device authentication:

npx @openai/codex-security@latest login --device-auth

For CI, use OPENAI_API_KEY or CODEX_API_KEY from the CI secret manager. Do not put the key in a command, repository file, or scan artifact.

If both a stored ChatGPT login and an environment API key exist, choose the intended identity:

npx @openai/codex-security@latest scan . --working-tree --base HEAD --auth chatgpt

Expected result: login status identifies a usable local sign-in. If access is denied, confirm that the account has Codex Security access and complete any Trusted Access verification requested by OpenAI.

Step 4: Scan Staged and Unstaged Changes

Run the real scan from the Git worktree root:

npx @openai/codex-security@latest scan . \
  --working-tree \
  --base HEAD \
  --output-dir "$SCAN_DIR/results" \
  --max-cost 5

--working-tree --base HEAD reviews staged and unstaged changes against the current commit. The CLI is report-only by default. --max-cost 5 stops when the estimated model cost exceeds five US dollars, although requests already in progress can finish above that estimate.

Expected result: stderr ends with a finding count, severity breakdown, coverage state, elapsed time, result directory, and next step. The result directory contains:

scan-manifest.json
findings.json
coverage.json
report.md
artifacts/
exports

Open report.md for the readable review. Then inspect coverage.json for excluded surfaces, deferred work, and open questions. Coverage can be complete, partial, or unknown.

Step 5: Interpret Exit Codes Correctly

Codex Security uses these important exit codes:

Exit

Meaning

What to do

0

The scan completed with complete coverage and passed its severity policy

Review the report and coverage before committing

1

A completed scan found an issue at or above --fail-on-severity

Triage the finding and rerun the relevant scope

2

Input, runtime, or export failed, or coverage is incomplete

Read the error and coverage.json; do not call this a clean scan

130

The user interrupted with Ctrl-C

Keep partial results only as incomplete evidence

143

SIGTERM stopped the scan

Investigate the termination and rerun

Without --fail-on-severity, findings do not automatically turn the scan into a blocking policy. Add a threshold only when the team is ready to enforce it:

npx @openai/codex-security@latest scan . \
  --diff origin/main \
  --head HEAD \
  --output-dir "$SCAN_DIR/pr-results" \
  --max-cost 5 \
  --fail-on-severity high

Fetch origin/main first so the selected base revision exists locally.

Step 6: Validate a Finding After a Fix

A later scan that omits a finding does not by itself prove the vulnerability is fixed. Use the bundled validator against the completed findings document:

npx @openai/codex-security@latest validate \
  "$SCAN_DIR/results/findings.json" \
  "<finding description and location>"

Expected result: validation directly rechecks the candidate finding. Keep the original report, the code change, and the validation result together for review.

Optional: Install the Pre-Commit Check

After the manual workflow is understood, install the supported hook:

npx @openai/codex-security@latest install-hook

OpenAI says the hook scans staged and unstaged changes before each commit, blocks high-severity findings and scan errors, and does not replace an existing pre-commit script. Inspect the repository's hook setup before enabling it for a team.

Common Failure Modes

Symptom

Likely boundary

Safe response

Node or Python version error

Unsupported local runtime

Upgrade the owning runtime, then repeat the version checks

Access denied after login

Account lacks access or Trusted Access is incomplete

Confirm entitlement instead of changing repository permissions

Output directory rejected

Directory is inside the worktree, nonempty, or not private

Create a fresh private directory outside the repository

--diff cannot resolve a revision

The base ref was not fetched

Fetch the exact base and rerun from the worktree root

Exit 2 with a report

Coverage is partial or the runtime failed

Read coverage.json and resolve deferred or failed surfaces

Authentication prompt is surprising

ChatGPT login and API key are both available

Pass --auth chatgpt or --auth api-key explicitly

Findings seem unrelated to the changed code

Scope or architecture context is too broad

Use --working-tree, selected --path values, or trusted --knowledge-base documents

Why This Order Works

The dry run isolates local path and configuration problems before authentication or model work begins. A private output directory keeps sensitive findings out of Git. Working-tree scope matches the pre-commit question, while the cost limit bounds the first attempt. Finally, reviewing coverage separately from findings prevents a partial scan from looking clean.

This follows the same practical structure that made Aident's Ollama networking guide useful: state the exact task, give reproducible commands, show expected results, name look-alike failures, and explain why the boundary matters. For broader review discipline, see how to verify an agent's tests and how to audit an agent skill before installation.

Verify One Read-Only GitHub Action With Aident Loadout

Codex Security scans the code. Aident Loadout can separately verify that your coding agent can inspect a connected GitHub surface without receiving a pasted provider token.

Install or update Aident Loadout with this prompt:

Follow https://aident.ai/SETUP.md

Then run:

aident account auth status
aident vault vault --action status
aident capabilities search \
  --query "find a connected read-only GitHub Action that searches repository issues"

Inspect the selected Action before any execution:

aident capabilities get --name "<canonical-action-name>"

Use Aident Loadout to inspect one live GitHub Action schema. Measure success as one current schema inspected, zero provider secrets pasted, and zero repository writes.

Sources

Refresh this guide when OpenAI changes the supported Node or Python versions, authentication precedence, scan artifacts, coverage contract, exit codes, cost controls, or pre-commit hook behavior.

Home

Home

Home

Integrations

Integrations

Integrations

Vault

Vault

Vault

Audit

Audit

Audit

Arana Grande

Arana Grande

Arana Grande

Free

Free

Free

30-day audit summary

30-day audit summary

30-day audit summary

Daily action-call volume and the latest receipts from the Loadout audit trail.

Daily action-call volume and the latest receipts from the Loadout audit trail.

Daily action-call volume and the latest receipts from the Loadout audit trail.

View Audit

View Audit

View Audit

Loadout usage

Loadout usage

Loadout usage

617 action calls in the last 30 days

617 action calls in the last 30 days

617 action calls in the last 30 days

May 19 - Jun 17

May 19 - Jun 17

May 19 - Jun 17

10 active days

10 active days

10 active days

Less

Less

Less

More

More

More

Recent activity

Recent activity

Recent activity

Latest action-call receipts from connected agents

Latest action-call receipts from connected agents

Latest action-call receipts from connected agents

Apr 23, 09:23 AM

Apr 23, 09:23 AM

Apr 23, 09:23 AM

Shopify

Shopify

Shopify

Creates Or Updates An Asset For A Theme

Creates Or Updates An Asset For A Theme

Creates Or Updates An Asset For A Theme

Success

Success

Success

Apr 23, 09:21 AM

Apr 23, 09:21 AM

Apr 23, 09:21 AM

Shopify

Shopify

Shopify

Update Products Param Product Id

Update Products Param Product Id

Update Products Param Product Id

Success

Success

Success

Apr 23, 08:53 AM

Apr 23, 08:53 AM

Apr 23, 08:53 AM

Shopify

Shopify

Shopify

Update Products Param Product Id

Update Products Param Product Id

Update Products Param Product Id

Failed

Failed

Failed

Apr 22, 22:13 PM

Apr 22, 22:13 PM

Apr 22, 22:13 PM

Shopify

Shopify

Shopify

Create Product Image

Create Product Image

Create Product Image

Success

Success

Success

Apr 22, 22:12 PM

Apr 22, 22:12 PM

Apr 22, 22:12 PM

Shopify

Shopify

Shopify

Create Product Image

Create Product Image

Create Product Image

Success

Success

Success

Connected integration coverage

Connected integration coverage

Connected integration coverage

162

162

162

of 753 accessible connected

of 753 accessible connected

of 753 accessible connected

Callable actions

Callable actions

Callable actions

1,126

1,126

1,126

Vault credentials

Vault credentials

Vault credentials

8

8

8

Explore what's possible

Explore what's possible

Explore what's possible

See all Integrations

See all Integrations

See all Integrations

Google Ads

Google Ads

Google Ads

All available Goolge Ads tools via...

All available Goolge Ads tools via...

All available Goolge Ads tools via...

X (twitter)

X (twitter)

X (twitter)

All available X tools via...

All available X tools via...

All available X tools via...

Github

Github

Github

All available Github tools via...

All available Github tools via...

All available Github tools via...

Notion

Notion

Notion

All available Notion tools via...

All available Notion tools via...

All available Notion tools via...

Slack

Slack

Slack

All available Slack tools via...

All available Slack tools via...

All available Slack tools via...

Firecrawl

Firecrawl

Firecrawl

All available Firecrawl tools via...

All available Firecrawl tools via...

All available Firecrawl tools via...

753 integrations are available for loadouts.

753 integrations are available for loadouts.

753 integrations are available for loadouts.

Plug your entire stack into your AI agents.

Plug your entire stack into your AI agents.

Plug your entire stack into your AI agents.

Skip the integration headache. Plug 750+ tools into Claude Code, Codex, and OpenClaw in one go, and let your agents execute today.

Skip the integration headache. Plug 750+ tools into Claude Code, Codex, and OpenClaw in one go, and let your agents execute today.