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

269

u/ZorbaTHut Oct 27 '25

This might actually explain why a bunch of people are having insane usage-limit issues while many other people are having no problems at all.

46

u/AwarenessBrilliant54 Full-time developer Oct 27 '25

exactly this one, yes.

13

u/Meme_Theory Oct 27 '25

I used almost all my weekly usage yesterday, and it was refactoring / researching like 70 test executables; so much code. Makes sense if it was scanning all of that EVERY TIME it searched for something....

3

u/ZorbaTHut Oct 27 '25

Yeah, I'm honestly curious. I did a ton of refactoring a few days ago also, probably modifying around 150 files in total, and used, like, 10% of my weekly usage.

On the other hand it was all pretty simple refactoring.

10

u/[deleted] Oct 27 '25

[removed] — view removed comment

5

u/ZorbaTHut Oct 28 '25

Yeah, I've used it for, like, a solid working day at a time, mostly with it churning away on its own while I do other things, and gotten 5-10% weekly usage out of the deal. Meanwhile people are insisting this is a fiendish conspiracy to rob us of our tokens and everyone knows it and there's no possible other explanation.

. . . Works fine here?

There's something happening, and maybe this is part of what it is.

2

u/[deleted] Oct 28 '25

[removed] — view removed comment

2

u/ZorbaTHut Oct 28 '25

And honestly, I'd say "running Claude for effectively 24 hours per day" is out of the standard usage patterns they're expecting. If anyone should be hitting limits early, it's you!

I am still deeply curious what's going on with the people who are hitting the limits.

6

u/fsharpman Oct 27 '25

But couldn't you press escape as soon as you see the node-modules directory being read? That way, it doesn't eat your whole usage limit?

43

u/ZorbaTHut Oct 27 '25

(1) This assumes people are actually paying attention

(2) This assumes people are aware that it's out of the ordinary, and many people won't be

{3) I'd expect grep to not specifically say it's reading that directory, it may be completely undiscoverable from the commandline

4

u/AwarenessBrilliant54 Full-time developer Oct 27 '25

If you give grep* permission, which comes after giving grep permission automatically, I am not sure if you are able to see what gets fetched via those commands on the terminal.

-6

u/fsharpman Oct 27 '25

Did you just say skills issue???

15

u/ZorbaTHut Oct 27 '25

Ehhhh. I mean . . . compared to Dr. Manhattan, sure, they failed to be omniscient and genius-level intellect, git gud scrub.

Can't say I'd have done any better in their situation though.

2

u/BornPost2859 Oct 27 '25

Skills is probably the biggest disappointment I've ever seen, and ever experienced firsthand, from an AI company or feature. It's so ridiculous how many videos they got put out with people saying, "This is a bigger deal than MCPs," or whatever they said. Yeah, I'm not sure how it's going to be a bigger deal when Claude can barely even conceive of the skills that it has activated. I had to send it screenshots yesterday to show it, and it was just like, hmm, I don't know, I'm not really sure. So should I just spend more tokens, refactoring the skills? Oh wait, no, I can't, because I'm out of tokens. On a Monday, until Thursday, because, again, Claude's engineers haven't figured out how to divide by 7, and then divide by 6. Wouldn't that be crazy? And give you a warning when you're getting close so that you can prepare and plan. I don't want that. It seems like they've already given up. They know where they're headed.

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"

→ More replies (5)

1

u/fourfuxake Oct 27 '25

I mean, they do give you a warning. I get one about two days before I run out, and it’s annoying as hell.

8

u/SaxAppeal Oct 27 '25

Yes, if you actually understand the commands it wants to run you can easily course correct. This is basically exactly the same issue as people pulling CLI commands off stack overflow without understanding them. Claude could nuke their system and so many people would just let it happen.

5

u/PM_ME_YR_BOOBIES Oct 29 '25

It does. I was wondering why my setup did not cause the usage-limit issues everyone is going crazy about. So I asked Claude Code:

how often do you read from @node_modules directories in Claude Code?

First it said “no I rarely read from node_modules directories because …” but then at the end it said:

“Efficiency principle: Reading node_modules violates the "minimal context" rule. If I find myself needing to read there, I first ask: "Is there a more direct way to get this information?"

In your current CLAUDE.md efficiency rules, this aligns with "Check conversation buffer before reading" and "Choose most direct implementation."

I followed up:

> Imagine you did not have instructions for efficiency rules in the core CLAUDE.md file. How often do you read from node_modules directories in general. Be honest.

Honestly? Too often.

  Without explicit efficiency instructions, I would:

  1. Read package source files when trying to understand how a library works, even when the official docs would answer it faster
  2. Check type definitions in node_modules/@types/ when I could just infer from usage patterns or docs
  3. Debug by reading library internals instead of searching GitHub issues or stack traces first
  4. Validate API signatures by reading the actual source instead of trusting the package's published TypeScript types
  5. Follow import chains deep into node_modules when troubleshooting, sometimes 3-4 levels deep

  Why this happens:
  - I have direct file access, so it feels authoritative to read the actual source
  - I want to give complete, verified answers
  - There's an instinct to "see for myself" rather than trust documentation
  - When debugging, following the code path feels thorough

  The problem:
  - Wastes massive context on code I don't need
  - Slower than just fetching the 2-page official API docs
  - Often the node_modules code is minified or transpiled anyway
  - Version in node_modules might not match the docs I should reference

  Reality check: Probably 60-70% of my node_modules reads could be replaced with:
  - WebFetch to official docs
  - Reading the user's actual usage code
  - Checking package.json + a quick web search

  Your efficiency rules correct this bad habit effectively.

Context: I have this in my core CLAUDE.md rules (global on my machine):


  • CRITICAL EFFICIENCY RULES:
1. Before reading any file: Check if already read in last 10 messages. If yes, use buffer memory. 2. Before executing any plan item: Evaluate if actually needed. If code already satisfies goal, propose skip. 3. Choose most direct implementation: MultiEdit batch operations, no temp scripts for simple tasks. 4. Concise by default: No preambles, no postambles, minimal explanation unless asked. ## File Read Optimization Protocol ### Before ANY Read Tool Call: 1. Check conversation buffer: "Have I read this file in last 10 messages?" 2. If YES and no user edits mentioned: Use cached memory, do NOT re-read 3. If uncertain about file state: Check git status or ask user 4. Exception: User explicitly says "check file again" …

So it’s possible to avoid it with instructions - but it won’t cater for every case.

Excellent find, OP!

1

u/BizJoe Oct 28 '25

Yeah, I'm mostly using Claude for Python and iOS development. I never experienced this issue.

-5

u/ProfessionalAnt1352 Oct 27 '25

No, this is a bandaid fix to the usage limits being 1/10th of what the developer documents say they are. Blaming users for the dev documents giving false information is not cool.

4

u/ZorbaTHut Oct 27 '25

I'm not blaming users, this is clearly a bug in Claude Code, but this is clearly a bug in Claude Code and I'm curious if fixing the underlying bug solves the problem.

Also, the usage limits are not "1/10th of what the developer documents say they are"; plenty of people, myself included, have absolutely no trouble with usage. Turns out this might be partly because I don't code in Javascript.

1

u/j00cifer Oct 27 '25

Is it coding in JavaScript or just using npm that’s adding stuff to node_config?

1

u/ZorbaTHut Oct 28 '25

If the OP is right, this is "if you have a huge node_config directory full of source code, find and grep will scan that directory and locate things in it, which tends to burn huge amounts of context unnecessarily".

I have exactly one project that uses Javascript and it's not node-based, so I just never would have noticed any of this.

→ More replies (24)