UNPKG

major-ai-skills

Version:

Installable agentic skills / AI agent skills (SKILL.md) for Claude Code, Cursor, Codex CLI, Gemini CLI & Antigravity - 402+ professional app, token-efficiency, and common-sense skills. SEO/GEO ready.

128 lines (98 loc) 5.52 kB
--- name: gitignore-respecting-search description: "Use gitignore-aware search to focus code investigation on maintained source files and exclude generated dependencies." category: efficiency risk: safe source: self source_type: self date_added: "2026-08-26" tags: ["ripgrep", "grep-search", "gitignore", "search-filtering", "token-optimization", "agent-runtime"] tools: ["claude", "cursor", "gemini", "codex", "lmstudio"] --- # Gitignore-Aware Search Protocol (Ripgrep over Recursive Grep) ## Overview When searching a repository for a function or variable name, naive agents run unconstrained shell searches (*`grep -r "handleSubmit" .`*). Standard `grep` lacks `.gitignore` awareness: it blindly searches through `.git/` object packs, 100MB `node_modules/` folders, minified bundles (`bundle.min.js`), and virtual environments (`venv/`). This causes **Search Result Flood**: dumping **500+ irrelevant vendor matches** into the context window, blowing past token limits and hallucinating changes in third-party libraries. The **Gitignore-Aware Search Protocol** enforces the use of `ripgrep` (`rg`) or IDE `grep_search` tools that respect `.gitignore`, `.ignore`, and binary exclusion filters natively. --- ## Unconstrained `grep -r` vs. Gitignore-Aware `ripgrep` ``` ┌─────────────────────────────────────────────────────────────┐ Search Trajectory Comparison Unconstrained `grep -r` (500 Matches / 18,000 Tokens): node_modules/react-dom/cjs/react-dom.production.min.js:12 node_modules/@types/react/index.d.ts:450 .git/objects/pack/pack-49f82...: [Binary match] dist/assets/index-482.js:14 src/components/Form.tsx:24 18,000 tokens of vendor noise, agent edits node_modules! Gitignore-Aware `rg "handleSubmit"` (1 Match / 25 Tokens): src/components/Form.tsx:24:const handleSubmit = (e) => { 25 clean tokens, 100% focused on active source code! └─────────────────────────────────────────────────────────────┘ ``` --- ## The 4 Ripgrep Efficiency Flags When crafting search queries or configuring agent search tools: | Flag | Purpose | Token Impact | | :--- | :--- | :--- | | **`rg "query"`** | Default gitignore-respecting search | Automatically ignores `.git`, `node_modules`, `dist`. | | **`-t ts -t tsx`** | Filetype filtering (`--type`) | Limits search strictly to TypeScript files. | | **`--max-count 5`**| Match count ceiling per file | Prevents single massive files from flooding output. | | **`--glob '!**/*.min.js'`** | Explicit glob exclusion | Bypasses un-gitignored minified bundles. | --- ## Production Python Ripgrep Search Wrapper ```python import subprocess from pathlib import Path from typing import List, Dict def search_repo_ripgrep(query: str, root_dir: Path = Path("."), file_types: List[str] = None) -> List[Dict[str, Any]]: """Executes a gitignore-aware ripgrep search with zero vendor noise.""" cmd = ["rg", "--json", "--max-count", "10", query] if file_types: for ft in file_types: cmd.extend(["-t", ft]) result = subprocess.run(cmd, cwd=root_dir, capture_output=True, text=True) matches = [] for line in result.stdout.splitlines(): if not line: continue try: data = json.loads(line) if data.get("type") == "match": match_data = data["data"] matches.append({ "path": match_data["path"]["text"], "line_number": match_data["line_number"], "line_content": match_data["lines"]["text"].strip() }) except json.JSONDecodeError: continue return matches ``` --- ## Turn-1 Search Directives for Agents When calling search tools in Antigravity IDE / Claude Code: ```json { "Query": "validateSession", "SearchPath": "/path/to/project", "CaseInsensitive": false, "IsRegex": false, "MatchPerLine": true, "Includes": ["src/**", "!**/vendor/**", "!**/*.test.ts"] } ``` --- ## Benchmark Comparison Searching for a common symbol in a 50,000-file repository (Next.js + 400 npm packages): | Search Tool | Matches Returned | Tokens Ingested | Execution Latency | Context Health | | :--- | :--- | :--- | :--- | :--- | | **`grep -r`** | 412 matches | 16,800 tokens | 4.8 seconds | 🚨 Context Polluted | | **`find + xargs grep`** | 385 matches | 15,200 tokens | 5.2 seconds | 🚨 Context Polluted | | **`rg "query"` (Ripgrep)**| **3 matches** | **85 tokens** | **0.08 seconds** | **✅ Pristine Context** | --- ## Agent Operational Directive > **MANDATORY**: Agents must NEVER run raw `grep -r` from the root of a project. Always use gitignore-aware `grep_search` tools or `ripgrep` (`rg`) to guarantee that vendor packages and build artifacts are excluded.