Proposed Refactor: Replace once_cell with std::sync::LazyLock

Resolved 💬 2 comments Opened Mar 14, 2026 by htiennv Closed Mar 19, 2026

What is the proposal?

I propose refactoring the codebase to remove the external once_cell dependency and replace its usage with the standard library's std::sync::LazyLock.

Why is this change necessary/beneficial?

  • Dependency Reduction: std::sync::LazyLock has been stable since Rust 1.80.0. Since the project is currently using Rust toolchain v1.93.0, once_cell is no longer required for basic lazy initialization of statics.
  • Idiomatic Rust: Leveraging the standard library where possible is a best practice that improves maintainability and ensures long-term compatibility without relying on third-party crates.
  • Scaling & Maintenance: Reducing the total number of dependencies simplifies the [Cargo.lock](cci:7://file:///Users/tiennv/work/ext/codex/codex-rs/Cargo.lock:0:0-0:0) and makes the project cleaner.

How will this be implemented?

  1. Clean up dependencies:
  • Remove once_cell from [workspace.dependencies] in the root [Cargo.toml](cci:7://file:///Users/tiennv/work/ext/codex/codex-rs/Cargo.toml:0:0-0:0).
  • Remove once_cell from member crates: codex-core, codex-shell-command, and codex-git.
  1. Refactor Code:
  • Replace once_cell::sync::Lazy with std::sync::LazyLock in:
  • [shell-command/src/command_safety/windows_dangerous_commands.rs](cci:7://file:///Users/tiennv/work/ext/codex/codex-rs/shell-command/src/command_safety/windows_dangerous_commands.rs:0:0-0:0)
  • [utils/git/src/apply.rs](cci:7://file:///Users/tiennv/work/ext/codex/codex-rs/utils/git/src/apply.rs:0:0-0:0)
  • [core/src/test_support.rs](cci:7://file:///Users/tiennv/work/ext/codex/codex-rs/core/src/test_support.rs:0:0-0:0)
  • [core/src/auth/storage.rs](cci:7://file:///Users/tiennv/work/ext/codex/codex-rs/core/src/auth/storage.rs:0:0-0:0)
  1. Verification:
  • Ran cargo test for affected crates.
  • Ran cargo fmt to maintain code style.

Impact

  • Breaking Changes: None. This is a purely internal refactoring.
  • Affected Surfaces: All internal crates that rely on lazy-initialized constants.

View original on GitHub ↗

This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗