{"record":{"id":"8536e182b652fdf3","repo":"chenhg5/cc-connect","slug":"claudecode-start-claude-usage-probe-w","errorCode":null,"errorMessage":"claudecode: start claude usage probe: %w","messagePattern":"claudecode: start claude usage probe: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agent/claudecode/claude_usage.go","lineNumber":92,"sourceCode":"\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\n\n\tvar stderr bytes.Buffer\n\tcmd.Stderr = &stderr\n\n\tptmx, err := pty.StartWithSize(cmd, &pty.Winsize{Rows: 40, Cols: 120})\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"claudecode: start claude usage probe: %w\", err)\n\t}\n\n\tvar waitErr error\n\tprocessDone := make(chan struct{})\n\tgo func() {\n\t\twaitErr = cmd.Wait()\n\t\tclose(processDone)\n\t}()\n\n\tterminal := newClaudeUsageTerminal()\n\treadDone := make(chan error, 1)\n\tgo func() {\n\t\tbuf := make([]byte, 4096)\n\t\tfor {\n\t\t\tn, err := ptmx.Read(buf)\n\t\t\tif n > 0 {\n\t\t\t\tterminal.Write(buf[:n])\n\t\t\t}","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/agent/claudecode/claude_usage.go#L74-L110","documentation":"runClaudeUsageProbe starts the claude CLI under a PTY (pty.StartWithSize, 40x120) so it behaves like an interactive session for the usage probe. This error wraps the pty start failure — the command could not be spawned or a PTY could not be allocated (e.g. the claude binary missing from the probe's working context, exec format issues, or OS pty exhaustion).","triggerScenarios":"GetUsage → runClaudeUsageProbe builds the claude command (--tools \"\" --permission-mode plan ...) and calls pty.StartWithSize(cmd, &pty.Winsize{...}); error occurs when cmd.Path cannot be resolved/executed, the working dir is invalid, the OS denies pty allocation, or out of pty/file descriptors.","commonSituations":"claude binary was removed between the LookPath check and spawn; running inside a container/runtime that disallows PTY allocation; ulimit on processes/file descriptors exhausted; cwd options point at a deleted directory.","solutions":["Confirm `claude` is still executable (`claude --version`) and that PATH is stable for the daemon","Check the wrapped error's cause: 'no such file' → reinstall claude; 'operation not permitted' → PTY restrictions in container/sandbox","Raise ulimit -n / process limits if fd or pty exhaustion is reported","Ensure the probe's working directory exists and is accessible by the service user, then retry GetUsage"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if _, err := exec.LookPath(\"claude\"); err != nil { return err }\nif err := unix.Access(claudePath, unix.X_OK); err != nil { return fmt.Errorf(\"claude not executable: %w\", err) }","typeGuard":null,"tryCatchPattern":"screen, err := runClaudeUsageProbe(ctx)\nif err != nil {\n    if strings.Contains(err.Error(), \"start claude usage probe\") {\n        log.Errorf(\"PTY spawn failed: %v (check pty permissions, fd limits, container seccomp)\", err)\n        return nil // or fall back to non-PTY execution\n    }\n    return err\n}","preventionTips":["Grant the daemon's container/sandbox permission to allocate PTYs (/dev/ptmx, devpts mount)","Raise nofile/process ulimits for long-running daemons","Verify `claude --version` works as the service user after every CLI update","Provide a non-PTY fallback path for environments where pty.StartWithSize is unavailable"],"tags":["pty","exec","subprocess"],"backgroundTag":"command-not-found","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"}