---
title: How the Glob Pattern Filter Works
description: How Code2Prompt decides which files to keep or discard using include (-i) and exclude (-e) globs.
---

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.

---

## 1. Sets and Symbols

Throughout the explanation we use the usual set notation

| Symbol                            | Meaning                                                  |
| --------------------------------- | -------------------------------------------------------- |
| $A$                               | set of files that match **at least one** include pattern |
| $B$                               | set of files that match **at least one** exclude pattern |
| $\Omega$                          | the whole project tree (the _universe_)                  |
| $C = A \cap B$                    | files that match both lists (the _overlap_)              |
| $D = \Omega \setminus (A \cup B)$ | files that match neither list                            |

---

## 2. Four Situations

### Overview of the four situations

| Include list | Exclude list | Files 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`).

---

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

| 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
