feat: support dotenv

This commit is contained in:
Michael Bolin
2025-07-22 10:58:18 -07:00
parent 4082246f6a
commit afb94dee66
9 changed files with 34 additions and 2 deletions
+2 -1
View File
@@ -9,11 +9,12 @@ workspace = true
[dependencies]
clap = { version = "4", features = ["derive", "wrap_help"], optional = true }
codex-core = { path = "../core" }
dotenvy = { version = "0.15.7", optional = true }
toml = { version = "0.9", optional = true }
serde = { version = "1", optional = true }
[features]
# Separate feature so that `clap` is not a mandatory dependency.
cli = ["clap", "toml", "serde"]
cli = ["clap", "dotenvy", "toml", "serde"]
elapsed = []
sandbox_summary = []
+7
View File
@@ -0,0 +1,7 @@
/// Load env vars from ~/.codex/.env and `$(pwd)/.env`.
pub fn load_dotenv() {
if let Ok(codex_home) = codex_core::config::find_codex_home() {
dotenvy::from_path(codex_home.join(".env")).ok();
}
dotenvy::dotenv().ok();
}
+6
View File
@@ -1,6 +1,12 @@
#[cfg(feature = "cli")]
mod approval_mode_cli_arg;
#[cfg(feature = "cli")]
mod dotenv;
#[cfg(feature = "cli")]
pub use dotenv::load_dotenv;
#[cfg(feature = "elapsed")]
pub mod elapsed;