`codex exec --json` now maps to the behavior of `codex exec
--experimental-json` with new event and item shapes.
Thread events:
- thread.started
- turn.started
- turn.completed
- turn.failed
- item.started
- item.updated
- item.completed
Item types:
- assistant_message
- reasoning
- command_execution
- file_change
- mcp_tool_call
- web_search
- todo_list
- error
Sample output:
<details>
`codex exec "list my assigned github issues" --json | jq`
```
{
"type": "thread.started",
"thread_id": "01999ce5-f229-7661-8570-53312bd47ea3"
}
{
"type": "turn.started"
}
{
"type": "item.completed",
"item": {
"id": "item_0",
"item_type": "reasoning",
"text": "**Planning to list assigned GitHub issues**"
}
}
{
"type": "item.started",
"item": {
"id": "item_1",
"item_type": "mcp_tool_call",
"server": "github",
"tool": "search_issues",
"status": "in_progress"
}
}
{
"type": "item.completed",
"item": {
"id": "item_1",
"item_type": "mcp_tool_call",
"server": "github",
"tool": "search_issues",
"status": "completed"
}
}
{
"type": "item.completed",
"item": {
"id": "item_2",
"item_type": "reasoning",
"text": "**Organizing final message structure**"
}
}
{
"type": "item.completed",
"item": {
"id": "item_3",
"item_type": "assistant_message",
"text": "**Assigned Issues**\n- openai/codex#3267 – “stream error: stream disconnected before completion…” (bug) – last update 2025-09-08\n- openai/codex#3257 – “You've hit your usage limit. Try again in 4 days 20 hours 9 minutes.” – last update 2025-09-23\n- openai/codex#3054 – “reqwest SSL panic (library has no ciphers)” (bug) – last update 2025-09-03\n- openai/codex#3051 – “thread 'main' panicked at linux-sandbox/src/linux_run_main.rs:53:5:” (bug) – last update 2025-09-10\n- openai/codex#3004 – “Auto-compact when approaching context limit” (enhancement) – last update 2025-09-26\n- openai/codex#2916 – “Feature request: Add OpenAI service tier support for cost optimization” – last update 2025-09-12\n- openai/codex#1581 – “stream error: stream disconnected before completion: stream closed before response.complete; retrying...” (bug) – last update 2025-09-17"
}
}
{
"type": "turn.completed",
"usage": {
"input_tokens": 34785,
"cached_input_tokens": 12544,
"output_tokens": 560
}
}
```
</details>
114 lines
3.9 KiB
Rust
114 lines
3.9 KiB
Rust
use clap::Parser;
|
|
use clap::ValueEnum;
|
|
use codex_common::CliConfigOverrides;
|
|
use std::path::PathBuf;
|
|
|
|
#[derive(Parser, Debug)]
|
|
#[command(version)]
|
|
pub struct Cli {
|
|
/// Action to perform. If omitted, runs a new non-interactive session.
|
|
#[command(subcommand)]
|
|
pub command: Option<Command>,
|
|
|
|
/// Optional image(s) to attach to the initial prompt.
|
|
#[arg(long = "image", short = 'i', value_name = "FILE", value_delimiter = ',', num_args = 1..)]
|
|
pub images: Vec<PathBuf>,
|
|
|
|
/// Model the agent should use.
|
|
#[arg(long, short = 'm')]
|
|
pub model: Option<String>,
|
|
|
|
#[arg(long = "oss", default_value_t = false)]
|
|
pub oss: bool,
|
|
|
|
/// Select the sandbox policy to use when executing model-generated shell
|
|
/// commands.
|
|
#[arg(long = "sandbox", short = 's', value_enum)]
|
|
pub sandbox_mode: Option<codex_common::SandboxModeCliArg>,
|
|
|
|
/// Configuration profile from config.toml to specify default options.
|
|
#[arg(long = "profile", short = 'p')]
|
|
pub config_profile: Option<String>,
|
|
|
|
/// Convenience alias for low-friction sandboxed automatic execution (-a on-failure, --sandbox workspace-write).
|
|
#[arg(long = "full-auto", default_value_t = false)]
|
|
pub full_auto: bool,
|
|
|
|
/// Skip all confirmation prompts and execute commands without sandboxing.
|
|
/// EXTREMELY DANGEROUS. Intended solely for running in environments that are externally sandboxed.
|
|
#[arg(
|
|
long = "dangerously-bypass-approvals-and-sandbox",
|
|
alias = "yolo",
|
|
default_value_t = false,
|
|
conflicts_with = "full_auto"
|
|
)]
|
|
pub dangerously_bypass_approvals_and_sandbox: bool,
|
|
|
|
/// Tell the agent to use the specified directory as its working root.
|
|
#[clap(long = "cd", short = 'C', value_name = "DIR")]
|
|
pub cwd: Option<PathBuf>,
|
|
|
|
/// Allow running Codex outside a Git repository.
|
|
#[arg(long = "skip-git-repo-check", default_value_t = false)]
|
|
pub skip_git_repo_check: bool,
|
|
|
|
/// Path to a JSON Schema file describing the model's final response shape.
|
|
#[arg(long = "output-schema", value_name = "FILE")]
|
|
pub output_schema: Option<PathBuf>,
|
|
|
|
#[clap(skip)]
|
|
pub config_overrides: CliConfigOverrides,
|
|
|
|
/// Specifies color settings for use in the output.
|
|
#[arg(long = "color", value_enum, default_value_t = Color::Auto)]
|
|
pub color: Color,
|
|
|
|
/// Print events to stdout as JSONL.
|
|
#[arg(long = "json", alias = "experimental-json", default_value_t = false)]
|
|
pub json: bool,
|
|
|
|
/// Whether to include the plan tool in the conversation.
|
|
#[arg(long = "include-plan-tool", default_value_t = false)]
|
|
pub include_plan_tool: bool,
|
|
|
|
/// Specifies file where the last message from the agent should be written.
|
|
#[arg(long = "output-last-message")]
|
|
pub last_message_file: Option<PathBuf>,
|
|
|
|
/// Initial instructions for the agent. If not provided as an argument (or
|
|
/// if `-` is used), instructions are read from stdin.
|
|
#[arg(value_name = "PROMPT")]
|
|
pub prompt: Option<String>,
|
|
}
|
|
|
|
#[derive(Debug, clap::Subcommand)]
|
|
pub enum Command {
|
|
/// Resume a previous session by id or pick the most recent with --last.
|
|
Resume(ResumeArgs),
|
|
}
|
|
|
|
#[derive(Parser, Debug)]
|
|
pub struct ResumeArgs {
|
|
/// Conversation/session id (UUID). When provided, resumes this session.
|
|
/// If omitted, use --last to pick the most recent recorded session.
|
|
#[arg(value_name = "SESSION_ID")]
|
|
pub session_id: Option<String>,
|
|
|
|
/// Resume the most recent recorded session (newest) without specifying an id.
|
|
#[arg(long = "last", default_value_t = false, conflicts_with = "session_id")]
|
|
pub last: bool,
|
|
|
|
/// Prompt to send after resuming the session. If `-` is used, read from stdin.
|
|
#[arg(value_name = "PROMPT")]
|
|
pub prompt: Option<String>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, ValueEnum)]
|
|
#[value(rename_all = "kebab-case")]
|
|
pub enum Color {
|
|
Always,
|
|
Never,
|
|
#[default]
|
|
Auto,
|
|
}
|