MCPcopy Create free account
hub / github.com/codeaashu/claude-code / registerDebugSkill

Function registerDebugSkill

src/skills/bundled/debug.ts:12–103  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

10const TAIL_READ_BYTES = 64 * 1024
11
12export function registerDebugSkill(): void {
13 registerBundledSkill({
14 name: 'debug',
15 description:
16 process.env.USER_TYPE === 'ant'
17 ? 'Debug your current Claude Code session by reading the session debug log. Includes all event logging'
18 : 'Enable debug logging for this session and help diagnose issues',
19 allowedTools: ['Read', 'Grep', 'Glob'],
20 argumentHint: '[issue description]',
21 // disableModelInvocation so that the user has to explicitly request it in
22 // interactive mode and so the description does not take up context.
23 disableModelInvocation: true,
24 userInvocable: true,
25 async getPromptForCommand(args) {
26 // Non-ants don't write debug logs by default — turn logging on now so
27 // subsequent activity in this session is captured.
28 const wasAlreadyLogging = enableDebugLogging()
29 const debugLogPath = getDebugLogPath()
30
31 let logInfo: string
32 try {
33 // Tail the log without reading the whole thing - debug logs grow
34 // unbounded in long sessions and reading them in full spikes RSS.
35 const stats = await stat(debugLogPath)
36 const readSize = Math.min(stats.size, TAIL_READ_BYTES)
37 const startOffset = stats.size - readSize
38 const fd = await open(debugLogPath, 'r')
39 try {
40 const { buffer, bytesRead } = await fd.read({
41 buffer: Buffer.alloc(readSize),
42 position: startOffset,
43 })
44 const tail = buffer
45 .toString('utf-8', 0, bytesRead)
46 .split('\n')
47 .slice(-DEFAULT_DEBUG_LINES_READ)
48 .join('\n')
49 logInfo = `Log size: ${formatFileSize(stats.size)}\n\n### Last ${DEFAULT_DEBUG_LINES_READ} lines\n\n\`\`\`\n${tail}\n\`\`\``
50 } finally {
51 await fd.close()
52 }
53 } catch (e) {
54 logInfo = isENOENT(e)
55 ? 'No debug log exists yet — logging was just enabled.'
56 : `Failed to read last ${DEFAULT_DEBUG_LINES_READ} lines of debug log: ${errorMessage(e)}`
57 }
58
59 const justEnabledSection = wasAlreadyLogging
60 ? ''
61 : `
62## Debug Logging Just Enabled
63
64Debug logging was OFF for this session until now. Nothing prior to this /debug invocation was captured.
65
66Tell the user that debug logging is now active at \`${debugLogPath}\`, ask them to reproduce the issue, then re-read the log. If they can't reproduce, they can also restart with \`claude --debug\` to capture logs from startup.
67`
68
69 const prompt = `# Debug Skill

Callers 1

initBundledSkillsFunction · 0.85

Calls 1

registerBundledSkillFunction · 0.85

Tested by

no test coverage detected