Back to Feed
r/ClaudeCode
by BoshBoyBinton
New
Claude Code crashing and creating HUGE debug files *FIX*
1 points
0 comments
100% upvoted
View on Reddit
Content
Hello, recently I've been having my claude code instances crash and cause unneeded errors in my production pipeline. It's not the end of the world since the most important context can be saved by copying the conversation and just pasting it into a new one, but it's not a proper fix and is missing a large portion of the context that isn't displayed in the terminal.
Anyways, the bug is basically a runaway debugger that gets stuck writing HUGE amounts of logs to a debug file until you stop the container which effectively freezes the terminal. I found a fix that works with the bug so it'll work until the bug is fixed. Basically, I just have a script run in the background that reads all of the debug files and if they every grow too fast then the file gets deleted. This will happen a couple times until the debugger tries to write to a file that doesn't exist and then throws an internal error. This error stops the infinite debug cycle which prevents the giant files being created AND unfreezes the terminal. I'm extremely happy that the fix was so simple since it crashed at least 5 times previously and was really getting on my nerves.
The way to implement the fix is to create this shell file:
`#!/bin/bash`
`DEBUG_DIR="/root/.claude/debug"`
`mkdir -p "$DEBUG_DIR"`
`while true; do`
`for file in "$DEBUG_DIR"/*.txt; do`
`[ -f "$file" ] || continue`
`size1=$(stat -c%s "$file" 2>/dev/null || echo 0)`
`sleep 2`
`size2=$(stat -c%s "$file" 2>/dev/null || echo 0)`
`growth=$((size2 - size1))`
`if [ "$growth" -gt 2000000 ]; then`
`echo "$(date): Runaway debug file detected (grew ${growth} bytes), deleting..."`
`rm -f "$file"`
`fi`
`done`
`sleep 5`
`done`
and then run it in the background. If you're using docker compose then you can simply add it to a volume and then change the entrypoint to this:
`entrypoint: ["/bin/bash", "-c", "chmod +x /scripts/claude-watchdog.sh && /scripts/claude-watchdog.sh & exec /bin/zsh"]`
Comments
No comments fetched yet
Comments are fetched when you run cortex fetch with comment fetching enabled