diff --git a/codex-rs/core/src/environment_context.rs b/codex-rs/core/src/environment_context.rs
index 4be06a3300..ac7e36f0a5 100644
--- a/codex-rs/core/src/environment_context.rs
+++ b/codex-rs/core/src/environment_context.rs
@@ -122,7 +122,12 @@ impl EnvironmentContext {
} else {
None
};
- EnvironmentContext::new(cwd, approval_policy, sandbox_policy, None)
+ // Diff messages should only include fields that changed between turns.
+ // Operating system is a static property of the host and should not be
+ // emitted as part of a per-turn diff.
+ let mut ec = EnvironmentContext::new(cwd, approval_policy, sandbox_policy, None);
+ ec.operating_system = None;
+ ec
}
}
diff --git a/codex-rs/core/tests/suite/prompt_caching.rs b/codex-rs/core/tests/suite/prompt_caching.rs
index fee57784d7..7797e6cf09 100644
--- a/codex-rs/core/tests/suite/prompt_caching.rs
+++ b/codex-rs/core/tests/suite/prompt_caching.rs
@@ -36,19 +36,53 @@ fn text_user_input(text: String) -> serde_json::Value {
})
}
+#[allow(dead_code)]
+fn has_wsl_env_markers() -> bool {
+ std::env::var_os("WSL_INTEROP").is_some()
+ || std::env::var_os("WSLENV").is_some()
+ || std::env::var_os("WSL_DISTRO_NAME").is_some()
+}
+
+fn operating_system_context_block() -> String {
+ #[cfg(target_os = "windows")]
+ {
+ let info = os_info::get();
+ let name = info.os_type().to_string();
+ let version = info.version().to_string();
+ let is_wsl = has_wsl_env_markers();
+ return format!(
+ " \n {name}\n {version}\n {is_wsl}\n \n"
+ );
+ }
+
+ #[cfg(all(unix, not(target_os = "macos")))]
+ {
+ if has_wsl_env_markers() {
+ return " \n Windows Subsystem for Linux\n \n true\n \n".to_string();
+ }
+ return String::new();
+ }
+
+ #[cfg(target_os = "macos")]
+ {
+ String::new()
+ }
+}
+
fn default_env_context_str(cwd: &str, shell: &Shell) -> String {
+ let shell_line = match shell.name() {
+ Some(name) => format!(" {name}\n"),
+ None => String::new(),
+ };
+ let os_block = operating_system_context_block();
format!(
r#"
{}
on-request
read-only
restricted
-{}"#,
- cwd,
- match shell.name() {
- Some(name) => format!(" {name}\n"),
- None => String::new(),
- }
+{}{}"#,
+ cwd, shell_line, os_block
)
}