Codex Security CLI reference
Arguments, output formats, scan artifacts, providers, and exit codes for the Codex Security CLI.
Use this reference to check the supported codex-security commands, flags,
output formats, and exit behavior. For a guided first scan, start with the
CLI quickstart.
Install the published package in your project:
npm install @openai/codex-securityInvoke the installed package as npx @openai/codex-security. You can use
codex-security directly when the executable is available on your PATH.
Command overview
usage: codex-security [--version] <command> [options]The CLI provides these commands:
| Command | Purpose |
|---|---|
codex-security scan |
Run a Codex Security scan. |
codex-security install-hook |
Install a Git pre-commit security scan. |
codex-security bulk-scan |
Discover repositories and run resumable bulk scans. |
codex-security scans |
List, inspect, match, rerun, and compare saved scans. |
codex-security findings |
Review and update saved security findings. |
codex-security export |
Export completed findings as CSV, JSON, or SARIF. |
codex-security validate |
Check one or more candidate security findings. |
codex-security patch |
Patch one or more security issues. |
codex-security login |
Sign in, store credentials, or check sign-in status. |
codex-security logout |
Remove the stored sign-in. |
codex-security info |
Show read-only SDK and bundled-plugin metadata. |
The CLI also provides these integration commands:
| Command | Purpose |
|---|---|
codex-security completions |
Generate shell completion scripts. |
codex-security mcp |
Register the CLI as an MCP server. |
codex-security skills |
Sync Codex Security skills to agents. |
List all available commands:
npx @openai/codex-security --helpAdd --help to a command to inspect its arguments and options:
npx @openai/codex-security scan --helpcodex-security --version prints the installed version and exits.
codex-security info --json reports the SDK and bundled-plugin versions.
Neither command requires Python.
Discover commands and connect agents
Print the agent-readable command manifest:
npx @openai/codex-security --llmsInspect the scan argument schema as JSON:
npx @openai/codex-security scan --schema --format jsonGenerate shell completions for Bash:
npx @openai/codex-security completions bashReplace bash with zsh or fish for those shells.
Scan results support --format toon|json|yaml|jsonl and --full-output. This
framework-level --format is separate from --export-format, which selects
the format of an artifact exported from a completed scan. Global command help
also lists md, but scan results don't support Markdown output.
Register the CLI as an MCP server:
npx @openai/codex-security mcp addSync Codex Security skills to your agents:
npx @openai/codex-security skills addMCP exposes only the read-only info metadata command. Scans, exports,
authentication, validation, and patching remain CLI-only.
codex-security scan
Run a scan against a repository, selected paths, committed changes, or the working tree.
usage: codex-security scan [-h] [--auth {auto,chatgpt,api-key}]
[--provider {openai,openrouter,fireworks,amazon-bedrock}]
[--path PATH | --diff BASE | --working-tree]
[--head HEAD] [--base BASE]
[--knowledge-base PATH]
[--mode {standard,deep}] [--model MODEL]
[--effort {minimal,low,medium,high,xhigh}]
[--output-dir DIR]
[--archive-existing]
[--plugin-path PATH] [--python PATH]
[--codex KEY=VALUE] [--fail-on-severity LEVEL]
[--max-cost USD] [--dry-run] [--verbose]
[--json] [--format {toon,json,yaml,jsonl}]
[--full-output] [repository]repository defaults to the current directory.
Select scan authentication
Use --auth auto, the default, to select credentials automatically. When both
a ChatGPT sign-in and OPENAI_API_KEY or CODEX_API_KEY are available,
interactive scans with text output ask which credential to use. CI, JSON and
JSONL scans, and other scans without an interactive terminal use the
environment API key. Dry runs don't prompt or load credentials.
To use your stored credentials, pass --auth chatgpt:
npx @openai/codex-security scan . --auth chatgptTo use an environment API key, pass --auth api-key:
npx @openai/codex-security scan . --auth api-keyTo make stored credentials the automatic default, run
unset OPENAI_API_KEY CODEX_API_KEY.
Use Amazon Bedrock
Select Amazon Bedrock with --provider amazon-bedrock and specify an explicit
Bedrock model with --model:
npx @openai/codex-security scan . \
--provider amazon-bedrock \
--model openai.gpt-5.6-solSet AWS_REGION and authenticate with AWS_BEARER_TOKEN_BEDROCK, standard AWS
access keys, an AWS profile, web identity, container credentials, or the
default AWS credential chain. Bedrock scans use AWS credentials instead of
--auth, ChatGPT sign-in, or an OpenAI API key. Both scan and bulk-scan
support --provider.
Select the scan target
Choose one target type for each scan.
| Argument | Description |
|---|---|
--path PATH |
Scan a path relative to the repository. Repeat the flag for more paths. |
--diff BASE |
Scan committed changes from BASE to --head. The head defaults to HEAD. |
--head HEAD |
Set the head revision for --diff. |
--working-tree |
Scan staged and unstaged changes against --base. The base defaults to HEAD. |
--base BASE |
Set the base revision for --working-tree. |
--mode {standard,deep} |
Select the scan mode. The default is standard. |
--path, --diff, and --working-tree are mutually exclusive. --head
requires --diff, and --base requires --working-tree. Deep mode supports
repository and path targets.
Diff and working-tree scans require the repository argument to be the Git worktree root. The selected refs must exist in that checkout.
Scan the entire repository:
npx @openai/codex-security scan .Scan selected paths:
npx @openai/codex-security scan . --path src --path testsScan committed changes:
npx @openai/codex-security scan . --diff origin/main --head HEADScan staged and unstaged changes:
npx @openai/codex-security scan . --working-tree --base HEADRun a deeper review of the repository:
npx @openai/codex-security scan . --mode deepAdd security context
Use --knowledge-base PATH to provide architecture documents, threat models,
or security policies. Repeat the option for more files or directories:
npx @openai/codex-security scan . \
--knowledge-base /path/to/architecture.md \
--knowledge-base /path/to/security-policiesSupported documents include .md, .markdown, .txt, .pdf, and .docx
files. The CLI searches directories recursively, rejects linked input paths,
skips linked directory entries, and keeps extracted document content
outside the saved scan results.
Set output and policy options
Use these options to keep artifacts, preserve earlier results, or create a machine-readable result.
| Argument | Description |
|---|---|
--output-dir DIR |
Write scan artifacts to a private directory outside the enclosing Git worktree. Defaults to persistent Codex Security state. |
--archive-existing |
Move existing results to DIR.previous-<timestamp>-<id> and start with an empty output directory. Requires --output-dir. |
--fail-on-severity LEVEL |
Return exit 1 when a completed scan reports a finding at or above critical, high, medium, or low. |
--max-cost USD |
Stop a scan when its estimated model cost exceeds the specified USD amount. |
--dry-run |
Check the repository, target, output directory, and Codex configuration without starting a scan. |
--verbose |
Print redacted lifecycle, authentication, progress, and cost diagnostics to stderr. |
--json |
Print manifest, findings, coverage, paths, and turn metadata as one JSON document. |
--format FORMAT |
Print the complete scan result as toon, json, yaml, or jsonl. |
--full-output |
Print the complete result using the default structured output format. |
The cost limit is an estimate, not a hard spending cap. Requests already in progress can finish above the limit, and partial scan results remain available.
When you omit --output-dir, results persist under
$CODEX_HOME/state/plugins/codex-security/scans/<repository>. CODEX_HOME
defaults to ~/.codex. Set CODEX_SECURITY_STATE_DIR to keep results under
$CODEX_SECURITY_STATE_DIR/scans/<repository> instead. These directories can
contain source excerpts and vulnerability details, so manage their permissions
and retention accordingly.
The workbench keeps scan history in
$CODEX_HOME/state/plugins/codex-security/workbench.sqlite3. Setting
CODEX_SECURITY_STATE_DIR also moves the workbench database.
The output directory must be outside the scanned directory and any enclosing
Git worktree. A scan can replace an existing result directory with
--archive-existing.
To preserve earlier results before reusing an output directory:
npx @openai/codex-security scan . \
--output-dir /path/outside/repository/results \
--archive-existingScans are report-only by default. Add --fail-on-severity to evaluate a
severity policy in CI:
npx @openai/codex-security scan . \
--diff origin/main \
--output-dir /path/outside/repository/results \
--json \
--fail-on-severity high \
> /path/outside/repository/codex-security.jsonA dry run checks local inputs without loading credentials, starting Codex, or probing the plugin's Python interpreter:
npx @openai/codex-security scan . \
--output-dir /path/outside/repository/results \
--dry-runConfigure the runtime
Use runtime options when you need an explicit model, interpreter, plugin, or Codex configuration value.
| Argument | Description |
|---|---|
--auth {auto,chatgpt,api-key} |
Select the scan credentials. The default is auto. |
--provider {openai,openrouter,fireworks,amazon-bedrock} |
Select the inference provider. The default is openai. |
--model MODEL |
Select the model. The default is gpt-5.6-sol. Required with --provider amazon-bedrock. |
--effort {minimal,low,medium,high,xhigh} |
Select the model's reasoning effort. The default is xhigh. |
--plugin-path PATH |
Use a Codex Security plugin directory or ZIP to override the bundled plugin. |
--python PATH |
Select the Python interpreter for the plugin runtime. |
--codex KEY=VALUE |
Override an isolated Codex configuration value. Values use TOML syntax. Repeat the flag for more values. |
To select a different model and reasoning effort without writing TOML:
npx @openai/codex-security scan . --model gpt-5.6-terra --effort highQuote string values passed through --codex so the TOML parser receives a
string:
npx @openai/codex-security scan . --codex 'model="gpt-5.6-terra"'codex-security install-hook
Install a Git pre-commit security check for the current repository:
npx @openai/codex-security install-hookThe check scans staged and unstaged changes before each commit and blocks
high-severity findings or scan errors. It respects core.hooksPath and does
not replace an existing pre-commit script. Set a different severity threshold
when needed:
npx @openai/codex-security install-hook . --fail-on-severity mediumcodex-security bulk-scan
Discover and scan GitHub repositories, or run a resumable scan from a repository CSV:
For a complete guide to GitHub discovery, CSV inventories, campaign results, and containerized scans, see Run bulk security scans.
usage: codex-security bulk-scan [input] [--output-dir DIR]
[--workers N] [--mode {standard,deep}]
[--provider {openai,openrouter,fireworks,amazon-bedrock}]
[--model MODEL]
[--effort {minimal,low,medium,high,xhigh}]
[--max-attempts N] [--plugin-path PATH]
[--python PATH] [--codex KEY=VALUE]Run npx @openai/codex-security bulk-scan without arguments to select
repositories interactively. This flow requires a GitHub CLI sign-in.
To choose a model and reasoning effort during interactive discovery:
npx @openai/codex-security bulk-scan --model gpt-5.6-terra --effort highFor a prepared repository list, provide a CSV and --output-dir:
npx @openai/codex-security bulk-scan repositories.csv \
--output-dir /path/outside/repositories/security-scans \
--workers 4The CSV requires id, repository, and revision columns. Revisions must be
full commit hashes. Optional scope and mode columns configure individual
repositories:
id,repository,revision,scope,mode
service,https://github.com/example/service.git,0123456789abcdef0123456789abcdef01234567,src,standard--workers limits simultaneous scans and defaults to 4. --mode defaults to
standard, and --max-attempts defaults to 1. Set --max-attempts when
you want to retry a repository after an error. Run the same command again to
resume a bulk scan from its existing output directory. The CLI skips completed
repositories only when their recorded result artifacts are still present.
For containerized campaigns, see Run bulk scans in Docker.
codex-security scans
Find saved scans
List saved scans for the current directory:
npx @openai/codex-security scansList scans for a different repository:
npx @openai/codex-security scans list /path/to/repositoryFind scans stored under a specific output directory:
npx @openai/codex-security scans list --scan-root /path/outside/repository/resultsInspect or repeat a scan
Show a saved scan's results and configuration:
npx @openai/codex-security scans show SCAN_IDRerun the scan against the current checkout using its original configuration:
npx @openai/codex-security scans rerun SCAN_IDMatch and compare findings
Match findings that share the same root cause across two scans:
npx @openai/codex-security scans match PREVIOUS_SCAN_ID CURRENT_SCAN_IDCompare the matched scans to find new, persisting, reopened, resolved, and unknown findings:
npx @openai/codex-security scans compare PREVIOUS_SCAN_ID CURRENT_SCAN_IDA finding is unknown when the later scan has incomplete coverage or doesn't
cover the finding's original location. Add --force to match when you need to
recompute an existing match.
To match all completed scans for the current repository, including scans from other checkouts:
npx @openai/codex-security scans match --allScan results can vary even when you rerun the same configuration. Matching and
comparison track changes; they don't make results deterministic or prove that a
vulnerability no longer exists. Use validate to recheck a security-critical
finding against the current code.
codex-security findings
Record a reviewed finding as a false positive:
usage: codex-security findings false-positive OCCURRENCE_ID
--reason REASONInspect the saved scan to identify the finding occurrence:
npx @openai/codex-security scans show SCAN_IDRecord a specific explanation for the false positive:
npx @openai/codex-security findings false-positive FINDING_OCCURRENCE_ID \
--reason "The framework escapes this input before it reaches the query"The reason must not be empty. Codex Security saves the decision for the repository and provides it as context to future scans. Each scan independently rechecks the current source, controls, and reachability. A previous decision doesn't suppress a rule, path, or vulnerability class.
codex-security export
Export CSV, JSON, or SARIF from a completed, sealed scan. Export validates the scan artifacts before writing output and leaves the Codex runtime and credentials untouched.
usage: codex-security export [--export-format {csv,json,sarif}]
[--output FILE|-] [--source-root PATH]
[--python PATH] scan_dirscan_dir is the completed scan directory.
| Argument | Description |
|---|---|
--export-format {csv,json,sarif} |
Select the export format. The default is sarif. |
--output FILE|- |
Write the selected format to a file or stdout. Defaults to a file in the current directory. |
--source-root PATH |
Add source-line fingerprints to SARIF using a repository checkout. |
--python PATH |
Select the Python interpreter for the bundled exporter. |
--source-root works only with --export-format sarif. JSON preserves
the sealed findings document. CSV contains portable finding columns and does
not include local workbench triage state.
Without --output, the CLI writes SARIF to results.sarif, JSON to
findings.json, and CSV to findings.csv in the current working directory.
Exports can contain source excerpts and vulnerability details. Run the command
outside the repository or pass --output with a private path outside the
scanned checkout.
Write SARIF to a file:
npx @openai/codex-security export /path/to/scan \
--export-format sarif \
--source-root /path/to/repository \
--output /path/outside/repository/exports/results.sarifWrite SARIF to stdout:
npx @openai/codex-security export /path/to/scan \
--export-format sarif \
--source-root . \
--output -Export findings as JSON:
npx @openai/codex-security export /path/to/scan \
--export-format json \
--output /path/outside/repository/exports/findings.jsonExport findings as CSV:
npx @openai/codex-security export /path/to/scan \
--export-format csv \
--output /path/outside/repository/exports/findings.csvcodex-security validate and codex-security patch
Check whether a candidate finding is valid:
npx @openai/codex-security validate findings.json \
"Possible SQL injection in src/query.ts:42"Generate a fix with the bundled remediation skill:
npx @openai/codex-security patch findings.json \
"Missing authorization check in src/routes.ts:18"Each argument can contain literal text or point to a file. Both commands work
against the current directory. Use validate to directly recheck an original
finding after a fix or when a later scan no longer reports it. A scan
comparison alone doesn't prove that a fix worked. External tools can use these
commands without rebuilding the scanner.
Use --effort to select reasoning effort for either command:
npx @openai/codex-security validate "Possible SQL injection" --effort highcodex-security login, logout, and info
Sign in interactively:
npx @openai/codex-security loginUse device authentication on a remote or headless machine:
npx @openai/codex-security login --device-authCheck the current sign-in:
npx @openai/codex-security login statusRemove the stored sign-in:
npx @openai/codex-security logoutStore an API key by passing it on stdin:
printenv OPENAI_API_KEY | npx @openai/codex-security login --with-api-keyStore an enterprise access token:
printenv CODEX_ACCESS_TOKEN | npx @openai/codex-security login --with-access-tokenInspect read-only SDK and bundled-plugin metadata:
npx @openai/codex-security info --jsonWhen you expose the CLI as an MCP server, info is the only available command.
Scans, exports, sign-in, validation, and patching remain CLI-only.
Read scan output
By default, scans send progress, completion summaries, and errors to stderr
without writing the complete scan result to stdout. Request --json,
--format, or --full-output to send structured scan results to stdout.
Verbose diagnostics
Add --verbose to print redacted lifecycle, authentication, progress, and cost
diagnostics to stderr:
npx @openai/codex-security scan . --verboseSet CODEX_SECURITY_LOG_LEVEL=debug to enable the same diagnostics without the
flag. LOG_LEVEL=debug also enables diagnostics when
CODEX_SECURITY_LOG_LEVEL is unset.
These logging controls apply only to the CLI. Credentials and provider identifiers remain redacted, and structured scan results remain on stdout.
Completion summary
A completed scan writes its finding count, severity breakdown, coverage, elapsed time, report path, and result directory to stderr. It includes token usage and estimated cost when available:
codex-security: Findings: 4 (1 critical, 2 high, 1 informational). Coverage: complete.
codex-security: Elapsed: 1s.
codex-security: Tokens: 1,250 input, 200 cached, 30 output.
codex-security: Report: /path/to/scan/report.md
codex-security: Results: /path/to/scanInformational findings count toward the summary total. Severity policies
evaluate only critical, high, medium, and low findings.
JSON output
scan --json writes one complete JSON document to stdout. Its top-level shape
is:
manifest
findings
coverage
scanDir
threadId
reportPath
artifactsDir
sarifPath
turn
id
status
durationMs
finalResponse
usageProgress, completion summaries, archive notices, and errors remain on stderr.
A completed scan still prints the full JSON result when a severity policy
returns exit 1 or incomplete coverage returns exit 2.
Scan artifacts
A completed scan keeps the readable report and structured artifacts together:
<scan-directory>/
├── scan-manifest.json
├── findings.json
├── coverage.json
├── report.md
├── artifacts/
└── exports/
└── results.sarif # when producedThe structured files serve different jobs:
| File | Contents |
|---|---|
scan-manifest.json |
Scan identity, status, target, scope, producer, and sealed artifact records. |
findings.json |
Finding identifiers, severity, confidence, taxonomy, locations, evidence, validation, data flow, reachability, and remediation. |
coverage.json |
Reviewed surfaces, exclusions, deferred work, open questions, and coverage completeness. |
report.md |
Readable scan report. |
artifacts/ |
Supporting scan artifacts. |
exports/results.sarif |
SARIF generated during the scan, when present. |
Coverage completeness has three values:
complete: The scan records complete coverage for its selected scope.partial: The scan records deferred work or other coverage limits.unknown: The scan reports coverage completeness as unknown.
Review deferred surfaces, explicit exclusions, and open questions before using coverage as evidence for a security decision.
Exit codes and signals
The CLI uses these exit codes:
| Exit | Condition |
|---|---|
0 |
A scan completed with complete coverage and passed its severity policy, a bulk scan completed without failures, or another command succeeded. |
1 |
A completed scan reports a finding at or above the configured severity. |
2 |
The CLI found an input, runtime, or export error, a scan has incomplete coverage, or a bulk scan has repositories with errors. |
130 |
Ctrl-C interrupted a scan. |
143 |
SIGTERM terminated a scan. |
Any scan with partial or unknown coverage returns 2, even without a
severity policy. When you request structured output, completed scans still
write the available results to stdout. The CLI prints the location of any
partial output after an interruption or runtime error.
Authentication and prerequisites
Set OPENAI_API_KEY or CODEX_API_KEY, sign in with
npx @openai/codex-security login, or use an existing file-backed Codex
sign-in. For Amazon Bedrock, use a Bedrock API key or the standard AWS
credential chain instead.
For credential selection, see Select scan authentication.
For CI, keep the API key scoped to the scan step and use a trusted workflow.
The CLI requires Node.js 22 or later. Running a scan or exporting findings also
requires Python 3.10 or later. Python 3.10 also requires tomli. Use --python
or PYTHON to select an interpreter when automatic discovery is unsuitable.
Continue with the CLI quickstart, bulk-scan guide, CLI FAQ, CI guide, or TypeScript SDK guide.
Plain-text aliases
- --output FILE|-