2 2
3> For the complete documentation index, see [llms.txt](https://learn.chatgpt.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to the page URL.3> For the complete documentation index, see [llms.txt](https://learn.chatgpt.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to the page URL.
4 4
5Codex Security helps security and engineering teams find, confirm, and fix5Run a standard scan of a local repository with the standalone Codex Security
6vulnerabilities. Use its command-line interface (CLI) to scan6CLI. This quickstart ends with a saved report you can review and revisit.
7repositories you own or have permission to assess, review findings over time,7For scans inside a Codex conversation, use the [Codex Security
8and check changes before they land.8plugin](https://learn.chatgpt.com/docs/security/plugin).
9
10The `@openai/codex-security` package is public. Scans using OpenAI inference
11 require Codex Security access. For an interactive scan in Codex, start with
12 the [Codex Security plugin quickstart](https://learn.chatgpt.com/docs/security/plugin). For connected
13 GitHub repositories, see [Codex Security cloud setup](https://learn.chatgpt.com/docs/security/setup).
14 9
15## Check the prerequisites10## Check the prerequisites
16 11
17The CLI requires Node.js 22 (22.13.0 or later), 24, or 26. Scans, bulk scans,12You need Node.js 22 (22.13.0 or later), 24, or 26, plus Python 3.10 or later.
18exports, scan history, and saved findings also require Python 3.10 or later.13Python 3.10 also needs `tomli`. Scans using OpenAI inference require Codex Security access.
19For more detail, see [Authentication and14Depending on your account and repository, full-repository scans may also
20prerequisites](https://learn.chatgpt.com/docs/security/cli/reference#authentication-and-prerequisites).15require [Trusted Access for Cyber](https://chatgpt.com/cyber).
16
17The CLI runs with your operating-system permissions and doesn't pause for
18approval.
19Scan processes can inherit your environment, so remove unrelated credentials
20before starting. See [Local scan
21permissions](https://learn.chatgpt.com/docs/security/cli/reference#local-scan-permissions).
21 22
22## Set up and verify the CLI23## Set up and verify the CLI
23 24
24Run the CLI with `npx` and check its version:25Run the public package with `npx`:
25 26
26```bash27```bash
27npx @openai/codex-security --version28npx @openai/codex-security --version
28```29```
29 30
30To see both the package version and the version of its bundled plugin, run:31The command prints the installed package version. Use `info --json` to check
31 32the bundled plugin version, or `--help` to list commands. Package changes are
32```bash33listed in the [CLI and SDK releases](https://github.com/openai/codex-security/releases).
33npx @openai/codex-security info --json
34```
35
36See the [CLI and SDK releases](https://github.com/openai/codex-security/releases)
37for package changes.
38
39List the available commands:
40
41```bash
42npx @openai/codex-security --help
43```
44
45See also [CLI reference](https://learn.chatgpt.com/docs/security/cli/reference).
46 34
47## Sign in35## Sign in
48 36
52npx @openai/codex-security login40npx @openai/codex-security login
53```41```
54 42
55On a remote or headless machine, use device authentication:43On a machine without a browser, add `--device-auth` and follow the displayed
56 44sign-in instructions. Use `--auth chatgpt` in the scan commands below to select
57```bash45that sign-in even when your environment also contains an API key.
58npx @openai/codex-security login --device-auth
59```
60
61For CI and other automated workflows, set an OpenAI API key:
62
63```bash
64export OPENAI_API_KEY="<your-api-key>"
65```
66 46
67For Amazon Bedrock, follow the [Amazon Bedrock47For API keys and other providers, see [Select scan
68setup](https://learn.chatgpt.com/docs/security/cli/reference#use-amazon-bedrock) instead of signing in48authentication](https://learn.chatgpt.com/docs/security/cli/reference#select-scan-authentication).
69with ChatGPT or setting an OpenAI API key. Check [Bedrock release49For Amazon Bedrock, use [AWS credentials and model
70status](https://learn.chatgpt.com/docs/security/cli/reference#bedrock-release-status) to see what your50access](https://learn.chatgpt.com/docs/security/cli/reference#use-amazon-bedrock) instead of a ChatGPT
71installed version supports.51sign-in or OpenAI API key.
72
73For [OpenRouter or
74Fireworks](https://learn.chatgpt.com/docs/security/cli/reference#use-openrouter-or-fireworks), set the
75provider's API key and select a model with `--provider` and `--model`.
76
77To use your ChatGPT sign-in when an API key is also set, select it explicitly:
78
79```bash
80npx @openai/codex-security scan . --auth chatgpt
81```
82
83To require the environment API key, select API-key authentication:
84
85```bash
86npx @openai/codex-security scan . --auth api-key
87```
88
89Depending on your account and repository, full-repository scans may also
90require [Trusted Access for Cyber](https://chatgpt.com/cyber).
91 52
92## Prepare a scan53## Prepare a scan
93 54
94Choose a repository you trust and have permission to assess. Scans use your55Replace these paths with your repository and a new results directory outside
95local operating-system permissions and don't pause for approval. Scan56its Git worktree:
96processes can inherit your environment, so remove unrelated credentials before
97you start. See [Local scan
98permissions](https://learn.chatgpt.com/docs/security/cli/reference#local-scan-permissions).
99
100Choose a directory outside the repository for the scan results:
101 57
102```bash58```bash
103REPOSITORY=/path/to/repository59REPOSITORY=/path/to/repository
104SCAN_DIR=/path/outside/repository/codex-security-results60SCAN_DIR=/path/outside/repository/codex-security-results
105```61```
106 62
107If you omit `--output-dir`, Codex Security saves results in its own persistent63Results can include source excerpts and vulnerability details. Choose a private
108state directory. Results can include source excerpts and vulnerability details,64location. If you omit `--output-dir`, the CLI uses its persistent state directory.
109so choose a private location and an appropriate retention policy.
110
111If the default state directory isn't writable, select a writable directory
112outside the scanned repository:
113 65
114```bash66Check the target and output location:
115export CODEX_SECURITY_STATE_DIR=/path/outside/repository/codex-security-state
116```
117
118Check the repository, target, and output directory before starting a scan:
119 67
120```bash68```bash
121npx @openai/codex-security scan "$REPOSITORY" --output-dir "$SCAN_DIR" --dry-run69npx @openai/codex-security scan "$REPOSITORY" \
70 --auth chatgpt --output-dir "$SCAN_DIR" --dry-run
122```71```
123 72
124The dry run checks local inputs, including any `--knowledge-base` paths,73A successful dry run confirms the local inputs. It doesn't start a scan, load
125without starting Codex, loading credentials, or probing the plugin's Python74credentials, or check the plugin's Python interpreter, so it doesn't establish
126interpreter.75that authentication and runtime setup will succeed.
127 76
128## Run your first scan77## Run your first scan
129 78
130Run a standard scan and keep its results in the selected directory:79Remove `--dry-run` to start the scan:
131 80
132```bash81```bash
133npx @openai/codex-security scan "$REPOSITORY" --output-dir "$SCAN_DIR"82npx @openai/codex-security scan "$REPOSITORY" \
83 --auth chatgpt --output-dir "$SCAN_DIR"
134```84```
135 85
136Interactive terminals show a live scan dashboard. Add `--headless` to show86An interactive terminal shows a live dashboard. Non-interactive terminals show progress
137plain progress lines instead. CI and terminals without an interactive session87lines. Add `--headless` to use progress lines in an interactive terminal too.
138use plain progress automatically.88The dashboard and saved logs can contain source code or credentials. Review
139 89them before sharing.
140The dashboard also shows live session details. These can contain source code
141or credentials, so review them before sharing.
142 90
143By default, the CLI writes scan progress and its completion summary to stderr.91When the scan finishes, stderr includes the report path, finding count, and
144It doesn't print the full scan result to stdout. A completed scan prints a92elapsed time. For example:
145summary like this:
146 93
147```text94```text
148 REPORT /path/outside/repository/codex-security-results/report.md95 REPORT /path/outside/repository/codex-security-results/report.md
149 96
150 FINDINGS 2 (2 confirmed this scan; 0 previously found; 1 high, 1 medium)97 FINDINGS 2 (2 confirmed this scan; 0 previously found; 1 high, 1 medium)
151 COVERAGE complete
152 ELAPSED 42s98 ELAPSED 42s
153 RESULTS /path/outside/repository/codex-security-results99 RESULTS /path/outside/repository/codex-security-results
154```100```
155 101
156Token usage and estimated cost appear when available. To print the complete102By default, the severity of a finding doesn't cause a scan to fail. For
157result as machine-readable JSON, request structured output explicitly:103machine-readable stdout, add `--json`. To make findings fail a CI check, set a
158 104[severity policy](https://learn.chatgpt.com/docs/security/cli/ci#choose-a-severity-policy).
159```bash
160npx @openai/codex-security scan "$REPOSITORY" --output-dir "$SCAN_DIR" --json
161```
162
163Scans are report-only by default, so findings remain available for local
164review. You may want to add a severity threshold when you are ready to [run scans in
165CI](https://learn.chatgpt.com/docs/security/cli/ci).
166
167## Choose a model and reasoning effort
168
169Scans use `gpt-5.6-sol` with `xhigh` reasoning effort by default. Select a
170different model and effort when the task requires them. Choose a model your
171credentials can access. If you use ChatGPT sign-in, check [GPT-6.1 Sol
172availability](https://learn.chatgpt.com/docs/models#gpt-6.1-sol) before using this example:
173
174```bash
175npx @openai/codex-security scan "$REPOSITORY" \
176 --model gpt-6.1-sol \
177 --effort medium
178```
179
180
181Available effort levels depend on the selected model. The CLI supports `minimal`,
182`low`, `medium`, `high`, `xhigh`, and `max`; GPT-6.1 Sol requires at least `low`.
183 105
184## Review the results106## Review the results
185 107
186Open `report.md` for the readable result. The scan directory also contains the108Open `report.md` from the reported directory. Confirm the target and revision,
187structured files used by automation:109then read the coverage before reviewing individual findings.
188
189```text
190codex-security-results/
191├── scan-manifest.json
192├── findings.json
193├── coverage.json
194├── report.md
195├── artifacts/
196└── exports/
197 └── results.sarif # when produced
198```
199
200- `scan-manifest.json` records the target, scope, producer, and sealed
201 artifacts.
202- `findings.json` records severity, confidence, locations, evidence, and
203 remediation for each finding.
204- `coverage.json` records reviewed surfaces, exclusions, deferred work, open
205 questions, and coverage completeness.
206
207Coverage can be `complete`, `partial`, or `unknown`. Read any deferred areas or
208open questions before treating the scan as evidence of review.
209The [CLI reference](https://learn.chatgpt.com/docs/security/cli/reference#scan-artifacts) describes
210the full artifact and output contract.
211
212## Review and patch findings
213
214After a complete interactive scan with findings, the CLI offers a finding
215browser. Review the evidence and choose which findings to fix. You can find
216the saved tasks in the Codex desktop app.
217
218To patch high and critical findings without the browser:
219
220```bash
221npx @openai/codex-security scan "$REPOSITORY" \
222 --patch --patch-severity high --json
223```
224
225Add `--create-pr` to commit verified patches and open a GitHub pull request.
226
227You can also patch saved findings or import Linear issues. See the
228[`validate` and `patch` reference](https://learn.chatgpt.com/docs/security/cli/reference#codex-security-validate-and-codex-security-patch).
229
230## Choose the next scan
231
232Use a path scan when a repository contains separate services or packages:
233
234```bash
235npx @openai/codex-security scan "$REPOSITORY" \
236 --path services/billing \
237 --path packages/auth
238```
239
240Review committed changes between the base revision and `HEAD`:
241
242```bash
243npx @openai/codex-security scan "$REPOSITORY" --diff origin/main --head HEAD
244```
245
246Review staged and unstaged changes against `HEAD`:
247
248```bash
249npx @openai/codex-security scan "$REPOSITORY" --working-tree --base HEAD
250```
251
252Diff and working-tree scans expect the repository argument to be the Git
253worktree root. Fetch the selected revisions before starting a diff scan.
254
255Use deep mode when a repository or path needs broader review:
256
257```bash
258npx @openai/codex-security scan "$REPOSITORY" --mode deep
259```
260
261To control workers, subagents, and when the scan stops:
262
263```bash
264npx @openai/codex-security scan "$REPOSITORY" \
265 --mode deep \
266 --workers 2 \
267 --subagents 0 \
268 --stop-after-no-new 3 \
269 --max-discovery-runs 10 \
270 --max-time-hours 1.5
271```
272
273These options require deep mode, which supports repository and path targets,
274not diff or working-tree scans. Here, `--workers` controls independent
275standard-scan workers within one scan; `bulk-scan --workers` controls concurrent
276repository scans. `--max-time-hours` accepts a positive number up to `96`,
277including fractional hours. At the limit, the scan stops unfinished workers,
278preserves completed scan results, and aggregates them into the final report.
279
280## Add architecture and security context
281
282Provide architecture documents, threat models, or security policies as scan
283context. This helps Codex Security evaluate findings against how your system
284actually works:
285
286```bash
287npx @openai/codex-security scan "$REPOSITORY" \
288 --knowledge-base /path/to/architecture.md \
289 --knowledge-base /path/to/security-policies
290```
291
292## Add custom scan instructions
293
294Add instructions that focus the scan on your security priorities. Use a
295second file for follow-up instructions:
296
297```bash
298npx @openai/codex-security scan "$REPOSITORY" \
299 --scan-prompt-file /path/to/scan.md \
300 --post-scan-prompt-file /path/to/follow-up.md
301```
302
303The follow-up runs in the same authenticated session after successful scans
304and scans with incomplete coverage or errors. If the follow-up fails, the CLI
305reports a warning and keeps the completed scan. It doesn't run after
306cancellation or a scan that reaches its cost limit. Both options also work
307with `bulk-scan`; a CSV `prompt` column adds repository-specific instructions.
308
309## Set a scan budget
310
311Use `--max-cost` to stop a scan when its estimated model cost exceeds a limit
312in USD:
313
314```bash
315npx @openai/codex-security scan "$REPOSITORY" --max-cost 5
316```
317
318Requests already in progress can finish slightly above the limit. If a deep
319scan reaches the limit after Codex Security aggregates completed worker
320results, the CLI saves the completed report, marks its coverage as `partial`,
321and returns exit code `2`. If the scan can't produce a completed report, any
322available partial output stays on disk.
323
324## Scan changes before each commit
325
326Install a Git pre-commit security check for your repository:
327
328```bash
329npx @openai/codex-security install-hook
330```
331
332The check scans staged and unstaged changes before each commit. It blocks
333high-severity findings and scan errors without replacing an existing
334pre-commit script.
335
336## Scan repositories in bulk
337
338Sign in to GitHub before discovering repositories:
339
340```bash
341gh auth login
342```
343
344Discover and select repositories from your GitHub account or organization:
345
346```bash
347npx @openai/codex-security bulk-scan
348```
349
350The interactive flow excludes archived repositories and forks. It asks you to
351confirm the selected repositories before scanning.
352
353To scan a prepared repository list, provide a CSV and an output directory:
354
355```bash
356npx @openai/codex-security bulk-scan repositories.csv \
357 --output-dir /path/outside/repositories/security-scans \
358 --workers 4
359```
360 110
361Run the same command again to resume an existing bulk scan. Codex Security111Check `scan.status` in `scan-manifest.json` to confirm that the scan completed.
362skips completed repositories. Add `--max-attempts 3` when you want to retry112Review `coverage.json` for reviewed surfaces, excluded paths, deferred work,
363temporary repository or scan errors.113and open questions.
364 114
365For GitHub discovery, CSV preparation, campaign results, and Docker setup, see115A completed scan exits with `0` unless findings meet a configured severity
366[Run bulk security scans](https://learn.chatgpt.com/docs/security/cli/bulk-scans).116threshold, which returns `1`. Coverage gaps don't change the exit code, so
117exit `0` doesn't mean every file was reviewed. Input, execution, result-integrity,
118or required-output failures return `2`. The
119[CLI reference](https://learn.chatgpt.com/docs/security/cli/reference#exit-codes-and-signals) explains
120the exit codes.
367 121
368## Run bulk scans in Docker122For each finding, check the affected code, attacker prerequisites, validation
123evidence, and remaining uncertainty. A source-based finding doesn't necessarily
124include a successful runtime reproduction. Select a finding for remediation
125only after its evidence supports the claimed issue.
369 126
370If your access includes the Codex Security Docker image, use the supplied127Keep the scan directory together when sharing or archiving it. It contains
371hardened Compose configuration and security profile on a Linux Docker host.128`scan-manifest.json`, `findings.json`, and `coverage.json` alongside the report
372The host must support unprivileged user namespace creation. Supply a repository129and supporting artifacts. See [Scan
373CSV, keep results and sign-in state in persistent mounted directories, and130artifacts](https://learn.chatgpt.com/docs/security/cli/reference#scan-artifacts) for the full layout.
374provide credentials through your environment or a secret manager:
375
376```bash
377docker compose run --rm codex-security \
378 bulk-scan /input/repositories.csv \
379 --output-dir /output \
380 --workers 4
381```
382
383The container runs bulk scans without interactive prompts. Use the CLI outside
384Docker when you want to discover repositories interactively. For private
385repositories, provide `GH_TOKEN` or `GITHUB_TOKEN` through your environment or
386secret manager. The [sign-in requirements](#sign-in), including account and
387repository access, also apply to containerized scans.
388 131
389## Revisit a saved scan132## Revisit a saved scan
390 133
391List the saved scans for your repository:134List scans for the repository:
392 135
393```bash136```bash
394npx @openai/codex-security scans list "$REPOSITORY"137npx @openai/codex-security scans list "$REPOSITORY"
395```138```
396 139
397Copy a scan ID from the results to inspect its findings and configuration:140Copy a scan ID from the results:
398 141
399```bash142```bash
400npx @openai/codex-security scans show SCAN_ID143npx @openai/codex-security scans show SCAN_ID
401```144```
402 145
403To inspect the saved events from a scan and its workers:146After a complete interactive scan with findings, the CLI also offers a finding
404 147browser. Review the evidence there before choosing a fix. For saved findings,
405```bash148use the [validate and patch
406npx @openai/codex-security scans logs SCAN_ID149commands](https://learn.chatgpt.com/docs/security/cli/reference#codex-security-validate-and-codex-security-patch).
407```
408
409Saved logs aren't redacted and can contain source code or credentials. Review
410them before sharing.
411
412List open findings across the repository's scans:
413 150
414```bash151## Choose the next scan
415npx @openai/codex-security findings list "$REPOSITORY"
416```
417
418An earlier finding stays open when the latest scan doesn't confirm it.
419
420To mark a reviewed finding as a false positive, explain why the finding doesn't
421apply:
422
423```bash
424npx @openai/codex-security findings false-positive FINDING_OCCURRENCE_ID \
425 --reason "The route already checks permissions"
426```
427
428Later scans consider that explanation but still recheck the current code.
429
430Run the same scan against the current checkout using its original configuration:
431
432```bash
433npx @openai/codex-security scans rerun SCAN_ID
434```
435
436Compare two scans to find new, persisting, reopened, resolved, or unknown
437findings:
438
439```bash
440npx @openai/codex-security scans compare PREVIOUS_SCAN_ID CURRENT_SCAN_ID
441```
442
443The comparison automatically matches findings by root cause and reuses saved
444matches.
445
446For the bulk-scan CSV format, scan-history filters, and command options, see
447the [CLI reference](https://learn.chatgpt.com/docs/security/cli/reference).
448
449Continue with the workflow that fits your goal:
450 152
451- [Run bulk security scans](https://learn.chatgpt.com/docs/security/cli/bulk-scans) to discover GitHub153| Goal | Guide |
452 repositories or scan a pinned CSV inventory.154| ---------------------------------------- | ---------------------------------------------------------------------------------------- |
453- [Read the CLI FAQ](https://learn.chatgpt.com/docs/security/cli/faq) for answers about scan history,155| Scan selected paths or a diff | [Select the scan target](https://learn.chatgpt.com/docs/security/cli/reference#select-the-scan-target) |
454 false-positive feedback, coverage, and fix verification.156| Use deep scans or limit their runtime | [Configure deep scans](https://learn.chatgpt.com/docs/security/cli/reference#configure-deep-scans) |
455- [Run scans in CI](https://learn.chatgpt.com/docs/security/cli/ci) to review pull requests, preserve157| Supply architecture or security policies | [Add security context](https://learn.chatgpt.com/docs/security/cli/reference#add-security-context) |
456 results, and set a severity policy.158| Change the model or reasoning effort | [Configure the runtime](https://learn.chatgpt.com/docs/security/cli/reference#configure-the-runtime) |
457- [Use the CLI reference](https://learn.chatgpt.com/docs/security/cli/reference) to check every flag,159| Set an estimated cost limit | [Output and policy options](https://learn.chatgpt.com/docs/security/cli/reference#set-output-and-policy-options) |
458 output format, artifact, and exit code.160| Scan multiple repositories | [Bulk scans](https://learn.chatgpt.com/docs/security/cli/bulk-scans) |
459- [Integrate the TypeScript SDK](https://learn.chatgpt.com/docs/security/sdk) to run scans from an161| Check pull requests automatically | [CI guide](https://learn.chatgpt.com/docs/security/cli/ci) |
460 application or developer tool.162
163For authentication problems, repeat-scan differences, or false-positive
164feedback, see the [CLI FAQ](https://learn.chatgpt.com/docs/security/cli/faq).