openai/codex · error · anyhow::Error
--codex-home is required with --user
Error message
--codex-home is required with --user
What it means
Returned by resolve_sandbox_setup_identity when --user names a user but --codex-home is absent. For a non-current user the CODEX_HOME cannot be inferred from the invoking environment, so an explicit directory is mandatory.
Solutions
- Add --codex-home <dir> alongside --user
- Use --current-user, which can fall back to the detected CODEX_HOME
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at codex-rs/cli/src/sandbox_setup.rs:158 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of openai/codex@339751715c (2026-08-25).
Data as JSON: /api/errors/286ab1109da7e9af.
Report an issue: GitHub.
Appendix: source
Thrown at codex-rs/cli/src/sandbox_setup.rs:158
})?;
let codex_home = match cmd.codex_home.clone() {
Some(codex_home) => codex_home,
None => find_codex_home()?.to_path_buf(),
};
return Ok(SandboxSetupIdentity {
real_user,
codex_home,
});
}
let real_user = cmd
.user
.clone()
.ok_or_else(|| anyhow::anyhow!("--user or --current-user is required"))?;
let codex_home = cmd
.codex_home
.clone()
.ok_or_else(|| anyhow::anyhow!("--codex-home is required with --user"))?;
Ok(SandboxSetupIdentity {
real_user,
codex_home,
})
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn parses_managed_user_identity() {
let command = SandboxSetupCommand::try_parse_from([
"setup",
"--elevated",
"--user",
"DOMAIN\\alice",
"--codex-home",View on GitHub (pinned to 339751715c)