llmignore 0.1.0

Parse and match .llmignore files — the .gitignore for AI. Supports all 13 AI ignore formats.
Documentation
  • Coverage
  • 100%
    20 out of 20 items documented5 out of 7 items with examples
  • Size
  • Source code size: 38.26 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.29 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 17s Average build duration of successful builds.
  • all releases: 17s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • llmignore-spec/parser-rust
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • llmignore-spec

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

Installation

Add to your Cargo.toml:

[dependencies]
llmignore = "0.1"

Usage

Parse and match

use llmignore::{parse, matches};

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

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

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

let patterns = parse(content);

assert!(matches(&patterns, ".env"));           // ignored
assert!(matches(&patterns, ".env.local"));     // ignored
assert!(!matches(&patterns, ".env.example"));  // negation re-includes it
assert!(matches(&patterns, "certs/server.pem")); // ignored
assert!(!matches(&patterns, "src/main.rs"));   // not matched

Debug which patterns match

use llmignore::{parse, match_all};

let content = ".env.*\n!.env.example";
let patterns = parse(content);
let matching = match_all(&patterns, ".env.example");

for pat in &matching {
    let prefix = if pat.is_negation { "!" } else { " " };
    println!("  line {}: {}{}", pat.line_number, prefix, pat.pattern);
}
// Output:
//   line 1:  .env.*
//   line 2: !.env.example

Read from file

use llmignore::{parse, matches};
use std::fs;

if let Ok(content) = fs::read_to_string(".llmignore") {
    let patterns = parse(&content);

    if matches(&patterns, "secrets/api-key.pem") {
        println!("This file should be excluded from AI context");
    }
}

Explore supported formats

use llmignore::FORMATS;

for fmt in FORMATS {
    let negation = if fmt.supports_negation { "yes" } else { "no" };
    let official = if fmt.official { "official" } else { "community" };
    println!("  {:<20} {:<16} negation={}  ({})", fmt.filename, fmt.tool, 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) -> Vec<Pattern>

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

matches(patterns: &[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: &[Pattern], path: &str) -> Vec<&Pattern>

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

FORMATS: &[Format]

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

Pattern

pub struct Pattern {
    pub pattern: String,
    pub is_negation: bool,
    pub line_number: usize,
}

Format

pub struct Format {
    pub id: &'static str,
    pub filename: &'static str,
    pub tool: &'static str,
    pub tool_url: &'static str,
    pub description: &'static str,
    pub official: bool,
    pub supports_negation: bool,
    pub supports_cascading: bool,
    pub docs_url: Option<&'static str>,
    pub notes: Option<&'static str>,
}

Zero Dependencies

This crate uses only the Rust standard library. No external crates required.

Links

License

MIT