gitbutlerapp/gitbutler · error · anyhow::Error
Could not determine home directory
Error message
Could not determine home directory
What it means
`but skill install --global` computes its install base from the user's home directory. When the platform home lookup fails (HOME on Unix or USERPROFILE on Windows unset or empty), installation cannot proceed and this error is returned.
Source
Thrown at crates/but/src/command/skill/mod.rs:413
/// Expand tilde in path to home directory
fn expand_tilde(path_str: &str) -> Option<PathBuf> {
if path_str == "~" || path_str.starts_with("~/") || path_str.starts_with("~\\") {
home_dir().map(|home| {
if path_str == "~" {
home
} else {
home.join(&path_str[2..])
}
})
} else {
None
}
}
/// Get the base directory for installation (repo root or home directory)
fn get_base_dir(ctx: Option<&mut Context>, global: bool) -> Result<PathBuf> {
if global {
home_dir().ok_or_else(|| anyhow::anyhow!("Could not determine home directory"))
} else {
let ctx = ctx.ok_or_else(|| {
anyhow::anyhow!(
"Not in a git repository. Use --global to install globally, or run from within a repository."
)
})?;
let repo = ctx.repo.get()?;
repo.workdir()
.ok_or_else(|| anyhow::anyhow!("Not in a Git repository"))
.map(|p| p.to_path_buf())
}
}
/// Replace version in SKILL.md content
fn inject_version(content: &str, version: &str) -> String {
// Handle different line endings (Unix \n, Windows \r\n, or old Mac \r)
let frontmatter_end = content
.find("---\n\n")View on GitHub (pinned to caf1f223d3)
Solutions
- Set HOME explicitly (export HOME=/home/user, or USERPROFILE on Windows) and retry
- Install per-repository instead: run the command without --global from inside a git repository
- In containers, set ENV HOME=/root in the image or pass -e HOME=... at run time
Example fix
# before docker run img but skill install my-skill --global # HOME unset -> error # after docker run -e HOME=/root img but skill install my-skill --global
Defensive patterns
Strategy: validation
Validate before calling
if std::env::var_os("HOME").is_none() && std::env::var_os("USERPROFILE").is_none() {
anyhow::bail!("HOME is not set; global skill install needs a home directory");
} Prevention
- Set HOME/USERPROFILE in scripts, services, and container images
- Prefer repo-local installs in headless environments
When it happens
Trigger: Running `but skill install --global` in an environment without HOME/USERPROFILE: minimal containers, CI runners with sanitized env, systemd units, cron jobs.
Common situations: Docker images that never set HOME; service accounts; scripts run with env -i or heavily scrubbed environments.
Related errors
- Failed to determine home directory
- Could not determine home directory
- Errors occurred: {cmd_errors:?}
- Failed to sign SSH: {stdout} {stderr}
- Could not find '{}'. Please make sure it is in your `PATH` o
AI-assisted analysis of gitbutlerapp/gitbutler@caf1f223d3 (2026-08-20).
Data as JSON: /api/errors/57bc00974c3d8a55.
Report an issue: GitHub.