Feature Request: Support `.ignore` files to override `.gitignore` exclusions
Problem
CodeGraph uses git ls-files under the hood to discover source files, which means it inherently respects .gitignore. Any directory or file matched by .gitignore is invisible to CodeGraph and cannot be indexed.
In many real-world projects, entire directories are gitignored even though they contain valuable source code that an AI agent needs to understand. Common examples:
- A top-level
customer/directory that contains per-customer customization code Pods/in iOS projects (tracked locally but gitignored)vendor/in Go projects- Embedded independent git repos inside a monorepo
Currently, the only workaround is to remove entries from .gitignore (which changes repo semantics) or to initialize a separate CodeGraph instance inside the ignored directory (which creates a fragmented index and requires passing --projectPath everywhere).
Proposed Solution
Support .ignore files (using the same pattern syntax as .gitignore) that act as a local override layer on top of .gitignore. This is a well-established pattern used by tools like ripgrep, fd, ag, and rg:
.gitignore— patterns to ignore (unchanged, respected by CodeGraph as today).ignore— patterns to override.gitignorewith negation patterns (!prefix)
For example, if .gitignore contains:
customer/
And the user creates .ignore with:
!customer/
Then CodeGraph would include the customer/ directory in its index even though it's gitignored.
How it works (proposed)
- CodeGraph reads
.gitignoreas today to get the base exclusion set. - CodeGraph then reads
.ignorefiles (if present) from the same locations where.gitignoreis checked. .ignorepatterns are applied after.gitignorepatterns, so negation patterns (!xxx/) in.ignorecan re-include files/directories that.gitignoreexcluded..ignoreis gitignored by default (added to tooling's own ignore list) so it doesn't affect repository semantics.
Why this is better than alternatives
| Approach | Downsides |
|---|---|
Remove entries from .gitignore |
Changes repo behavior for all git commands; commits required |
git add -f |
Modifies the repo permanently; pollutes git tracking |
| Separate CodeGraph instances | Fragmented index; --projectPath needed everywhere; no cross-repo queries |
.ignore file |
Zero impact on git; local to each developer; well-known pattern from other tools |
Prior art
ripgrep(rg): reads.ignorefiles as a gitignore-aware ignore layerfd: reads.ignorefiles with the same semanticsag(the silver searcher): supports.ignorefiles- Node.js's
globmodule: respects.gitignore+.ignore - Git itself: supports
.gitignore+.git/info/exclude+core.excludesFile(though.ignoreis not native to git)
Use case from the reporter
We have a large networking switch firmware project organized as:
root/ (main git repo, customer/ is in .gitignore)
customer/
cus_dlinkg2/ (1075 C source files, independent git repo)
With .ignore support, users could add !customer/ to .ignore at the project root and CodeGraph would index the customer code as part of the main project — no separate init needed, no --projectPath required.
Additional notes
- The
.ignorefile should be checked at the project root level (same directory as.gitignore). - Ensure
.ignoreis added to CodeGraph's own built-in exclusion list so it is never indexed itself. - The parse order should be:
.gitignore→.ignore(applied as overlay).
Fix
I’d like to take a look at this. I’ll start by checking how buildDefaultIgnore() and git-based file discovery interact, then propose a small change with regression tests for .ignore overriding .gitignore without changing existing default excludes.
Using this as the canonical issue for overriding .gitignore to index intentionally-ignored source (e.g. via a .codegraphignore / .ignore with ! negation). Folding in duplicate #511. 👍 here to signal demand. (Note: #622 is a related but distinct bug about embedded git repos excluded by a super-repo's .gitignore — keeping that one open separately.)