chenhg5/cc-connect · error

claudecode: start claude usage probe: %w

Error message

claudecode: start claude usage probe: %w

What it means

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).

Source

Thrown at agent/claudecode/claude_usage.go:92

		"--no-chrome",
	}
	cmd := exec.CommandContext(probeCtx, "claude", args...)
	cmd.Dir = workDir

	env := filterEnv(os.Environ(), "CLAUDECODE")
	env = append(env, "DISABLE_TELEMETRY=true")
	env = append(env, "DISABLE_COST_WARNINGS=true")
	if extra := a.usageProbeEnv(); len(extra) > 0 {
		env = core.MergeEnv(env, extra)
	}
	cmd.Env = env

	var stderr bytes.Buffer
	cmd.Stderr = &stderr

	ptmx, err := pty.StartWithSize(cmd, &pty.Winsize{Rows: 40, Cols: 120})
	if err != nil {
		return "", fmt.Errorf("claudecode: start claude usage probe: %w", err)
	}

	var waitErr error
	processDone := make(chan struct{})
	go func() {
		waitErr = cmd.Wait()
		close(processDone)
	}()

	terminal := newClaudeUsageTerminal()
	readDone := make(chan error, 1)
	go func() {
		buf := make([]byte, 4096)
		for {
			n, err := ptmx.Read(buf)
			if n > 0 {
				terminal.Write(buf[:n])
			}

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Confirm `claude` is still executable (`claude --version`) and that PATH is stable for the daemon
  2. Check the wrapped error's cause: 'no such file' → reinstall claude; 'operation not permitted' → PTY restrictions in container/sandbox
  3. Raise ulimit -n / process limits if fd or pty exhaustion is reported
  4. Ensure the probe's working directory exists and is accessible by the service user, then retry GetUsage
Defensive patterns

Strategy: try-catch

Validate before calling

if _, err := exec.LookPath("claude"); err != nil { return err }
if err := unix.Access(claudePath, unix.X_OK); err != nil { return fmt.Errorf("claude not executable: %w", err) }

Try / catch

screen, err := runClaudeUsageProbe(ctx)
if err != nil {
    if strings.Contains(err.Error(), "start claude usage probe") {
        log.Errorf("PTY spawn failed: %v (check pty permissions, fd limits, container seccomp)", err)
        return nil // or fall back to non-PTY execution
    }
    return err
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06). Data as JSON: /api/errors/8536e182b652fdf3. Report an issue: GitHub.