claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

Need for dedicated .claudeignore file - .gitignore is insufficient for multi-platform projects

Open houmie opened this issue 7 months ago • 4 comments

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:

  1. Both platforms are part of the same repository
  2. Mac directories contain legitimate code that needs to be tracked in Git
  3. 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

houmie avatar May 25 '25 07:05 houmie

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

ZachHandley avatar Jun 24 '25 23:06 ZachHandley

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.

lobinator avatar Jun 26 '25 17:06 lobinator

+1

b-tops avatar Jun 28 '25 14:06 b-tops

+1 it is very inconvenient that content in .gitignore also blocks access to Claude Code

danielraffel avatar Jun 30 '25 16:06 danielraffel

+1

dnichols4 avatar Jul 02 '25 01:07 dnichols4

+1

zhyc9de avatar Jul 02 '25 02:07 zhyc9de

+1, it's called .gitignore, not .claudeignore

courthead avatar Jul 03 '25 15:07 courthead

I like this idea; in the meantime, updating settings.local.json worked for me 👍

geraldalewis avatar Jul 03 '25 19:07 geraldalewis

+1

vukdavid avatar Jul 04 '25 10:07 vukdavid

+1

kamellperry avatar Jul 07 '25 23:07 kamellperry

+1

matousek-martin avatar Jul 10 '25 08:07 matousek-martin

+1

sudarshan227 avatar Jul 10 '25 17:07 sudarshan227

+1

Sanmonsua avatar Jul 10 '25 18:07 Sanmonsua

+1

lukasbloom avatar Jul 13 '25 12:07 lukasbloom

+1

smith-ai-1 avatar Jul 14 '25 13:07 smith-ai-1

+1

notspammy11 avatar Jul 15 '25 16:07 notspammy11

I'm the OP of this thread. It is possible — it's just not well documented.

  1. Exit Claude Code.

  2. In the terminal, run:

    claude config add ignorePatterns "MacTests/"
    
  3. 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

houmie avatar Jul 15 '25 16:07 houmie

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?

lukasbloom avatar Jul 15 '25 16:07 lukasbloom

That's correct.

houmie avatar Jul 15 '25 16:07 houmie

Exactly, for me the issue is that I want to include something in CLAUDE that .gitignore excludes for GIT commit.

vukdavid avatar Jul 16 '25 07:07 vukdavid

+1

tfiling avatar Jul 20 '25 09:07 tfiling

+1

mibuhand avatar Jul 24 '25 20:07 mibuhand

+1

dbaranoff avatar Jul 25 '25 16:07 dbaranoff

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.

fredbenenson avatar Aug 02 '25 15:08 fredbenenson

+1

filopedraz avatar Aug 04 '25 17:08 filopedraz

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.

fredbenenson avatar Aug 04 '25 17:08 fredbenenson

I'm the OP of this thread. It is possible — it's just not well documented.

  1. Exit Claude Code.
  2. In the terminal, run:
    claude config add ignorePatterns "MacTests/"
    
  3. 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 avatar Aug 19 '25 18:08 NightMachinery

@NightMachinery how this helps with the problems mentioned above like "want to include something in CLAUDE that .gitignore excludes for GIT commit"?

vukdavid avatar Aug 20 '25 07:08 vukdavid

@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.

NightMachinery avatar Aug 22 '25 01:08 NightMachinery

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.

igorkofman avatar Aug 22 '25 18:08 igorkofman