source dump of claude code
at main 79 lines 4.3 kB view raw
1import { registerBundledSkill } from '../bundledSkills.js' 2 3// Prompt text contains `ps` commands as instructions for Claude to run, 4// not commands this file executes. 5// eslint-disable-next-line custom-rules/no-direct-ps-commands 6const STUCK_PROMPT = `# /stuck — diagnose frozen/slow Claude Code sessions 7 8The user thinks another Claude Code session on this machine is frozen, stuck, or very slow. Investigate and post a report to #claude-code-feedback. 9 10## What to look for 11 12Scan for other Claude Code processes (excluding the current one — PID is in \`process.pid\` but for shell commands just exclude the PID you see running this prompt). Process names are typically \`claude\` (installed) or \`cli\` (native dev build). 13 14Signs of a stuck session: 15- **High CPU (≥90%) sustained** — likely an infinite loop. Sample twice, 1-2s apart, to confirm it's not a transient spike. 16- **Process state \`D\` (uninterruptible sleep)** — often an I/O hang. The \`state\` column in \`ps\` output; first character matters (ignore modifiers like \`+\`, \`s\`, \`<\`). 17- **Process state \`T\` (stopped)** — user probably hit Ctrl+Z by accident. 18- **Process state \`Z\` (zombie)** — parent isn't reaping. 19- **Very high RSS (≥4GB)** — possible memory leak making the session sluggish. 20- **Stuck child process** — a hung \`git\`, \`node\`, or shell subprocess can freeze the parent. Check \`pgrep -lP <pid>\` for each session. 21 22## Investigation steps 23 241. **List all Claude Code processes** (macOS/Linux): 25 \`\`\` 26 ps -axo pid=,pcpu=,rss=,etime=,state=,comm=,command= | grep -E '(claude|cli)' | grep -v grep 27 \`\`\` 28 Filter to rows where \`comm\` is \`claude\` or (\`cli\` AND the command path contains "claude"). 29 302. **For anything suspicious**, gather more context: 31 - Child processes: \`pgrep -lP <pid>\` 32 - If high CPU: sample again after 1-2s to confirm it's sustained 33 - If a child looks hung (e.g., a git command), note its full command line with \`ps -p <child_pid> -o command=\` 34 - Check the session's debug log if you can infer the session ID: \`~/.claude/debug/<session-id>.txt\` (the last few hundred lines often show what it was doing before hanging) 35 363. **Consider a stack dump** for a truly frozen process (advanced, optional): 37 - macOS: \`sample <pid> 3\` gives a 3-second native stack sample 38 - This is big — only grab it if the process is clearly hung and you want to know *why* 39 40## Report 41 42**Only post to Slack if you actually found something stuck.** If every session looks healthy, tell the user that directly — do not post an all-clear to the channel. 43 44If you did find a stuck/slow session, post to **#claude-code-feedback** (channel ID: \`C07VBSHV7EV\`) using the Slack MCP tool. Use ToolSearch to find \`slack_send_message\` if it's not already loaded. 45 46**Use a two-message structure** to keep the channel scannable: 47 481. **Top-level message** — one short line: hostname, Claude Code version, and a terse symptom (e.g. "session PID 12345 pegged at 100% CPU for 10min" or "git subprocess hung in D state"). No code blocks, no details. 492. **Thread reply** — the full diagnostic dump. Pass the top-level message's \`ts\` as \`thread_ts\`. Include: 50 - PID, CPU%, RSS, state, uptime, command line, child processes 51 - Your diagnosis of what's likely wrong 52 - Relevant debug log tail or \`sample\` output if you captured it 53 54If Slack MCP isn't available, format the report as a message the user can copy-paste into #claude-code-feedback (and let them know to thread the details themselves). 55 56## Notes 57- Don't kill or signal any processes — this is diagnostic only. 58- If the user gave an argument (e.g., a specific PID or symptom), focus there first. 59` 60 61export function registerStuckSkill(): void { 62 if (process.env.USER_TYPE !== 'ant') { 63 return 64 } 65 66 registerBundledSkill({ 67 name: 'stuck', 68 description: 69 '[ANT-ONLY] Investigate frozen/stuck/slow Claude Code sessions on this machine and post a diagnostic report to #claude-code-feedback.', 70 userInvocable: true, 71 async getPromptForCommand(args) { 72 let prompt = STUCK_PROMPT 73 if (args) { 74 prompt += `\n## User-provided context\n\n${args}\n` 75 } 76 return [{ type: 'text', text: prompt }] 77 }, 78 }) 79}