cd /news/ai-agents/how-a-claude-code-session-froze-my-m… · home › topics › ai-agents › article
[ARTICLE · art-173089] src=dev.to ↗ pub= topic=ai-agents verified=true sentiment=↓ negative

How a Claude Code session froze my Mac with a 288 GB text file

A developer traced a frozen Mac to a Claude Code session whose shell loop grew a single text file to 288 GB in about 12 minutes. The loop redirected output to /tmp/qa/review-all.txt while globbing /tmp/qa/review-*.txt, so the output file matched its own input pattern; BSD cat on macOS, unlike GNU coreutils, does not detect that an input is the output file and kept appending until a write failed at 96% disk usage. The developer killed the lingering cat and grep processes, deleted the file to recover space from 37 GiB to 306 GiB, and recommended excluding the output path from the glob, checking file sizes with stat, and setting ulimit -f for agent-run commands.

recommendation

When agents run shell loops that write files, exclude the output path from input globs and set ulimit -f so a runaway write is killed before it fills the disk.

more in playbook: Securing agents and AI tools
by read3 min views10 publishedNov 20, 2026

My Mac suddenly became unresponsive this morning. The disk was almost full, and one text file in /tmp had grown to 288 GB in about 12 minutes.

I run a lot of Claude Code sessions at once, so the first question was which one, if any, was writing it.

lsof lists the processes that have a file open:

lsof /tmp/qa/review-all.txt

It showed a cat and a grep. Walking up the parent chain with ps -o pid,ppid,command -p <pid> led from both of them to shells started by the same Claude Code session.

That session was running a design review over a set of pages. Each review wrote a small text file of findings, and the last step combined them into one file:

for f in /tmp/qa/review-*.txt; do
  echo "=== $(basename "$f")"
  cat "$f"
done > /tmp/qa/review-all.txt

The output file is review-all.txt, and that name also matches review-*.txt.

The redirect at the end applies to the whole loop, so the shell creates review-all.txt before it expands the glob. The new, empty output file lands in the list of inputs. When the loop reaches it, cat starts reading the file it is appending to. Every block it reads is written back onto the end, so the end of the file moves away as fast as cat reads, and cat never gets there.

The one-line version has the same trap, with a delay:

cat /tmp/qa/review-*.txt > /tmp/qa/review-all.txt

Here the glob is expanded before the redirect creates the file, so the first run is fine. On the second run the old review-all.txt is one of the inputs, and the loop starts. Agents rerun commands all the time.

I ran the same loop on a Linux machine with GNU coreutils and got this:

cat: review-all.txt: input file is output file

GNU cat checks whether an input is the same file as its output and skips it. The cat that ships with macOS comes from BSD and has no such check, so it keeps going until a write fails. Mine stopped on its own after 12 minutes, probably when a write failed for lack of space. By then the file held 288 GB, about 400 MB for every second it ran, and the disk was 96% full.

The command ran into the agent's 10-minute command timeout, so the tool moved it to the background and the agent went on with other work. Two more full reads of the file followed:

grep -c over the combined file to count the clean pages. That grep had to read all 288 GB.cat review-all.txt | wc -c, which reads every byte again just to count them. Both were still running when I found the file. Neither changed it, but together they kept the disk busy reading hundreds of gigabytes. A person in a hurry could have written every one of these commands.

Stop anything that still has the file open before you delete it. Deleting a file only removes its name; the space comes back when the last process holding it closes.

lsof /tmp/qa/review-all.txt
kill <pid>
rm /tmp/qa/review-all.txt

Free space went from 37 GiB back to 306 GiB.

> /tmp/qa/combined.md). Or skip it explicitly at the top of the loop: [ "$f" = /tmp/qa/review-all.txt ] && continue. ls -l or stat. They read metadata. cat file | wc -c reads the whole file. This is worth putting in the instructions you give your agents.ulimit -f kills a process with SIGXFSZ when a file it writes passes the limit, and a generous limit still stops a runaway file long before the disk fills. The units differ between shells: zsh counts 512-byte blocks and bash counts 1 KB blocks, so ulimit -f 200 means 100 KB in zsh and 200 KB in bash.

── more in #ai-agents 4 stories · sorted by recency
── more on @claude code 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/how-a-claude-code-se…] indexed:0 read:3min 2026-11-20 · —