{"slug": "how-a-claude-code-session-froze-my-mac-with-a-288-gb-text-file", "title": "How a Claude Code session froze my Mac with a 288 GB text file", "summary": "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.", "body_md": "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.\n\nI run a lot of Claude Code sessions at once, so the first question was which one, if any, was writing it.\n\n`lsof` lists the processes that have a file open:\n\n```\nlsof /tmp/qa/review-all.txt\n```\n\nIt 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.\n\nThat 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:\n\n```\nfor f in /tmp/qa/review-*.txt; do\n  echo \"=== $(basename \"$f\")\"\n  cat \"$f\"\ndone > /tmp/qa/review-all.txt\n```\n\nThe output file is `review-all.txt`, and that name also matches `review-*.txt`.\n\nThe 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.\n\nThe one-line version has the same trap, with a delay:\n\n```\ncat /tmp/qa/review-*.txt > /tmp/qa/review-all.txt\n```\n\nHere 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.\n\nI ran the same loop on a Linux machine with GNU coreutils and got this:\n\n```\ncat: review-all.txt: input file is output file\n```\n\nGNU `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.\n\nThe 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:\n\n`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.\nBoth 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.\n\nStop 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.\n\n```\nlsof /tmp/qa/review-all.txt\nkill <pid>\nrm /tmp/qa/review-all.txt\n```\n\nFree space went from 37 GiB back to 306 GiB.\n\n`> /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.", "url": "https://wpnews.pro/news/how-a-claude-code-session-froze-my-mac-with-a-288-gb-text-file", "canonical_source": "https://dev.to/hitesh_sisara/how-a-claude-code-session-froze-my-mac-with-a-288-gb-text-file-2h0", "published_at": "2026-11-20 06:07:45+00:00", "updated_at": "2026-11-20 06:13:09.355744+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "developer-tools"], "entities": ["Claude Code", "macOS", "GNU coreutils", "BSD"], "also_reported_by": [], "takeaway": "A shell loop that redirects into a file matching its own glob (review-*.txt > review-all.txt) makes BSD cat on macOS read and re-append its own output indefinitely, so exclude the output path from the glob or set ulimit -f to cap runaway writes.", "recommendation": {"advice": "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.", "playbook": "agent-security", "playbook_url": "https://wpnews.pro/playbooks/agent-security"}, "alternates": {"html": "https://wpnews.pro/news/how-a-claude-code-session-froze-my-mac-with-a-288-gb-text-file", "markdown": "https://wpnews.pro/news/how-a-claude-code-session-froze-my-mac-with-a-288-gb-text-file.md", "text": "https://wpnews.pro/news/how-a-claude-code-session-froze-my-mac-with-a-288-gb-text-file.txt", "jsonld": "https://wpnews.pro/news/how-a-claude-code-session-froze-my-mac-with-a-288-gb-text-file.jsonld"}}