Skip to content

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, and the design choices behind them.


Throughout the explanation we use the usual set notation

SymbolMeaning
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

Include listExclude listFiles kept
A = ∅B = ∅Ω
A = ∅B ≠ ∅¬B
A ≠ ∅B = ∅A
A ≠ ∅B ≠ ∅A \ B
  1. No include list, no exclude list

    If no patterns are specified, all files are kept (Ω).

  2. Exclude list only

    In this case, Code2Prompt acts as a blacklist, removing files that match the excluded patterns ( Ω \ B = ¬B).

  3. Include list only

    If only an include list is specified, Code2Prompt acts as a whitelist, keeping only files that match the included patterns (A).

  4. 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).


With both lists present (A ≠ ∅, B ≠ ∅) you have four logical possibilities for the overlap C and the rest D.

Want C?Want D?Reasonable?
NoNoDefault behaviour (A \ B)
YesNoSame behavior as case 3 (A)
NoYessurprising (“discard what I asked for C, keep what I didn’t”)
YesYesSame 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).

Want to keep…Use
everythingno -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