chenhg5/cc-connect · error
codex: write auth.json: %w
Error message
codex: write auth.json: %w
What it means
Wraps a failed os.WriteFile of the generated auth.json (mode 0600) under the resolved CODEX_HOME. It fires when the codex home directory is not writable — permissions, read-only filesystem, or a path occupied by a file where a directory is expected.
Source
Thrown at agent/codex/provider_config.go:66
home, err := resolveCodexHomeForConfig(codexHome)
if err != nil {
return fmt.Errorf("codex: resolve codex home: %w", err)
}
if err := os.MkdirAll(home, 0o755); err != nil {
return fmt.Errorf("codex: mkdir codex home: %w", err)
}
authPath := filepath.Join(home, "auth.json")
payload := map[string]any{
"OPENAI_API_KEY": apiKey,
"auth_mode": "apikey",
}
data, err := json.MarshalIndent(payload, "", " ")
if err != nil {
return fmt.Errorf("codex: marshal auth.json: %w", err)
}
if err := os.WriteFile(authPath, append(data, '\n'), 0o600); err != nil {
return fmt.Errorf("codex: write auth.json: %w", err)
}
slog.Debug("codex: wrote auth.json", "path", authPath)
return nil
}
func resolveCodexHomeForConfig(explicit string) (string, error) {
if h := strings.TrimSpace(explicit); h != "" {
return h, nil
}
if h := strings.TrimSpace(os.Getenv("CODEX_HOME")); h != "" {
return h, nil
}
homeDir, err := os.UserHomeDir()
if err != nil {
return "", err
}
return filepath.Join(homeDir, ".codex"), nil
}View on GitHub (pinned to 4000b2338a)
Solutions
- Ensure the codex home directory (default ~/.codex) is writable by cc-connect
- Check disk space and read-only mounts
- If CODEX_HOME is customized, verify the path exists and is a directory
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at agent/codex/provider_config.go:66 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/f6cb66a4f63e9fab.
Report an issue: GitHub.