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.