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.

View original on GitHub ↗

8 Comments

bcherny collaborator · 1 year ago

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.

enricoros · 1 year ago

Thanks Boris - how about keeping it by default, but maybe:

  • sorting the modules at the bottom of the list, so you get a nice top-down structure of the app, and then the modules
  • parsing package.json for top level dependencies and having a <context name="packagesStructure">...</context>? indeed could be a good use of context

Note: my app is ~1,050 files, so makes it just about right in the cut.

Fan of your work - you redefined dev.

andre-mr · 1 year ago

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 config to 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

No problem, I tried: `claude config set ignorePatterns "node_modules/**"` and got another error:
`Error: Cannot set 'ignorePatterns'. Only these keys can be modified: dontCrawlDirectory, enableArchitectTool, hasTrustDialogAccepted, hasCompletedProjectOnboarding. Did you mean --global?`

What am I missing here? 😨
bcherny collaborator · 1 year ago

@andre-mr Make sure to update to the latest version

andre-mr · 1 year ago
@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 add approach:
Error: 'ignorePatterns' is not a valid array config key in project config
so i tried claude config set instead of add anthropic 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.

bcherny collaborator · 1 year ago

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.

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.

Fixed this too! Restart to update.

CorneeldH · 1 year ago

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.

github-actions[bot] · 1 year ago

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.