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

Resolved 💬 32 comments Opened May 25, 2025 by houmie Closed Aug 22, 2025
💡 Likely answer: A maintainer (igorkofman, collaborator) responded on this thread — see the highlighted reply below.

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

View original on GitHub ↗

32 Comments

ZachHandley · 1 year ago

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

lobinator · 1 year ago
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.

b-tops · 1 year ago

+1

danielraffel · 1 year ago

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

dnichols4 · 1 year ago

+1

zhyc9de · 1 year ago

+1

courthead · 1 year ago

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

geraldalewis · 1 year ago

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

vukdavid · 1 year ago

+1

kamellperry · 1 year ago

+1

matousek-martin · 1 year ago

+1

sudarshan227 · 1 year ago

+1

Sanmonsua · 1 year ago

+1

lukasbloom · 1 year ago

+1

smith-ai-1 · 1 year ago

+1

notspammy11 · 1 year ago

+1

houmie · 1 year ago

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/"
``

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

lukasbloom · 1 year ago

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?

houmie · 1 year ago

That's correct.

vukdavid · 1 year ago

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

tfiling · 12 months ago

+1

r-Kai-dev · 11 months ago

+1

dbaranoff · 11 months ago

+1

fredbenenson · 11 months ago

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.

filopedraz · 11 months ago

+1

fredbenenson · 11 months ago

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.

NightMachinery · 11 months ago
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.

vukdavid · 11 months ago

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

NightMachinery · 10 months ago
@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.

igorkofman collaborator · 10 months ago

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.

madeupname · 10 months ago

@igorkofman Except the deny rules are broken:

https://github.com/anthropics/claude-code/issues/4570

I have deny rules in settings.json to prevent reading multiple top level directories and they and their contents show up every time I type @.

{
  "permissions": {
    "additionalDirectories": [
      "swing/strategies"
    ],
    "deny": [
      "Read(news/**)",
      "Read(venv/**)"
    ]
  }
}

news and venv are at the same level as .claude/, and I've tried every variant of the directory specifiers I can think of, including absolute paths, relative, \\ as a separator since I'm on on Windows, etc.. swing/strategies is in .gitignore and neither additionalDirectories nor /add-dir will add it. The whole system is broken and I'm on v1.0.88.

If I've missed a viable workaround in a GitHub comment I'd be grateful to anyone to point this out, but at his point it seems Claude and Anthropic agree this is a critical security bug that remains outstanding.

github-actions[bot] · 10 months 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.