Developer builds nightly launchd script to auto-trim runaway Claude agent logs
A developer running 20+ Claude AI resident agents found their ~/.claude/logs/ directory had silently grown to over 22MB across 188 files, accumulating hundreds of kilobytes daily. Rather than deleting logs outright — which would hinder debugging — they wrote a 60-line bash script called log-rotate.sh that truncates any file exceeding 5MB down to its most recent 2,000 lines. The script also purges dated artifacts and backup files older than 30 days, and applies the same trimming logic to its own log. Scheduled via macOS launchd to run nightly at 03:45, the script successfully shrank files like agentmemory.err.log from 5.2MB to 324KB in a single pass. The approach prioritises retaining recent context over archival completeness, trading backup safety for simplicity and consistent disk hygiene.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in