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, the special role of --include-priority, 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

  1. No include list, no exclude list

  2. Exclude list only

  3. Include list only

  4. 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-priorityresultset expression
    off (default)keep
    onkeep 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.

Let (A) and (B) overlap. Depending on the priority, the intersection is either included or excluded based on the include_priority parameter. By default, the intersection is excluded (exclusion primes over inclusion).

Visual Representation of Case 4


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:

Terminal window
code2prompt . \
-i "**/*.md,node_modules/**/LICENSE" \
-e "node_modules/**,target/**" \
--include-priority

One line, easy to read, easy to maintain.


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