{"record":{"id":"64f95fc8a17ab380","repo":"chenhg5/cc-connect","slug":"claudecode-create-usage-temp-dir-w","errorCode":null,"errorMessage":"claudecode: create usage temp dir: %w","messagePattern":"claudecode: create usage temp dir: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agent/claudecode/claude_usage.go","lineNumber":67,"sourceCode":"func (a *Agent) GetUsage(ctx context.Context) (*core.UsageReport, error) {\n\tif _, err := exec.LookPath(\"claude\"); err != nil {\n\t\treturn nil, fmt.Errorf(\"claudecode: 'claude' CLI not found in PATH\")\n\t}\n\n\tscreen, err := a.runClaudeUsageProbe(ctx)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\treturn parseClaudeUsageReport(screen, time.Now())\n}\n\nfunc (a *Agent) runClaudeUsageProbe(ctx context.Context) (string, error) {\n\tprobeCtx, cancel := context.WithCancel(ctx)\n\tdefer cancel()\n\n\tworkDir, err := os.MkdirTemp(\"\", \"cc-connect-claude-usage-*\")\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"claudecode: create usage temp dir: %w\", err)\n\t}\n\tdefer os.RemoveAll(workDir)\n\n\targs := []string{\n\t\t\"--tools\", \"\",\n\t\t\"--permission-mode\", \"plan\",\n\t\t\"--no-chrome\",\n\t}\n\tcmd := exec.CommandContext(probeCtx, \"claude\", args...)\n\tcmd.Dir = workDir\n\n\tenv := filterEnv(os.Environ(), \"CLAUDECODE\")\n\tenv = append(env, \"DISABLE_TELEMETRY=true\")\n\tenv = append(env, \"DISABLE_COST_WARNINGS=true\")\n\tif extra := a.usageProbeEnv(); len(extra) > 0 {\n\t\tenv = core.MergeEnv(env, extra)\n\t}\n\tcmd.Env = env","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/agent/claudecode/claude_usage.go#L49-L85","documentation":"runClaudeUsageProbe creates a temporary working directory (os.MkdirTemp with pattern \"cc-connect-claude-usage-*\") to run an isolated claude usage probe. This error wraps the os.MkdirTemp failure — the temp-dir root is unwritable, the pattern is invalid (practically never), or the OS ran out of resources.","triggerScenarios":"GetUsage → runClaudeUsageProbe → os.MkdirTemp(\"\", \"cc-connect-claude-usage-*\") fails with a *PathError: TMPDIR points to a nonexistent/unwritable directory, disk full, or the process lacks permission to create directories in the temp root.","commonSituations":"Hardened TMPDIR with restrictive permissions for the service user; TMPDIR set to a path that was deleted; read-only filesystem or full disk on the host running the daemon; container with a tiny/noexec tmpfs.","solutions":["Check TMPDIR for the cc-connect process (`cat /proc/<pid>/environ | tr '\\0' '\\n' | grep TMPDIR`) and ensure it exists and is writable by the service user","Free disk space / fix filesystem permissions on the temp root","Set TMPDIR explicitly to a safe writable location in the daemon environment (e.g. TMPDIR=/var/tmp/cc-connect with correct ownership)","If running in a container, mount a writable tmpfs at /tmp"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"tmp := os.TempDir()\nif fi, err := os.Stat(tmp); err != nil || !fi.IsDir() { return fmt.Errorf(\"TMPDIR %s unusable\", tmp) }\nprobe, err := os.MkdirTemp(tmp, \".cc-connect-write-test-*\"); if err == nil { os.Remove(probe) } else { return err }","typeGuard":"func tempDirWritable() bool { d, err := os.MkdirTemp(\"\", \"cc-connect-probe-*\"); if err != nil { return false }; os.Remove(d); return true }","tryCatchPattern":"screen, err := runClaudeUsageProbe(ctx)\nif err != nil {\n    var pe *fs.PathError\n    if errors.As(err, &pe) && strings.Contains(err.Error(), \"create usage temp dir\") {\n        log.Errorf(\"temp dir creation failed: %v (check TMPDIR permissions/disk space)\", pe)\n    }\n    return err\n}","preventionTips":["Ensure TMPDIR exists and is writable by the cc-connect service user","Set an explicit TMPDIR in the daemon environment on hardened hosts","Monitor disk space; tmpfs-backed /tmp needs headroom in containers","Exclude temp roots from aggressive cleanup jobs that delete live directories"],"tags":["filesystem","temp-dir","permissions"],"backgroundTag":"mkdir-permission-denied","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}