llmignore 0.1.0
Parse and match .llmignore files — the .gitignore for AI. Supports .cursorignore, .aiignore, .aiexclude, .claudeignore, .codeiumignore, .geminiignore, .aiderignore, .clineignore, .rooignore, .augmentignore, .copilotignore, .repomixignore.
Requires Python: >=3.8
Keywords: ai, ai-coding, aiderignore, aiexclude, aiignore, augmentignore, claudeignore, clineignore, codeiumignore, context-window, copilotignore, cursorignore, geminiignore, gitignore, llm, llmignore, repomixignore, rooignore, security

# llmignore

Parse and match `.llmignore` files — the `.gitignore` for AI.

Prevent AI coding tools from ingesting secrets, credentials, large binaries, and sensitive data into LLM context windows. Works with all 13 known AI ignore formats.

**Spec:** [rival.tips/llmignore](https://rival.tips/llmignore)

## Installation

```bash
pip install llmignore
```

## Usage

### Parse and match

```python
from llmignore import parse, match

content = """
# Secrets
.env
.env.*
**/*.pem
**/*.key

# Large binaries
**/*.wasm
**/node_modules/**

# But keep the example env
!.env.example
"""

patterns = parse(content)

match(patterns, ".env")              # True  (ignored)
match(patterns, ".env.local")        # True  (ignored)
match(patterns, ".env.example")      # False (negation re-includes it)
match(patterns, "certs/server.pem")  # True  (ignored)
match(patterns, "src/index.ts")      # False (not matched)
```

### Debug which patterns match

```python
from llmignore import parse, match_all

patterns = parse(open(".llmignore").read())
matching = match_all(patterns, "secrets/api-key.pem")

for p in matching:
    prefix = "!" if p.is_negation else " "
    print(f"  line {p.line_number}: {prefix}{p.pattern}")
```

### Read from file

```python
from pathlib import Path
from llmignore import parse, match

llmignore_path = Path(".llmignore")
if llmignore_path.exists():
    patterns = parse(llmignore_path.read_text())
    # Use patterns to filter files...
```

### Explore supported formats

```python
from llmignore import FORMATS

for fmt in FORMATS:
    negation = "yes" if fmt.supports_negation else "no"
    official = "official" if fmt.official else "community"
    print(f"  {fmt.filename:<20} {fmt.tool:<16} negation={negation}  ({official})")
```

## Supported Formats

| File | Tool | Official | Negation | Cascading |
|------|------|----------|----------|-----------|
| `.llmignore` | Universal | Yes | Yes | Yes |
| `.cursorignore` | Cursor | Yes | Yes | No |
| `.aiignore` | JetBrains | Yes | Yes | No |
| `.aiexclude` | Google Gemini | Yes | No | Yes |
| `.claudeignore` | Claude Code | No | Yes | Yes |
| `.codeiumignore` | Windsurf | Yes | Yes | No |
| `.geminiignore` | Gemini CLI | Yes | Yes | No |
| `.aiderignore` | Aider | Yes | Yes | No |
| `.clineignore` | Cline | Yes | Yes | No |
| `.rooignore` | Roo Code | Yes | Yes | No |
| `.augmentignore` | Augment | Yes | Yes | No |
| `.copilotignore` | GitHub Copilot | No | No | No |
| `.repomixignore` | Repomix | Yes | Yes | No |

## Glob Syntax

The syntax is identical to `.gitignore`:

| Pattern | Matches |
|---------|---------|
| `*.log` | Any `.log` file at any depth |
| `**/*.pem` | Any `.pem` file in any subdirectory |
| `**/node_modules/**` | Everything inside any `node_modules` directory |
| `build/` | The `build` directory and all its contents |
| `!important.log` | Re-includes `important.log` even if `*.log` excludes it |
| `src/secrets/**` | Everything inside `src/secrets/` (anchored) |
| `??.txt` | Any two-character `.txt` filename |
| `[abc].txt` | `a.txt`, `b.txt`, or `c.txt` |

## API Reference

### `parse(content: str) -> list[Pattern]`

Parse ignore file content into a list of `Pattern` objects. Handles comments, blank lines, negation, and escaped characters.

### `match(patterns: list[Pattern], path: str) -> bool`

Check whether a path should be ignored. Evaluates patterns in order with last-match-wins semantics. Negation patterns (`!`) re-include previously excluded files.

### `match_all(patterns: list[Pattern], path: str) -> list[Pattern]`

Return all patterns that match a path (both inclusions and negations). Useful for debugging ignore rules.

### `FORMATS: list[Format]`

All 13 known AI ignore file format definitions with metadata about tool support, negation, and cascading behavior.

### `Pattern`

Dataclass with fields: `pattern` (str), `is_negation` (bool), `line_number` (int).

### `Format`

Dataclass with fields: `id`, `filename`, `tool`, `tool_url`, `description`, `official`, `supports_negation`, `supports_cascading`, `docs_url`, `notes`.

## Zero Dependencies

This library uses only the Python standard library. No external packages required.

## Links

- [.llmignore spec](https://rival.tips/llmignore)
- [Template builder](https://rival.tips/llmignore)
- [RIVAL — AI model comparison](https://rival.tips)

## License

MIT