# How to Configure Graphify's Ignore Patterns with .graphifyignore

> Learn how to configure Graphify's ignore patterns using .graphifyignore. Exclude files from knowledge-graph extraction with gitignore-compatible syntax for efficient filtering.

- Repository: [Safi/graphify](https://github.com/safishamsi/graphify)
- Tags: how-to-guide
- Published: 2026-06-15

---

**Graphify uses a .graphifyignore file compatible with standard gitignore syntax to exclude files and directories from knowledge-graph extraction, automatically falling back to .gitignore rules when present, with all patterns cached at startup for optimal performance.**

Graphify, the open-source knowledge-graph extraction tool from the `safishamsi/graphify` repository, provides granular control over file inclusion through hierarchical ignore patterns. Learning how to configure Graphify's ignore patterns ensures that build artifacts, third-party dependencies, and generated code remain outside your knowledge graph while preserving the source files that matter.

## How Graphify Processes Ignore Patterns

The ignore system is implemented in [`graphify/detect.py`](https://github.com/safishamsi/graphify/blob/main/graphify/detect.py) and follows the gitignore specification with specific optimizations for knowledge-graph extraction.

### Pattern Parsing and Syntax

In [`graphify/detect.py`](https://github.com/safishamsi/graphify/blob/main/graphify/detect.py), the `_parse_gitignore_line` function (lines 698–712) handles the core parsing logic. This function strips comments (lines beginning with `#`), processes escaped hash characters (`\#`), and trims trailing whitespace to ensure accurate pattern matching. The parser supports standard glob patterns, directory-specific wildcards, and negation syntax.

### Hierarchical Loading and Fallback

When scanning a project, Graphify calls `_load_graphifyignore` (lines 735–750 in [`graphify/detect.py`](https://github.com/safishamsi/graphify/blob/main/graphify/detect.py)) to discover rules:

1. Graphify searches for `.graphifyignore` in each directory from the repository root down to the current scan location.
2. If a directory lacks `.graphifyignore`, the system automatically falls back to `.gitignore` (lines 735–662), respecting your existing version control exclusions without requiring duplicate configuration files.
3. Patterns from parent directories are loaded first, with local directory rules evaluated afterward.

### Matching Rules and Precedence

The `_is_ignored` function (lines 773–795 in [`graphify/detect.py`](https://github.com/safishamsi/graphify/blob/main/graphify/detect.py)) implements **last-match-wins** precedence with full support for negation patterns (`!`). This function also enforces the parent-exclusion rule: a negated file cannot be re-included if a parent directory is already ignored, preventing accidental inclusion of deeply nested artifacts.

### Caching for Performance

During watch mode operations, Graphify loads the ignore list exactly once at startup (lines 827–842 in [`graphify/watch.py`](https://github.com/safishamsi/graphify/blob/main/graphify/watch.py)) and caches the compiled patterns for the entire scan session. This design ensures that configuring Graphify's ignore patterns does not introduce performance penalties during live monitoring of large codebases.

## Creating a .graphifyignore File

Create a file named `.graphifyignore` at your repository root to define exclusion rules:

```text

# Exclude generated assets

node_modules/
build/
dist/
*.generated.py

# Keep a specific generated file despite the above pattern

!src/keep_generated.py

```

Comments begin with `#` and are ignored by the parser. Negated patterns using `!` re-include paths that match previous exclusion rules.

### Sub-Directory Configuration

Place additional `.graphifyignore` files in subdirectories to override parent rules:

```text

# Inside frontend/.graphifyignore

/.cache/
!/.cache/keep/

```

Local rules are evaluated after parent rules, allowing subdirectory-specific exceptions without modifying the root configuration.

## Fallback to .gitignore

When a `.graphifyignore` file is absent in a scanned directory, Graphify automatically reads the corresponding `.gitignore` file. This fallback behavior means existing projects do not need new configuration files to benefit from Graphify's extraction:

```text

# Example .gitignore automatically respected by Graphify

*.log
.tmp/
coverage/

```

The fallback mechanism ensures that standard version control exclusions immediately apply to knowledge-graph extraction without manual synchronization.

## Programmatic Pattern Validation

You can verify ignore patterns programmatically using the internal detection API:

```python
from pathlib import Path
from graphify.detect import _load_graphifyignore, _is_ignored

root = Path("/path/to/your/project")

# Load patterns from .graphifyignore or fallback to .gitignore

patterns = _load_graphifyignore(root)

# Test a specific file path

test_path = root / "node_modules" / "lib.js"
result = _is_ignored(test_path, root, patterns)

print(f"Is ignored: {result}")  # → True

```

This approach is useful for debugging complex negation patterns or verifying that your configuration correctly excludes intended paths before running a full extraction.

## Watch Mode Integration

When using the Graphify CLI in watch mode, the ignore configuration loads once at initialization:

```bash
graphify watch .

```

The watcher monitors the filesystem while respecting the cached ignore patterns, ensuring that changes to `node_modules/`, build directories, or other excluded paths do not trigger unnecessary re-processing.

## Summary

- **Graphify uses standard gitignore syntax** via `.graphifyignore` files, parsed by `_parse_gitignore_line` in [`graphify/detect.py`](https://github.com/safishamsi/graphify/blob/main/graphify/detect.py).
- **Automatic fallback** to `.gitignore` occurs when `.graphifyignore` is absent, leveraging existing project configurations.
- **Hierarchical rules** apply last-match-wins precedence with support for negation (`!`) and parent-directory exclusion logic handled by `_is_ignored`.
- **Performance optimization** ensures patterns are loaded and cached once at startup during watch mode (lines 827–842 in [`graphify/watch.py`](https://github.com/safishamsi/graphify/blob/main/graphify/watch.py)).
- **Subdirectory overrides** allow localized exceptions without modifying root configuration files.

## Frequently Asked Questions

### What is the difference between .graphifyignore and .gitignore?

Graphify prioritizes `.graphifyignore` when present but automatically falls back to `.gitignore` if the former is missing. This allows knowledge-graph-specific exclusions (such as generated documentation) that differ from version control rules, while ensuring existing `.gitignore` configurations work immediately without duplication.

### How do negation patterns work in Graphify?

Negation patterns using the `!` prefix re-include files or directories that were excluded by previous patterns. According to the implementation in [`graphify/detect.py`](https://github.com/safishamsi/graphify/blob/main/graphify/detect.py), the system applies last-match-wins logic, meaning the final matching pattern determines whether a path is ignored. However, a file cannot be re-included if its parent directory is already excluded.

### Can I use .graphifyignore in subdirectories?

Yes. Graphify searches for `.graphifyignore` in each directory from the repository root down to the scan location. Rules in child directories are evaluated after parent rules, allowing subdirectory-specific configurations to override global exclusions while maintaining inherited patterns from ancestor directories.

### Does configuring ignore patterns affect watch mode performance?

No. Graphify loads and caches all ignore patterns exactly once at the start of a watch operation (as implemented in [`graphify/watch.py`](https://github.com/safishamsi/graphify/blob/main/graphify/watch.py) lines 827–842). This caching ensures that filesystem monitoring remains efficient regardless of the complexity or quantity of ignore rules defined in your `.graphifyignore` files.