# How to Create Custom File Type Definitions with Glob Patterns in ripgrep

> Learn to add custom file types to ripgrep using glob patterns. Define them per-invocation with --type-add or persist them in a config file for efficient searching.

- Repository: [Andrew Gallant/ripgrep](https://github.com/BurntSushi/ripgrep)
- Tags: how-to-guide
- Published: 2026-03-05

---

**Use the `--type-add 'NAME:GLOB'` flag to define custom file types dynamically per invocation, or persist them in a ripgrep configuration file for permanent use.**

ripgrep classifies searchable files into *types* (such as `rust`, `python`, or `markdown`) using glob pattern mappings. While the tool ships with extensive built-in definitions in `DEFAULT_TYPES`, you can extend or create entirely new type definitions using custom glob patterns without modifying the source code.

## Understanding ripgrep's File Type System

By default, ripgrep recognizes hundreds of file types defined in the static table `DEFAULT_TYPES` located in [**[`crates/ignore/src/default_types.rs`](https://github.com/BurntSushi/ripgrep/blob/main/crates/ignore/src/default_types.rs)**](https://github.com/BurntSushi/ripgrep/blob/master/crates/ignore/src/default_types.rs#L12-L45). Each entry maps a type name to a list of glob patterns (e.g., `*.rs` for Rust).

When you invoke `rg -trust`, the searcher filters the file traversal to only paths matching the globs associated with that type.

## Using `--type-add` for Custom Definitions

The **`--type-add`** flag allows runtime extension of the type system. The implementation resides in the `TypeAdd` struct within [**[`crates/core/flags/defs.rs`](https://github.com/BurntSushi/ripgrep/blob/main/crates/core/flags/defs.rs)**](https://github.com/BurntSushi/ripgrep/blob/master/crates/core/flags/defs.rs#L36-L91), where the `doc_long` method (lines 57‑80) documents the precise syntax.

### Basic Syntax

The flag accepts a string in the format `'NAME:GLOB'`:

- **`NAME`** — A unique identifier using Unicode letters or digits only.
- **`GLOB`** — Any valid glob pattern accepted by ripgrep, including brace expansion (`*.{js,ts}`) or wildcards (`*.log`).

```bash
rg --type-add 'web:*.{html,css,js}' -tweb "search-term"

```

### Including Existing Types

To compose a new type from existing definitions, use the **`include`** keyword followed by comma-separated type names:

```bash
rg --type-add 'src:include:cpp,py,md' --type-add 'src:*.txt' -tsrc "TODO"

```

This imports all globs belonging to `cpp`, `python`, and `markdown` into the new `src` type, then appends an additional `*.txt` pattern.

### Multiple Pattern Addition

Supply the flag repeatedly to add multiple globs to the same type:

```bash
rg --type-add 'config:*.yaml' --type-add 'config:*.json' --type-add 'config:*.toml' -tconfig "key"

```

## Persisting Custom Types

Definitions added via `--type-add` are **per-invocation only** and stored as `TypeChange::Add { def: String }` entries in `LowArgs.type_changes` during CLI parsing. To make them permanent:

### Shell Aliases

Create an alias that includes your custom definitions:

```bash
alias rg="rg --type-add 'web:*.{html,css,js}'"

```

### Configuration Files

Add the flag to a ripgrep config file (default locations: `~/.ripgreprc` or `$XDG_CONFIG_HOME/ripgrep/config`):

```bash
--type-add=web:*.{html,css,js}

```

After configuration, invoke the type directly:

```bash
rg -tweb "search-term"

```

## Architectural Flow

The custom type resolution process follows three stages as implemented in the source:

1. **CLI Parsing** — The `TypeAdd` flag parser (lines 36‑91 in [`crates/core/flags/defs.rs`](https://github.com/BurntSushi/ripgrep/blob/main/crates/core/flags/defs.rs)) validates input and stores changes in `LowArgs.type_changes`.
2. **Type Resolution** — During `core::flags::parse`, the system merges built-in `DEFAULT_TYPES` with user-supplied additions, expanding `include:` directives by referencing the built-in table.
3. **File Selection** — The `ignore::WalkBuilder` uses the final glob set to filter paths before content scanning occurs.

## Practical Code Examples

Define a composite documentation type that includes Markdown and reStructuredText:

```bash
rg --type-add 'docs:include:md,rst' --type-add 'docs:*.txt' -tdocs "API"

```

Search only log files across a codebase:

```bash
rg --type-add 'logs:*.log' --type-add 'logs:*.log.{1..9}' -tlogs "ERROR"

```

Verify your custom type appears in the type list:

```bash
rg --type-add 'custom:*.xyz' --type-list | grep custom

```

## Summary

- Use **`--type-add 'NAME:GLOB'`** to create temporary custom file types on the command line.
- Use **`include:TYPE1,TYPE2`** to inherit globs from existing built-in definitions.
- Persist custom types using **shell aliases** or a **configuration file** (`~/.ripgreprc`).
- View all available types (including custom additions) with **`rg --type-list`**.
- The underlying implementation resides in [`crates/core/flags/defs.rs`](https://github.com/BurntSushi/ripgrep/blob/main/crates/core/flags/defs.rs) and [`crates/ignore/src/default_types.rs`](https://github.com/BurntSushi/ripgrep/blob/main/crates/ignore/src/default_types.rs).

## Frequently Asked Questions

### Can I use regular expressions instead of glob patterns for custom types?

No, the `--type-add` flag only accepts glob patterns. According to the source code in [`crates/core/flags/defs.rs`](https://github.com/BurntSushi/ripgrep/blob/main/crates/core/flags/defs.rs), the `TypeAdd` parser specifically handles glob syntax including brace expansion and wildcards. For regex-based filtering, use the `-g` or `--glob` flag directly with regex-compatible patterns, though this does not create a reusable type definition.

### Why aren't my custom type definitions saved between commands?

Custom types added via `--type-add` are stored only in the current invocation's `LowArgs.type_changes` vector and are not written to disk. As noted in the flag documentation (lines 57‑80 of [`defs.rs`](https://github.com/BurntSushi/ripgrep/blob/main/defs.rs)), these definitions are ephemeral by design. To persist them, you must add the `--type-add` line to a configuration file or shell alias as described in the persistence section.

### How do I verify that my custom type was registered correctly?

Run `rg --type-list` immediately after your `--type-add` definition. The output includes both built-in types and any custom types defined for that specific invocation. The custom type name will appear alongside its associated glob patterns, confirming successful registration in the type table.

### Can I override built-in type definitions with custom globs?

Yes. When you define a custom type using the same name as a built-in type (e.g., `cpp`), your `--type-add` definition appends globs to that type for the current invocation. However, you cannot remove built-in globs—only supplement them. To effectively "override," create a new type name (e.g., `mycpp`) with your preferred globs and use that type selector instead.