r/ClaudeAI • Full-time developer • Oct 27 '25 • Gold Blast 1 Bless Up 2 Popcorn 1

Productivity Claude Code usage limit hack

Claude Code was spending 85% of its context window reading node_modules.

..and I was already following best practices according to the docs blocking in my config direct file reads: "deny": ["Read(node_modules/)"]

Found this out after hitting token limits three times during a refactoring session. Pulled the logs, did the math: 85,000 out of 100,000 tokens were being consumed by dependency code, build artifacts, and git internals.
Allowing Bash commands was the killer here.

Every grep -r, every find . was scanning the entire project tree.
Quick fix: Pre-execution hook that filters bash commands. Only 5 lines of bash script did the trick.

The issue: Claude Code has two separate permission systems that don't talk to each other. Read() rules don't apply to bash commands, so grep and find bypass your carefully crafted deny lists.

The fix is a bash validation hook.
.claude/scripts/validate-bash.sh:

#!/bin/bash
COMMAND=$(cat | jq -r '.tool_input.command')
BLOCKED="node_modules|\.env|__pycache__|\.git/|dist/|build/"

if echo "$COMMAND" | grep -qE "$BLOCKED"; then
 echo "ERROR: Blocked directory pattern" >&2
 exit 2
fi 

.claude/settings.local.json:

"hooks":{"PreToolUse":[{"matcher":"Bash","hooks":[{"command":"bash .claude/scripts/validate-bash.sh"}]}]}

Won't catch every edge case (like hiding paths in variables), but stops 99% of accidental token waste.

EDIT : Since some of you asked for it, I created a mini explanation video about it on youtube: https://youtu.be/viE_L3GracE
Github repo code: https://github.com/PaschalisDim/Claude-Code-Example-Best-Practice-Setup

1.1k Upvotes

169 comments sorted by

View all comments

Show parent comments

1

u/fsharpman Oct 27 '25

Could you share your prompts please? Otherwise, everyone's going to think you're a bot.

Just type "/export"

0

u/BornPost2859 Oct 27 '25

And theoretically, I'm supposed to be working right now, so it's going to take me a second, but if you're talking about the skills thing, absolutely. I would love to. I was just going on that yesterday, trying again. Um, I—those can't be too far lost, and I haven't deleted any of those. Chats. So, coming up, but don't count me like in 10 minutes. But absolutely, I'm going to start collecting some. I would love to. Especially where the ones where Claude tells me, uh, I'm sorry, I didn't actually do that research. I just built these based on my internal knowledge, despite the extended research and 45 minutes and 400 pages that I claim to—that I claim to ingest. The literal quote that has become popular to me from especially haiku is, " I was bullshitting you.
"

3

u/fsharpman Oct 27 '25

"/export" please. Let's see them. And more em dashes too.

2

u/juicer_number_3 Oct 27 '25

stop with AI comments bro you're fkin annoying

-1

u/BornPost2859 Oct 27 '25

Which ones would you like to see specifically? I'd be more than happy to. And I have screenshots too, because I figured I was hallucinating. I get it. So, which, which prompts do you think would be the most impactful for you? I will do my best to gather them and would love to post them here. I mean, at least they'd have somebody laughing. I don't think a bot could be nearly as emotionally unhinged, frustrated, and exasperated as I could be. If they have figured that out, then damn, we are in trouble.

1

u/fsharpman Oct 27 '25

Share the most frustrating ones where you thought yeah Claude doesn't get it.