Need for dedicated .claudeignore file - .gitignore is insufficient for multi-platform projects
Problem
The current implementation suggests using .gitignore to exclude directories from Claude Code analysis (as mentioned in #79). However, this approach is inadequate for multi-platform projects where you need context-specific directory exclusion that differs from your Git workflow.
Use Case
I have a large iOS/Mac project with shared code and the following structure:
- Root-level directories shared between platforms
- Platform-specific directories (iOS-specific and Mac-specific folders)
- When working on iOS features, I need to ignore Mac-specific directories to save tokens
- When working on Mac features, I need to ignore iOS-specific directories
The problem: I cannot add Mac directories to .gitignore when working on iOS because:
- Both platforms are part of the same repository
- Mac directories contain legitimate code that needs to be tracked in Git
- The exclusion needs are context-dependent, not permanent
Current Workaround Limitations
The suggested solution of "adding large build directories to your .gitignore file" doesn't work because:
- These aren't build directories - they're source code directories
- They shouldn't be permanently ignored by Git
- The ignore patterns need to change based on current development context
Proposed Solution
A dedicated .claudeignore file (or similar mechanism) that:
- Works independently of
.gitignore - Allows temporary/context-specific exclusions
- Can be easily modified without affecting Git workflow
- Supports different ignore patterns for different development contexts
Related
This extends the discussion in #79 about directory exclusion, but addresses cases where .gitignore is not a viable solution.
Environment:
- Large multi-platform (iOS/Mac) codebase
- Shared root-level directories
- Platform-specific subdirectories that need conditional exclusion
Bump to this. Kinda ridiculous I either don't commit something (to keep it in context, but not on GitHub) or Claude doesn't care that it exists, with no in-between
Bump to this. Kinda ridiculous I either don't commit something (to keep it in context, but not on GitHub) or Claude doesn't care that it exists, with no in-between
Agreed (see below for a poorly working workaround). Both Cline and Roo, two open source projects that likely have less resources and community involvement than CC, have had this feature for months.
Use case:
I sometimes don’t want Claude.md and other memory related files to be version controlled and will store them in a foobar/ directory in the root. Yet if I add them to gitignore, CC has difficulty managing these files even with project/global instructions instructing the model to look at the specific foobar/ dir for all memory related files and claude.md. This workaround is hacky and works when I explicitly instruct CC to look/interact with memory files in foobar/, but it is hacky and annoying. Furthermore, the “@“ feature won’t recognize these files. CC shouldn’t be blind to everything in gitignore.
+1
+1 it is very inconvenient that content in .gitignore also blocks access to Claude Code
+1
+1
+1, it's called .gitignore, not .claudeignore
I like this idea; in the meantime, updating settings.local.json worked for me 👍
+1
+1
+1
+1
+1
+1
+1
+1
I'm the OP of this thread. It is possible — it's just not well documented.
-
Exit Claude Code.
-
In the terminal, run:
claude config add ignorePatterns "MacTests/" -
Start Claude Code again.
This will exclude the MacTests/ folder from Claude Code’s memory.
The setting is also saved in the hidden config file, in case you’d like to review it later.
It’s easy to test — just restart Claude Code after applying the change, then ask it about files in that folder. It won’t be able to tell you what’s inside.
Hope this helps
That solves the issue when we want to exclude something else on top of what's defined in .gitignore, but not when we want to include something that's in .gitignore, right?
That's correct.
Exactly, for me the issue is that I want to include something in CLAUDE that .gitignore excludes for GIT commit.
+1
+1
+1
Yes, I frequently copy other .md and useful docmentation into a tmp/ or reference/ directory which I ignore in .gitignore but want Claude to be able to access, so a .claudeinclude would be great or even just a way to configure this in regular claude settings with an array of includ/exclude paths.
+1
FWIW I tried using /add-dir and additionalDirectories in .claude/settings.json and no luck – it seems like there's a race condition / precedence problem where it's putting a priority on .gitignore instead of those, but haven't quite done enough testing to prove this.
I'm the OP of this thread. It is possible — it's just not well documented.
- Exit Claude Code.
- In the terminal, run:
claude config add ignorePatterns "MacTests/"- Start Claude Code again.
This will exclude the
MacTests/folder from Claude Code’s memory.The setting is also saved in the hidden config file, in case you’d like to review it later.
It’s easy to test — just restart Claude Code after applying the change, then ask it about files in that folder. It won’t be able to tell you what’s inside.
Hope this helps
This prints a deprecation warning, and puts the rule inside the global ~/.claude.json, which doesn't get synced via git.
@NightMachinery how this helps with the problems mentioned above like "want to include something in CLAUDE that .gitignore excludes for GIT commit"?
@NightMachinery how this helps with the problems mentioned above like "want to include something in CLAUDE that .gitignore excludes for GIT commit"?
It can have a syntax for force-including files that overrides .gitignore. Excluding is the more important problem for me, though.
Hey folks, we recommend using the deny read rules to exclude any files you want Claude to not read. https://docs.anthropic.com/en/docs/claude-code/settings#excluding-sensitive-files
Running in a subfolder and using /add-dir to pull in those things you want Claude to look at is another option.