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 (
--includeor-i) - “these patterns allow files” - exclude list (
--excludeor-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, 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 Situations
Section titled “2. Four Situations”Overview of the four situations
Section titled “Overview of the four situations”| Include list | Exclude list | Files kept |
|---|---|---|
| A = ∅ | B = ∅ | Ω |
| A = ∅ | B ≠ ∅ | ¬B |
| A ≠ ∅ | B = ∅ | A |
| A ≠ ∅ | B ≠ ∅ | A \ B |
-
No include list, no exclude list
If no patterns are specified, all files are kept (
Ω). -
Exclude list only
In this case, Code2Prompt acts as a blacklist, removing files that match the excluded patterns (
Ω \ B = ¬B). -
Include list only
If only an include list is specified, Code2Prompt acts as a whitelist, keeping only files that match the included patterns (
A). -
Include and exclude lists
If both lists are specified, Code2Prompt keeps files that match the include patterns, but removes those that match the exclude patterns (
A \ B).
3. More on the overlap
Section titled “3. More on the overlap”With both lists present (A ≠ ∅, B ≠ ∅) you have four logical possibilities
for the overlap C and the rest D.
Want C? | Want D? | Reasonable? |
|---|---|---|
| No | No | Default behaviour (A \ B) |
| Yes | No | Same behavior as case 3 (A) |
| No | Yes | surprising (“discard what I asked for C, keep what I didn’t”) |
| Yes | Yes | Same behavior as case 1 (Ω) |
This is for this reason that the --include-priority option was removed. Because, it would be the same result as if you had only an include list (case 3).
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 |
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 overlap is discarded by default