{"record":{"id":"56cf7e4f0d4410bb","repo":"chenhg5/cc-connect","slug":"resolve-home-directory-w-56cf7e","errorCode":null,"errorMessage":"resolve home directory: %w","messagePattern":"resolve home directory: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agent/codex/usage.go","lineNumber":190,"sourceCode":"\t}\n\tif bucket.SecondaryWindow != nil {\n\t\twindows = append(windows, core.UsageWindow{\n\t\t\tName:              \"Secondary\",\n\t\t\tUsedPercent:       bucket.SecondaryWindow.UsedPercent,\n\t\t\tWindowSeconds:     bucket.SecondaryWindow.LimitWindowSeconds,\n\t\t\tResetAfterSeconds: bucket.SecondaryWindow.ResetAfterSeconds,\n\t\t\tResetAtUnix:       bucket.SecondaryWindow.ResetAt,\n\t\t})\n\t}\n\treturn windows\n}\n\nfunc codexAuthPath() (string, error) {\n\tcodexHome := os.Getenv(\"CODEX_HOME\")\n\tif codexHome == \"\" {\n\t\thome, err := os.UserHomeDir()\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"resolve home directory: %w\", err)\n\t\t}\n\t\tcodexHome = filepath.Join(home, \".codex\")\n\t}\n\treturn filepath.Join(codexHome, \"auth.json\"), nil\n}\n","sourceCodeStart":172,"sourceCodeEnd":196,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/agent/codex/usage.go#L172-L196","documentation":"codexAuthPath builds the path to the Codex auth.json file: it uses $CODEX_HOME if set, otherwise $HOME/.codex via os.UserHomeDir(). This error wraps the os.UserHomeDir failure, which on Linux/Unix means HOME is unset or empty (and no CODEX_HOME override exists), so the library cannot determine where auth.json lives.","triggerScenarios":"CODEX_HOME is unset AND os.UserHomeDir() returns an error inside codexAuthPath, called from readOAuthTokens — typically when the process runs with a cleared environment (systemd unit without Environment=HOME, cron, container with minimal env, or `sudo -i` edge cases).","commonSituations":"Daemonizing cc-connect via systemd/launchd with a sanitized environment lacking HOME; Docker containers running as non-root without HOME set; CI runners with stripped env; invoking the binary through wrappers that clear the environment.","solutions":["Set CODEX_HOME in the service/container environment to the directory containing auth.json","Set HOME for the daemon (systemd: Environment=\"HOME=/home/youruser\" in the [Service] section)","Run the service as the user who owns the Codex credentials (User= in systemd unit)","Verify inside the same execution context: `tr '\\0' '\\n' < /proc/<pid>/environ | grep -E 'HOME|CODEX_HOME'`"],"exampleFix":"# before: systemd unit with empty env\n[Service]\nExecStart=/usr/local/bin/cc-connect\n# after\n[Service]\nUser=youruser\nEnvironment=\"HOME=/home/youruser\"\nExecStart=/usr/local/bin/cc-connect","handlingStrategy":"validation","validationCode":"if os.Getenv(\"CODEX_HOME\") == \"\" && os.Getenv(\"HOME\") == \"\" {\n    return errors.New(\"neither CODEX_HOME nor HOME is set; cannot locate codex auth.json\")\n}","typeGuard":null,"tryCatchPattern":"_, err := agent.GetUsage(ctx)\nif err != nil && strings.Contains(err.Error(), \"resolve home directory\") {\n    return fmt.Errorf(\"set CODEX_HOME or HOME for the cc-connect process: %w\", err)\n}","preventionTips":["Always set CODEX_HOME in systemd/docker/cron environments","Run the daemon as a real user with HOME defined","Verify env with /proc/<pid>/environ, not your shell","Document required env vars in deployment manifests"],"tags":["go","environment","codex","configuration"],"backgroundTag":"missing-env-var","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}