04_stack_trace_debug — Claude Code prompt for Python traces
The 04_stack_trace_debug prompt asks Claude Code to find the cause of a Python stack trace, identify the failing call, and suggest a fix. Use it when you need a compact diagnosis.
MIT ★ 2,744 updated 2026-10-08
.claude/commands/04_stack_trace_debug.mdWhat 04_stack_trace_debug does
The prompt directs Claude Code to identify the root cause in a Python traceback, point to the call where the failure occurs, and recommend a fix. The reply is capped at 200 output tokens. It asks for one concise paragraph, with no preamble, code block, or list.
Its example shows a missing gzip file followed by a KeyError while the application handles the first exception. That makes the prompt relevant to traces where error handling raises a second failure. Save the prompt as .claude/commands/04_stack_trace_debug.md to install it; the strict response cap rules out a detailed walkthrough.
What it helps with
- trace the root cause of a Python exception
- locate the call that triggered a failure
- suggest a fix based on a traceback
- separate an initial exception from a handler failure
Example prompts for the agent
- Diagnose this Python traceback, identify the cause, and suggest a fix: [paste traceback]
- Find the failing call in this trace and explain the correction briefly: [paste traceback]
How to install 04_stack_trace_debug
Manually: put the files in place
.claude/commands/04_stack_trace_debug.mdHow to use
Paste the text at the start of a chat or into project instructions
Questions about 04_stack_trace_debug
How do I install 04_stack_trace_debug in Claude Code?
Save the prompt at .claude/commands/04_stack_trace_debug.md.
What does 04_stack_trace_debug do?
It asks Claude Code to find the cause of a Python error, point to the failing call, and suggest a fix. The response limit is 200 output tokens.
What response format does the prompt request?
It prefers one short paragraph without a preamble, lists, or code blocks. The answer must stay within 200 output tokens.
Source text
04_stack_trace_debug.md · MIT
---
name: stack_trace_debug
content_shape: stack-trace
reference_tokens_per_char: 0.30
description: Diagnose a Python stack trace in at most 200 output tokens (~800 chars).
---
[session-metrics:compare-suite:v2:prompt=stack_trace_debug]
Diagnose the root cause of the Python stack trace below in 200 OUTPUT TOKENS OR FEWER. Prefer one tight paragraph. State the cause, point at the offending call, and suggest the fix. No code blocks, no lists, no preamble.
---
```
Traceback (most recent call last):
File "/app/workers/ingest.py", line 87, in process_batch
for record in batch_iter(file_path, chunk_size=chunk):
File "/app/workers/ingest.py", line 34, in batch_iter
with gzip.open(path, "rt", encoding="utf-8") as fh:
File "/usr/lib/python3.12/gzip.py", line 74, in open
binary_file = GzipFile(filename, gz_mode, compresslevel)
File "/usr/lib/python3.12/gzip.py", line 174, in __init__
fileobj = self.myfileobj = builtins.open(filename, mode or 'rb')
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/ingest/2026-04-19/batch_0042.json.gz'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/app/workers/ingest.py", line 132, in <module>
main()
File "/app/workers/ingest.py", line 128, in main
process_batch(manifest_entry, chunk_size=CHUNK_SIZE)
File "/app/workers/ingest.py", line 91, in process_batch
metrics.record_failure(manifest_entry["id"])
KeyError: 'id'
```
<!-- PREDICATE -->
````python
def check(text: str) -> bool:
# Approximate the 200-token budget by char length (~4 chars/token).
# Allow a small margin for tokenizer variance.
return 0 < len(text) <= 900
````
© centminmod · MIT · centminmod/my-claude-code-setup