chenhg5/cc-connect · error
resolve home directory
Error message
resolve home directory: %w
What it means
resolveCodexHome determines the codex home directory: CODEX_HOME env (from the provided env list first, then os.Getenv), falling back to os.UserHomeDir()+"/.codex". When os.UserHomeDir fails (it cannot determine the current user's home), the error is wrapped with this message. Downstream callers (cached models, model catalog, context usage) all fail with it.
Solutions
- Set CODEX_HOME explicitly (e.g. CODEX_HOME=/home/user/.codex) in the service environment.
- Set HOME (Unix) or ensure the user profile is loaded (Windows) for the process.
- Run the daemon as a regular user whose home directory is resolvable.
Example fix
// before ExecStart=/usr/local/bin/cc-connect # no HOME => UserHomeDir fails // after (systemd) [Service] Environment=CODEX_HOME=/home/alice/.codex ExecStart=/usr/local/bin/cc-connect
Defensive patterns
Strategy: validation
Validate before calling
if os.Getenv("CODEX_HOME") == "" {
if _, err := os.UserHomeDir(); err != nil {
return fmt.Errorf("cannot resolve codex home: set CODEX_HOME explicitly: %w", err)
}
} Try / catch
codexHome, err := resolveCodexHome(extraEnv)
if err != nil {
return fmt.Errorf("codex home unavailable; set CODEX_HOME: %w", err)
} Prevention
- Always set CODEX_HOME explicitly in daemon/systemd/container environments.
- Never launch services with a scrubbed environment missing HOME.
- Add a config check that warns when CODEX_HOME is unset at startup.
- Run containers with a defined user and home directory.
When it happens
Trigger: resolveCodexHome called in an environment where os.UserHomeDir() returns an error — no HOME env var on Unix, or user profile resolution failing on Windows — and CODEX_HOME is unset.
Common situations: Running cc-connect as a systemd service with a minimal env (HOME unset); containers running as a non-login user; Windows services without a loaded user profile; CI runners with scrubbed environments.
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
- cannot resolve home directory
- codex: resolve codex home
- resolve home dir
- resolve home directory for Agy permission bridge
- ffmpeg not found in PATH: install ffmpeg to enable voice…
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/e934761994089af5.
Report an issue: GitHub.
Appendix: source
Thrown at agent/codex/context_usage.go:147
if err != nil {
return nil, path, err
}
if usage == nil {
return nil, path, fmt.Errorf("context usage not found in rollout")
}
return usage, path, nil
}
func resolveCodexHome(extraEnv []string) (string, error) {
if value := getenvFromList(extraEnv, "CODEX_HOME"); value != "" {
return strings.TrimSpace(value), nil
}
if value := strings.TrimSpace(os.Getenv("CODEX_HOME")); value != "" {
return value, nil
}
homeDir, err := os.UserHomeDir()
if err != nil {
return "", fmt.Errorf("resolve home directory: %w", err)
}
return filepath.Join(homeDir, ".codex"), nil
}
func getenvFromList(env []string, key string) string {
prefix := key + "="
for i := len(env) - 1; i >= 0; i-- {
entry := env[i]
if strings.HasPrefix(entry, prefix) {
return strings.TrimSpace(strings.TrimPrefix(entry, prefix))
}
}
return ""
}
func findSessionFileInCodexHome(codexHome, sessionID string) string {
if strings.TrimSpace(codexHome) == "" || strings.TrimSpace(sessionID) == "" {
return ""View on GitHub (pinned to 4000b2338a)