warpdotdev/warp · error · anyhow::Error
Could not determine home directory
Error message
Could not determine home directory
What it means
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.
Source
Thrown at app/src/ai/agent_sdk/driver/git_credentials.rs:34
// Use the project's allowed Command wrapper (not std::process::Command, which is
// disallowed by clippy rules because it flashes a terminal window on Windows).
use command::blocking::Command as BlockingCommand;
use crate::server::server_api::ai::{AIClient, GitCredential};
/// How long to wait between credential refresh attempts (~50 minutes, staying
/// well ahead of the shortest-lived one-hour token expiry).
pub(crate) const GIT_CREDENTIALS_REFRESH_INTERVAL: Duration = Duration::from_secs(50 * 60);
const DEFAULT_GIT_NAME: &str = "Warp";
const DEFAULT_GIT_EMAIL: &str = "agent@warp.dev";
const GITHUB_HOST: &str = "github.com";
const GH_HOSTS_FILENAME: &str = "hosts.yml";
const GLAB_HOST: &str = "gitlab.com";
const GLAB_CONFIG_FILENAME: &str = "config.yml";
fn home_dir() -> Result<PathBuf> {
dirs::home_dir().ok_or_else(|| anyhow::anyhow!("Could not determine home directory"))
}
/// Write `content` to `path` using owner-only (0600) permissions.
///
/// On Unix the file is created with mode 0600 so no other user can read the
/// credential material. On non-Unix platforms the function falls back to the
/// standard write, relying on OS default permissions.
fn write_secret_file(path: &std::path::Path, content: &str) -> Result<()> {
#[cfg(unix)]
{
use std::io::Write as _;
use std::os::unix::fs::{OpenOptionsExt as _, PermissionsExt as _};
let mut file = std::fs::OpenOptions::new()
.write(true)
.create(true)
.truncate(true)
.mode(0o600)
.open(path)View on GitHub (pinned to e72fd7aacb)
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.
Example fix
# before docker run warp-agent … # HOME unset → error # after docker run -e HOME=/root warp-agent … # or in a systemd unit: [Service] Environment=HOME=/var/lib/warp
Defensive patterns
Strategy: validation
Validate before calling
let home = std::env::var_os("HOME")
.or_else(|| std::env::var_os("USERPROFILE"))
.filter(|h| !h.is_empty());
anyhow::ensure!(home.is_some(), "HOME/USERPROFILE must be set for git credential flows"); Type guard
fn has_home_dir() -> bool {
dirs::home_dir().is_some()
} Try / catch
if let Err(err) = refresh_git_credentials(ctx).await {
if err.to_string().contains("Could not determine home directory") {
// set HOME for the child process and retry once
} else { return Err(err); }
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- could not determine home directory
- could not determine home directory
- could not determine home directory
- could not determine home directory
- could not determine home directory
AI-assisted analysis of warpdotdev/warp@e72fd7aacb (2026-08-16).
Data as JSON: /api/errors/448d3fba6345dd46.
Report an issue: GitHub.