core-agent-ide/codex-rs
Michael Bolin 6fcc528a43
fix: provide tolerance for apply_patch tool (#993)
As explained in detail in the doc comment for `ParseMode::Lenient`, we
have observed that GPT-4.1 does not always generate a valid invocation
of `apply_patch`. Fortunately, the error is predictable, so we introduce
some new logic to the `codex-apply-patch` crate to recover from this
error.

Because we would like to avoid this becoming a de facto standard (as it
would be incompatible if `apply_patch` were provided as an actual
executable, unless we also introduced the lenient behavior in the
executable, as well), we require passing `ParseMode::Lenient` to
`parse_patch_text()` to make it clear that the caller is opting into
supporting this special case.

Note the analogous change to the TypeScript CLI was
https://github.com/openai/codex/pull/930. In addition to changing the
accepted input to `apply_patch`, it also introduced additional
instructions for the model, which we include in this PR.

Note that `apply-patch` does not depend on either `regex` or
`regex-lite`, so some of the checks are slightly more verbose to avoid
introducing this dependency.

That said, this PR does not leverage the existing
`extract_heredoc_body_from_apply_patch_command()`, which depends on
`tree-sitter` and `tree-sitter-bash`:


5a5aa89914/codex-rs/apply-patch/src/lib.rs (L191-L246)

though perhaps it should.
2025-06-03 09:06:38 -07:00
..
ansi-escape Update submodules version to come from the workspace (#850) 2025-05-07 10:08:06 -07:00
apply-patch fix: provide tolerance for apply_patch tool (#993) 2025-06-03 09:06:38 -07:00
cli feat: add support for -c/--config to override individual config items (#1137) 2025-05-27 23:11:44 -07:00
common fix(codex-rs): use codex-mini-latest as default (#1164) 2025-05-29 16:55:19 -07:00
core fix: provide tolerance for apply_patch tool (#993) 2025-06-03 09:06:38 -07:00
docs feat: initial import of Rust implementation of Codex CLI in codex-rs/ (#629) 2025-04-24 13:31:40 -07:00
exec feat: make reasoning effort/summaries configurable (#1199) 2025-06-02 16:01:34 -07:00
execpolicy chore: replace regex with regex-lite, where appropriate (#1200) 2025-06-02 17:11:45 -07:00
linux-sandbox fix: overhaul how we spawn commands under seccomp/landlock on Linux (#1086) 2025-05-23 11:37:07 -07:00
mcp-client fix: honor RUST_LOG in mcp-client CLI and default to DEBUG (#1149) 2025-05-28 17:10:06 -07:00
mcp-server feat: add support for -c/--config to override individual config items (#1137) 2025-05-27 23:11:44 -07:00
mcp-types Disallow expect via lints (#865) 2025-05-12 08:45:46 -07:00
scripts chore: script to create a Rust release (#759) 2025-04-30 12:39:03 -07:00
tui chore: replace regex with regex-lite, where appropriate (#1200) 2025-06-02 17:11:45 -07:00
.gitignore feat: initial import of Rust implementation of Codex CLI in codex-rs/ (#629) 2025-04-24 13:31:40 -07:00
Cargo.lock chore: replace regex with regex-lite, where appropriate (#1200) 2025-06-02 17:11:45 -07:00
Cargo.toml fix: overhaul how we spawn commands under seccomp/landlock on Linux (#1086) 2025-05-23 11:37:07 -07:00
config.md feat: make reasoning effort/summaries configurable (#1199) 2025-06-02 16:01:34 -07:00
default.nix restructure flake for codex-rs (#888) 2025-05-13 13:08:42 -07:00
justfile fix: enable set positional-arguments in justfile (#1169) 2025-05-30 09:11:53 -07:00
README.md docs: split the config-related portion of codex-rs/README.md into its own config.md file (#1165) 2025-05-29 16:59:35 -07:00
rustfmt.toml Update cargo to 2024 edition (#842) 2025-05-07 08:37:48 -07:00

Codex CLI (Rust Implementation)

We provide Codex CLI as a standalone, native executable to ensure a zero-dependency install.

Installing Codex

Today, the easiest way to install Codex is via npm, though we plan to publish Codex to other package managers soon.

npm i -g @openai/codex@native
codex

You can also download a platform-specific release directly from our GitHub Releases.

Config

Codex supports a rich set of configuration options. See config.md for details.

Model Context Protocol Support

Codex CLI functions as an MCP client that can connect to MCP servers on startup. See the mcp_servers section in the configuration documentation for details.

It is still experimental, but you can also launch Codex as an MCP server by running codex mcp. Using the @modelcontextprotocol/inspector is

npx @modelcontextprotocol/inspector codex mcp

Code Organization

This folder is the root of a Cargo workspace. It contains quite a bit of experimental code, but here are the key crates:

  • core/ contains the business logic for Codex. Ultimately, we hope this to be a library crate that is generally useful for building other Rust/native applications that use Codex.
  • exec/ "headless" CLI for use in automation.
  • tui/ CLI that launches a fullscreen TUI built with Ratatui.
  • cli/ CLI multitool that provides the aforementioned CLIs via subcommands.