How the Glob Pattern Filter Works
Code2Prompt uses glob patterns to include or exclude files and directories, working similarly to tools like tree or grep. It lets you pass two independent lists of glob patterns:
- include list (
--include
or-i
) - “these patterns allow files” - exclude list (
--exclude
or-e
) - “these patterns disallow files”
Code2prompt must decide, for every file in the project, whether it is kept or discarded. This page explains the rules, the special role of --include-priority
, and the design choices behind them.
1. Sets and symbols
Section titled “1. Sets and symbols”Throughout the explanation we use the usual set notation
Symbol | Meaning |
---|---|
set of files that match at least one include pattern | |
set of files that match at least one exclude pattern | |
the whole project tree (the universe) | |
files that match both lists (the overlap) | |
files that match neither list |
2. Four basic situations
Section titled “2. Four basic situations”-
No include list, no exclude list
-
Exclude list only
-
Include list only
-
Include and exclude lists
Here there is an overlap
that satisfies contradictory rules: “keep” (because it is in ) and “discard” (because it is in ). The flag --include-priority
exists solely to resolve that contradiction:--include-priority
result set expression off (default) keep on keep all of Note that the “rest”
is never included when an include list is present - otherwise the include list would no longer behave as a whitelist.
Visual Representation of Case 4
Section titled “Visual Representation of Case 4”Let (A) and (B) overlap. Depending on the priority, the intersection include_priority
parameter. By default, the intersection is excluded (exclusion primes over inclusion).
3. Why keep --include-priority
?
Section titled “3. Why keep --include-priority?”For trivial directories you can drop --exclude
and obtain the same set of
files. But in real-world projects we frequently need the pattern
- include many files (e.g. “every
*.md
”) - exclude huge sub-trees (e.g.
node_modules/**
,target/**
) - keep just a handful of exceptions inside those excluded trees
(e.g.node_modules/**/LICENSE
,docs/private/keep.md
)
Without --include-priority
you must choose between
- removing the exclusion (pulls thousands of files back), or
- writing a gigantic include list that enumerates every allowed path.
The flag offers an ergonomic shorthand:
code2prompt . \ -i "**/*.md,node_modules/**/LICENSE" \ -e "node_modules/**,target/**" \ --include-priority
One line, easy to read, easy to maintain.
4. Quick reference table
Section titled “4. Quick reference table”Want to keep… | Use |
---|---|
everything | no -i , no -e |
everything except some patterns | -e only |
only what matches the patterns | -i only |
what matches -i , minus what matches -e | -i and -e |
same as above but keep the overlap as well | -i , -e , --include-priority |
This design keeps the mental model simple:
- The include list is a whitelist as soon as it exists.
- The exclude list is a blacklist layered on top.
- The flag
--include-priority
changes the fate of the overlap only, nothing else.