YouTip LogoYouTip

Codex Noninteractive

Non-interactive mode allows you to use Codex in scripts, CI/CD pipelines, or headless environments. This section details how to configure and use non-interactive mode. * * * ## Basic Usage ### Executing Single Tasks ## Basic exec Command # Execute Simple Tasks codex exec"list Python files in current directory" # Use Double Quotes for Complex Commands codex exec"analyze code structure of src/ directory" ### Reading from Standard Input ## stdin Input # Read from Pipe echo"explain this code"| codex exec--stdin # Read from File codex exec--stdin< task.txt # Multi-line Input cat< Non-interactive mode is ideal for automation tasks and script integration. * * * ## Command Line Arguments ### Common Parameters | Parameter | Description | | --- | --- | | `exec "task"` | Execute specified task | | `--stdin` | Read task from standard input | | `--model, -m` | Specify model | | `--no-auto-approve` | Disable auto-approval | | `--output, -o` | Output to file | ### Complete Example ## Full Parameter Example # Specify Model codex exec-m gpt-5.4-mini "review code" # Output to File codex exec"create README"-o README.md # Disable Auto-Approval codex exec--no-auto-approve"run tests" # Combined Usage codex exec-m gpt-5.4"review PR"--output review.md * * * ## Configuration ### Configuration File Settings ## Configure Non-Interactive Mode # Default settings for non-interactive mode # Default model default_model = "gpt-5.4" # Auto-approve threshold auto_approve_threshold = "medium" # Timeout in seconds timeout = 300 ### Execution Policy In non-interactive mode, the default policy is usually `deny` (reject operations that may have side effects): ## Set Execution Policy # Use ask policy codex exec--approval ask "create file" # Use approve policy (use with caution) codex exec--approval approve "run tests" # Use deny policy (read-only) codex exec--approval deny "analyze code" > For security reasons, operations that may cause side effects are disabled by default in non-interactive mode. * * * ## Shell Script Integration ### Basic Scripts ## Shell Script Example #!/bin/bash # Use Codex for code review codex exec"review code in src/ directory"--output review.md if[$?-eq 0]; then echo"Review completed, results saved to review.md" else echo"Review failed" fi ### Batch Processing ## Batch Processing Script #!/bin/bash # Batch review multiple files for file in $(find src -name"*.py"); do echo"Reviewing: $file" codex exec"review $file file"--output"review_$(basename $file).md" done ### Conditional Execution ## Conditional Execution #!/bin/bash # Decide whether to use Codex based on file count FILE_COUNT=$(find src -name"*.py"|wc -l) if[$FILE_COUNT-gt 10]; then echo"Many files, using Codex for batch review" codex exec"review all Python files"--output full_review.md else echo"Fewer files, reviewing individually" for file in $(find src -name"*.py"); do codex exec"simple review of $file" done fi * * * ## CI/CD Integration ### GitHub Actions ## GitHub Actions Workflow span style="color: green;"> name: Code Review on: jobs: codex-review: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Setup Codex uses: openai/codex-action@v1 - name: Run Code Review run: | codex exec "Review code changes in this PR" --output review.md - name: Upload Review uses: actions/upload-artifact@v4 with: name: code-review path: review.md ### GitLab CI ## GitLab CI Configuration span style="color: #007F45;"> codex_review: image: node:20 before_script: - npm install -g @openai/codex script: - codex exec "Review changes in this merge request" --output review.md artifacts: paths: - review.md ### Jenkins ## Jenkins Pipeline pipeline { agent any stages { stage('Code Review'){ steps { sh 'codex exec "Review changed files" --output review.md' } } } post { always { archiveArtifacts 'review.md' } } } > Integrating Codex into CI/CD workflows enables automated code reviews and quality checks. * * * ## Best Practices ### Output Handling * Use `--output` to save results to a file * Check return codes to determine if execution was successful * Handle potential error cases ### Performance Optimization * Use `gpt-5.4-mini` to reduce costs * Batch process multiple tasks * Set reasonable timeout values ### Security * Avoid using `--approval approve` * Use read-only mode in CI/CD * Protect API keys > When using non-interactive mode in production environments, pay special attention to security concerns. * * * ## Common Issues ### Q: Does non-interactive mode support all features? Most features are supported, but some requiring interactive confirmation might not work. ### Q: How to handle operations requiring confirmation? Use the `--no-auto-approve` parameter, or set execution policies in the configuration file. ### Q: Can output format be customized? Currently supports plain text and Markdown output. ### Q: How to use in Docker? Install Codex into a Docker image, then call it within your CI/CD workflow.
← Codex GithubCodex Mcp β†’