Ignore 'node_modules' by default.
Status Fixed / completed
Maintainer reply ✓ Yes — bcherny
Activity 8 comments · opened Feb 27, 2025 · closed Feb 28, 2025
💡 Likely answer: A maintainer (bcherny, collaborator)
responded on this thread — see the highlighted reply below.
Understood that you could disallow node_modules via claude config add ignorePatterns node_modules.
However a large majority of frontend developers will try out Claude Code without knowing about this configuration parameter and will be disappointed.
(somehow /node_modules is also in my .gitignore but wasn't considered)
The result is that the first 1000 files in the prompt are node modules, and thus Claude becomes very ineffective and confused.
Would highly suggest to exclude node_modules by default.
8 Comments
We actually had this before, but found that Claude is a lot smarter when you let it grab type definitions and look through library code in node_modules. Let me see what I can do to tune this.
Thanks Boris - how about keeping it by default, but maybe:
<context name="packagesStructure">...</context>? indeed could be a good use of contextNote: my app is ~1,050 files, so makes it just about right in the cut.
Fan of your work - you redefined dev.
Me.
I tried Claude Code with a NextJS project, and for the first 2 basic prompts is cost me 1M+ input tokens. 😢
Then I realized they sent too many files and remembered the well-known node_modules issue.
I tried:
claude config add ignorePatterns "node_modules/**"from overview examples, but got this::error: unknown command 'add'What? So I tried
claude configto check options, they said:```Commands:
get [options] <key> Get a config value
set [options] <key> <value> Set a config value
remove [options] <key> Remove a config value
list [options] List all config values
help [command] display help for command
@andre-mr Make sure to update to the latest version
wow, i installed yesterday. but thanks, i updated via npm. now i got a message for
claude config addapproach:Error: 'ignorePatterns' is not a valid array config key in project configso i tried
claude config setinstead ofaddanthropic docs said and it seems to have worked:{
"dontCrawlDirectory": false,
"enableArchitectTool": false,
"hasTrustDialogAccepted": true,
"hasCompletedProjectOnboarding": true,
"ignorePatterns": "node_modules/**" 🎉
}
is that a config file somewhere? that's a global setting or per directory? i don't see those settings inside my project folder by the way.
This is done. We now ignore anything in your .gitignore, but tools can still access these. Lmk if it's feeling better! Restart to get the update.
Fixed this too! Restart to update.
Great stuff @bcherny ! It would be really nice if this was shown the user in some easy way as well. For instance, there is the documentation and the config settings but showing some of this stuff in the Claude.md or in another easy to view file (for instance .claudignore that automatically copies .gitignore). That way, users wouldn't have to search github for closed issues ;-)
Really appreciate the work btw.
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.