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::LazyLockhas been stable since Rust 1.80.0. Since the project is currently using Rust toolchain v1.93.0,once_cellis 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?
- Clean up dependencies:
- Remove
once_cellfrom[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_cellfrom member crates:codex-core,codex-shell-command, andcodex-git.
- Refactor Code:
- Replace
once_cell::sync::Lazywithstd::sync::LazyLockin: - [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)
- Verification:
- Ran
cargo testfor affected crates. - Ran
cargo fmtto maintain code style.
Impact
- Breaking Changes: None. This is a purely internal refactoring.
- Affected Surfaces: All internal crates that rely on lazy-initialized constants.
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗