{"record":{"id":"a9ae04e1ba0b7aa0","repo":"chenhg5/cc-connect","slug":"claudecode-write-claude-code-usage-probe-input","errorCode":null,"errorMessage":"claudecode: write Claude Code /usage probe input: %w","messagePattern":"claudecode: write Claude Code /usage probe input: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agent/claudecode/claude_usage.go","lineNumber":195,"sourceCode":"\t\t\tscreen := normalizeClaudeUsageText(terminal.String())\n\t\t\tif screen != lastScreen {\n\t\t\t\tlastScreen = screen\n\t\t\t\tlastChange = time.Now()\n\t\t\t}\n\t\t\tif usageReady(lastScreen) {\n\t\t\t\tif usageScreen == \"\" {\n\t\t\t\t\tusageScreen = lastScreen\n\t\t\t\t}\n\t\t\t}\n\t\t\tif screenErr := detectClaudeUsageOutputError(lastScreen, stderr.String()); screenErr != nil {\n\t\t\t\treturn \"\", screenErr\n\t\t\t}\n\t\t\tif usageScreen != \"\" && time.Since(lastChange) >= claudeUsageStableFor {\n\t\t\t\treturn usageScreen, nil\n\t\t\t}\n\t\t\tif action := nextClaudeUsageProbeAction(lastScreen, &state, time.Now()); action != \"\" {\n\t\t\t\tif _, err := io.WriteString(ptmx, action); err != nil {\n\t\t\t\t\treturn \"\", fmt.Errorf(\"claudecode: write Claude Code /usage probe input: %w\", err)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunc (a *Agent) usageProbeEnv() []string {\n\ta.mu.Lock()\n\tdefer a.mu.Unlock()\n\treturn a.runtimeEnvLocked()\n}\n\nfunc nextClaudeUsageProbeAction(screen string, state *claudeUsageProbeState, now time.Time) string {\n\tif now.Sub(state.lastActionAt) < claudeUsageActionGap {\n\t\treturn \"\"\n\t}\n\n\tif action := promptActionForScreen(screen); action != \"\" && state.promptResponses < 6 {","sourceCodeStart":177,"sourceCodeEnd":213,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/agent/claudecode/claude_usage.go#L177-L213","documentation":"Raised by the /usage probe when writing a keystroke to the Claude Code process's stdin fails (e.g. sending the '/usage' command or a key action from the probe state machine). It fires when the process has already exited and its stdin pipe is closed.","triggerScenarios":"Thrown at agent/claudecode/claude_usage.go:195 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Retry the /usage request","Check why Claude Code terminated early (see preceding log lines)","Upgrade Claude Code if it crashes on startup"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}