Oops, I grepped it away
I was cleaning up my Claude Code instructions. Instructions are like code: the less, the better. None at all is best. And models get smarter every day, so they need fewer of them.
Then I came across this one in my global instructions:
Never pipe large output straight to
tail/head/grepand lose the rest. Redirect the full output to a file first (> /tmp/<name>.log 2>&1), then view a slice of it. Do the same for the long-lived processes.
Agents pipe output like that to save context. But when the filter misses, they may rerun the whole command.
Is the instruction still needed? I asked Claude to dig through my session history and find out. My verdict: not a game changer, but it works.
One run, many looks
A long command runs once, and Claude looks into its output as many times as it needs. After one fix, a 2-minute pnpm check went red. First Claude checked how many tests failed, then which file, then the error, then took a closer look at a few lines of it. One run, four looks. Without the file, every new look would have meant another 2-minute run.
Some commands are better not rerun
Now and then, Claude came back to the output of a command that changed something, like a migration, a database sync or a dependency update:
- A database import into a staging environment was taking suspiciously long. Restarting it just to see where it got stuck would mean overwriting the staging database all over again. Instead, Claude looked into its log.
- One command ran a dependency update and then an install, but showed only the install's output. The update had failed, and Claude found its error in the update's own log, without running anything again.
There's one more perk, and this one is for me: when a long process is running, I can open its log and see how it's going.
The instruction costs almost nothing
Almost always, the file is read in the same command that writes it:
mise db:sync ... > /tmp/x.log 2>&1; echo "exit $?"; tail -15 /tmp/x.logIt doesn't burden Claude and doesn't burn a ton of tokens.
On fast commands, Claude ignores it, and that's fine
There are thousands of pipes like git status --short | head, and rerunning one with a different filter costs seconds.
So I kept this one, and I don't regrep it.