Running into this?

If your laptop runs hot

Situations that heated up my Mac while working with agents, and how I solved them. Find yours, hand the decision to your agent.

I turned off the maintenance Git starts on its own after every commit; maintenance now runs once an hour, as a single copy.
before76 git maintenance runs at once
afterat most 1
turn off git's automatic maintenance (gc.auto · maintenance.auto) and switch to hourly scheduled maintenance
Text for your agent · 23 lines
Situation: many agents commit often in the same git repository. Activity Monitor shows many `git maintenance run --auto`, `git repack` and `git pack-objects` processes at the same time; the machine is running hot.

Why: after a commit, once a threshold is crossed, git starts maintenance in the background (`git maintenance run --auto --detach`). This background run holds no lock (observed on git 2.54): while one repack takes minutes, every new commit starts another one. I had 76 concurrent repacks in 10 minutes, each repacking 11 GB of history from scratch, and a commit object was lost in the race.

Do:
1. Turn off commit-triggered maintenance in this repository:
   git config --local gc.auto 0
   git config --local maintenance.auto false
2. Stop the running maintenance together with its child processes, then a minute later delete the temporary packs they left behind (this stops maintenance in every repository on this machine; a push, fetch or clone keeps running):
   pkill -TERM -f 'git(-core/git)? (maintenance run|repack|pack-objects .*objects/pack/)'
   sleep 60; find "$(git rev-parse --git-path objects/pack)" -name 'tmp_*' -mmin +1 -delete
3. Set up maintenance to run on a schedule, as a single copy:
   git maintenance start
   git config --local maintenance.gc.enabled false
   git config --local maintenance.prefetch.enabled false
   git config --local maintenance.loose-objects.schedule hourly
   git config --local maintenance.incremental-repack.schedule daily

Verify:
- git fsck --connectivity-only --no-reflogs --no-dangling → prints nothing (no missing objects)
- pgrep -f 'git(-core/git)? (maintenance run|repack|pack-objects .*objects/pack/)' | wc -l → 0 (above 0 only while the hourly scheduled run is going)

Don't: start a full `git gc` or `git repack -a` while doing this.
I don't leave searches over big folders to macOS's own grep: I keep Claude Code up to date, and since 2.1.117 it runs the grep the agent types in Bash with its own fast grep; any big search that doesn't go through it I run with rg. I removed my hook that rewrote grep into rg: in a week it had rewritten 0 real searches.
beforemacOS grep over 96 GB of chat history: 491 s
afterrg: 8.7 s
If you see "grep" in Activity Monitor, stop it with kill and have the agent redo that search with rg; in Claude Code, if type grep doesn't print "function", run claude update
Text for your agent · 22 lines
Situation: You're working with an agent (Claude Code or Codex) on macOS. In Activity Monitor a process named "grep" has kept one core at 100% for minutes. The agent is searching a big folder (~/.claude/projects, ~/.codex/sessions, a log folder) or searching one folder for hundreds of patterns at once (grep -rlF -e … -e … or grep -rlF -f patterns.txt), and the command hasn't finished in half an hour. If the process stuck at 100% in Activity Monitor isn't "grep" but a version number (e.g. 2.1.322), this isn't your situation: that's Claude Code itself or its fast grep.

Why: What runs under the name "grep" is macOS's own grep (/usr/bin/grep, BSD grep 2.6.0). On large text it's several times slower than ripgrep (rg), and tens of times slower on text full of non-ASCII letters (Turkish, for one); the time goes to the CPU, not the disk; the number of patterns multiplies the slowness. On my machine grep -rl over 96 GB of Codex chat history took 491 s (8 minutes), rg -l 19 s on a cold disk; a grep with 1,147 patterns ran for 29 minutes at 100% CPU over 435 MB and never finished.
Since 2.1.117 Claude Code doesn't hand the agent's grep to it: when it opens Bash it installs a shell function named `grep` and runs the search with its built-in ugrep (macOS and Linux; Claude Code installed with npm installs the same binary today). In Activity Monitor and top this process shows up not as "grep" but as Claude Code's version number (e.g. 2.1.322, the same name as Claude Code's own process), and in ps -axo args as "ugrep". On the Mac mini with Claude Code 2.1.322, warm cache: on one 457 MB day of Codex chat, macOS grep 2.20 s, Claude Code's grep 0.03 s, rg 0.02 s, all three the same 2 files; 1,147 patterns with -F -f: ugrep 0.06 ↔ rg 0.05 s.
There are three ways to fall back to macOS grep: (a) Codex: it doesn't shadow grep, every grep the agent writes is /usr/bin/grep (Codex's own command output: "grep is /usr/bin/grep"); Codex already writes most searches with rg, the slow one is the search it writes with grep. (b) Claude Code is older than 2.1.117, or the command that launches Claude Code asks for the Grep or Glob tool (--allowedTools, --tools, the Agent SDK's allowedTools or tools list): when either tool is requested, Claude Code leaves grep in Bash to macOS grep (the allow list in settings doesn't do this). The local agent the Claude desktop app opens on a Mac doesn't shadow grep either. (c) In Claude Code, grep runs from inside another program (timeout 60 grep …, … | xargs grep …, find … -exec grep …, bash -c '… grep …', a .sh script, command grep, /usr/bin/grep) or carries a flag Claude Code doesn't pass to its grep (-z, --null and others). Claude Code's grep rejects a two-sided context pattern like .{0,80}word.{0,80} with "exceeds complexity limits"; the agent then rewrites the same search with /usr/bin/grep (on one 324 MB file macOS grep went past 10 minutes for me, rg 0.04 s).
Claude Code's grep skips files in .gitignore and binary files, and doesn't enter version-control folders (.git, .hg, .svn, .jj …). If what you're looking for is there, the agent won't find it; then have it write rg -uuu (searches everything).

Do:
1. In Terminal, see which command is running: ps -axo pid,etime,%cpu,args | awk '$4 == "grep" || $4 == "/usr/bin/grep"'. It prints one macOS grep per line, with how long it has been running and how much CPU it uses; Claude Code's ugrep doesn't appear in this list. Stop the line carrying the agent's search: kill <pid> (the first number on the line); if you don't, that grep keeps holding the core even after the rg search finishes. A killed grep gives no result: if the agent says "143" or "no matches found", the search never happened, and you'll have it redone with rg in step 3. If you're in Codex, go to step 3.
2. If you're in Claude Code, tell the agent: "run type grep and show the output exactly". If it prints a line containing "function" (zsh: "grep is a shell function from …/shell-snapshots/…", bash: "grep is a function"), the agent's grep is already Claude Code's ugrep and the command you saw in step 1 escaped the function: go to step 3. If it prints "grep is /usr/bin/grep", in Terminal: claude --version. If it's below 2.1.117: claude update. Quit and reopen Claude Code and repeat this step. If it's 2.1.117 or newer and the agent was opened by the Claude desktop app: go to step 3. Otherwise the command that launches Claude Code (or the Agent SDK's allowedTools/tools list) contains Grep or Glob; updating won't change that. Remove it from the list, or if you're keeping the Grep tool, go to step 3.
3. Tell the agent to write the search you stopped in step 1 with rg instead of grep (rg -uuu …, timeout 60 rg -uuu …, … | xargs rg -uuu …; -uuu also searches hidden files and files in .gitignore, as grep does). If rg is missing (Codex brings its own rg, Claude Code and Terminal don't): brew install ripgrep. For hundreds of patterns, one call: rg -uuu -lF -f patterns.txt <folder>.
4. If you installed the grep-rg.pl hook from an older version of this package, remove it. With Claude Code's own grep in place the hook gains no speed and breaks two things: (a) it makes the agent search folders in .gitignore too (node_modules, build output): in one repo grep -rl useState . took 0.6 s and found 0 files with the agent's grep, 59 s and 125 files with the rg the hook turned it into; (b) in a mode that doesn't skip permissions (without --dangerously-skip-permissions), grep runs without approval but the /opt/homebrew/bin/rg --no-config … the hook writes returns "This command requires approval", even with a Bash(grep:*) permission in settings. To remove it, delete the hook mentioning grep-rg.pl under "PreToolUse" in ~/.claude/settings.json, then: rm -f ~/.claude/hooks/grep-rg.pl ~/.claude/hooks/grep-rg.log. Reopen Claude Code.

Verify:
- In Claude Code, to the agent: "run type grep; grep -V | head -1" → a line containing "function" and "ugrep 7…". If the second prints "grep (BSD grep, GNU compatible) 2.6.0-FreeBSD", Claude Code didn't install its grep: step 2.
- In Codex, to the agent: "type grep; grep -V | head -1" → "grep is /usr/bin/grep" and "BSD grep": in Codex every search written with grep is macOS grep; in a big folder, step 3.
- The old hook is gone (if you did step 4, in Terminal): grep -c grep-rg ~/.claude/settings.json → 0.

Don't:
- Don't replace grep with rg through an alias or by putting an rg named "grep" on PATH: the flags differ (in rg -h is help and -E is encoding; in plain grep + ? | ( ) are literal characters, in rg they're special), and it silently gives wrong results. Claude Code already removes any grep alias when it installs its function.
- Don't install a hook that rewrites the agent's command to rg (PreToolUse updatedInput): Claude Code asks for permission based on the rewritten command. grep and plain rg -uuu -lH … run without approval, but rg with a full path, --no-config, --include-zero or -I needs approval: the hook adds an approval prompt to every search.
- Don't build a loop that calls a separate grep or rg per pattern (for p in …; do grep …; done): each pattern reads the folder from scratch. Write the patterns to a file and make one call: rg -uuu -lF -f patterns.txt <folder>.