chenhg5/cc-connect · error
gemini: cannot determine home dir: %w
Error message
gemini: cannot determine home dir: %w
What it means
DeleteSession needs the user's home directory to locate ~/.gemini/tmp/<slug>/chats. os.UserHomeDir() failed (usually $HOME unset), so the session cannot be deleted. The error wraps the underlying OS error.
Source
Thrown at agent/gemini/gemini.go:237
if a.activeIdx >= 0 && a.activeIdx < len(a.providers) {
if m := a.providers[a.activeIdx].Model; m != "" {
model = m
}
}
a.mu.Unlock()
return newGeminiSession(ctx, cmd, extraArgs, workDir, model, mode, sessionID, extraEnv, timeout)
}
// ListSessions reads sessions from ~/.gemini/tmp/<project_hash>/chats/.
func (a *Agent) ListSessions(_ context.Context) ([]core.AgentSessionInfo, error) {
return listGeminiSessions(a.workDir)
}
func (a *Agent) DeleteSession(_ context.Context, sessionID string) error {
homeDir, err := os.UserHomeDir()
if err != nil {
return fmt.Errorf("gemini: cannot determine home dir: %w", err)
}
chatsDir := filepath.Join(homeDir, ".gemini", "tmp", geminiProjectSlug(a.workDir), "chats")
// Session files are named session-<timestamp>-<uuid_prefix>.json, not <uuid>.json.
// Scan the directory to find the file containing the matching sessionId.
entries, err := os.ReadDir(chatsDir)
if err != nil {
return fmt.Errorf("session file not found: %s", sessionID)
}
for _, entry := range entries {
if entry.IsDir() || !strings.HasSuffix(entry.Name(), ".json") {
continue
}
fpath := filepath.Join(chatsDir, entry.Name())
data, err := os.ReadFile(fpath)
if err != nil {
continue
}
var sf struct {View on GitHub (pinned to 4000b2338a)
Solutions
- Set HOME in the process environment (e.g. Environment=HOME=/home/user in the systemd unit)
- Run cc-connect as a normal user with a valid home directory
- Pass the home dir via env explicitly when launching the daemon in containers (ENV HOME=/root)
- Log the wrapped inner error to confirm which env var is missing
Example fix
// before: docker run with no HOME CMD ["/usr/local/bin/cc-connect"] // after docker run -e HOME=/home/ccuser ...
Defensive patterns
Strategy: validation
Validate before calling
home, err := os.UserHomeDir()
if err != nil || home == "" {
return fmt.Errorf("cannot manage gemini sessions: set $HOME for this process")
} Try / catch
if err := agent.DeleteSession(ctx, id); err != nil && strings.Contains(err.Error(), "cannot determine home dir") {
log.Printf("environment misconfigured (HOME unset): %v", err)
} Prevention
- Always set HOME (and USERPROFILE on Windows) for daemons/containers
- Test the service under its real runtime env, not just an interactive shell
- Prefer running services under a dedicated user with a valid home directory
When it happens
Trigger: Calling Agent.DeleteSession(ctx, sessionID) in an environment where os.UserHomeDir() returns an error: $HOME (and on Windows USERPROFILE) is unset, e.g. daemons, containers, or services running with a scrubbed environment.
Common situations: systemd service with minimal env; Docker container running as non-root without HOME; cron jobs lacking HOME; running under a service manager with a restricted environment.
Understand the failure class
Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.
Related errors
- pi: cannot determine settings path
- get home dir: %w
- resolve home directory for Agy permission bridge: %w
- create Agy permission overlay: %w
- read existing Agy hooks %s: %w
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/21cf79cfc685431d.
Report an issue: GitHub.