{"record":{"id":"448d3fba6345dd46","repo":"warpdotdev/warp","slug":"could-not-determine-home-directory","errorCode":null,"errorMessage":"Could not determine home directory","messagePattern":"Could not determine home directory","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"app/src/ai/agent_sdk/driver/git_credentials.rs","lineNumber":34,"sourceCode":"// Use the project's allowed Command wrapper (not std::process::Command, which is\n// disallowed by clippy rules because it flashes a terminal window on Windows).\nuse command::blocking::Command as BlockingCommand;\n\nuse crate::server::server_api::ai::{AIClient, GitCredential};\n\n/// How long to wait between credential refresh attempts (~50 minutes, staying\n/// well ahead of the shortest-lived one-hour token expiry).\npub(crate) const GIT_CREDENTIALS_REFRESH_INTERVAL: Duration = Duration::from_secs(50 * 60);\n\nconst DEFAULT_GIT_NAME: &str = \"Warp\";\nconst DEFAULT_GIT_EMAIL: &str = \"agent@warp.dev\";\nconst GITHUB_HOST: &str = \"github.com\";\nconst GH_HOSTS_FILENAME: &str = \"hosts.yml\";\nconst GLAB_HOST: &str = \"gitlab.com\";\nconst GLAB_CONFIG_FILENAME: &str = \"config.yml\";\n\nfn home_dir() -> Result<PathBuf> {\n    dirs::home_dir().ok_or_else(|| anyhow::anyhow!(\"Could not determine home directory\"))\n}\n\n/// Write `content` to `path` using owner-only (0600) permissions.\n///\n/// On Unix the file is created with mode 0600 so no other user can read the\n/// credential material. On non-Unix platforms the function falls back to the\n/// standard write, relying on OS default permissions.\nfn write_secret_file(path: &std::path::Path, content: &str) -> Result<()> {\n    #[cfg(unix)]\n    {\n        use std::io::Write as _;\n        use std::os::unix::fs::{OpenOptionsExt as _, PermissionsExt as _};\n        let mut file = std::fs::OpenOptions::new()\n            .write(true)\n            .create(true)\n            .truncate(true)\n            .mode(0o600)\n            .open(path)","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/warpdotdev/warp/blob/e72fd7aacbbb2236d9b3be2aad7e7178fe94b4bc/app/src/ai/agent_sdk/driver/git_credentials.rs#L16-L52","documentation":"Thrown by home_dir() in git_credentials.rs when dirs::home_dir() returns None, so no base directory exists to locate gh/glab credential files (~/.config/gh/hosts.yml, ~/.gitconfig, glab config). This is an environment problem: the OS APIs and HOME/USERPROFILE both failed to yield a home directory.","triggerScenarios":"Calling git-credential helpers (load/refresh of GitHub/GitLab tokens, writing DEFAULT_GIT_NAME/EMAIL to .gitconfig) in a process where HOME and USERPROFILE are unset or empty and the platform lookup (getpwuid on Unix) fails — typically hardened containers, init-style daemons, or misconfigured CI.","commonSituations":"Docker images that deliberately unset HOME or run as a UID with no passwd entry; systemd services without Environment=\"HOME=...\"; macOS launchd agents; CI runners using scratch users; sandboxed executors where /etc/passwd lacks the user.","solutions":["Set HOME (Unix) or USERPROFILE (Windows) explicitly in the environment running the agent, e.g. HOME=/root or HOME=/tmp/warp-home.","For containers/systemd units, add Environment=HOME=... or a passwd entry for the runtime user.","Verify with a quick check before running: printenv HOME USERPROFILE and fix whichever is blank."],"exampleFix":"# before\ndocker run warp-agent …   # HOME unset → error\n\n# after\ndocker run -e HOME=/root warp-agent …\n# or in a systemd unit:\n[Service]\nEnvironment=HOME=/var/lib/warp","handlingStrategy":"validation","validationCode":"let home = std::env::var_os(\"HOME\")\n    .or_else(|| std::env::var_os(\"USERPROFILE\"))\n    .filter(|h| !h.is_empty());\nanyhow::ensure!(home.is_some(), \"HOME/USERPROFILE must be set for git credential flows\");","typeGuard":"fn has_home_dir() -> bool {\n    dirs::home_dir().is_some()\n}","tryCatchPattern":"if let Err(err) = refresh_git_credentials(ctx).await {\n    if err.to_string().contains(\"Could not determine home directory\") {\n        // set HOME for the child process and retry once\n    } else { return Err(err); }\n}","preventionTips":["Always set HOME (or USERPROFILE) in containers, systemd units, and CI running agent flows.","For synthetic UIDs, add a passwd entry so getpwuid-based home lookup succeeds.","Smoke-test environments with printenv HOME USERPROFILE before first agent run."],"tags":["environment","home-directory","git-credentials","rust"],"backgroundTag":null,"analyzedSha":"e72fd7aacbbb2236d9b3be2aad7e7178fe94b4bc","analyzedAt":"2026-08-16T08:27:25.381Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}