🇨🇳 简体中文 | English
For AI Agents (Claude Code, Cursor, Windsurf, etc.)
npx skills add mars167/git-ai-cli/skills/git-ai-code-searchFor CLI Usage
npm install -g @mars167/git-aiAdding a Semantic Layer to Your Codebase, Enabling AI to Evolve from "Reading Code" to "Understanding Code"
Code semantics should be versioned and traceable, just like code itself
git-ai is a local code understanding tool that builds a semantic layer for your codebase using advanced RAG techniques, enabling AI Agents and developers to deeply understand code structure and relationships.
- 🔗 Advanced RAG: Combines vector retrieval + graph retrieval for multi-dimensional semantic understanding
- 📊 Fast & Accurate: Optimized repo-map with PageRank-based importance scoring
- 🔄 Always Available: Indices travel with code, available immediately after checkout, no rebuild needed
- 🤖 AI-Native: MCP Server enables Claude, Trae and other Agents to deeply understand your codebase
- 🔒 Fully Local: Code never leaves your machine, secure and private
- ⚡ Full Lifecycle Support: From development to Review to refactoring, indices span the entire lifecycle
- 📊 Blazing Fast: 10k files indexed in < 30s, search response < 100ms
Find code using natural language, no need to remember file names or function names:
git-ai ai semantic "user authentication logic"
git-ai ai semantic "database connection pool configuration"
git-ai ai semantic "error handling middleware"Understand relationships between code:
# Find function callers
git-ai ai graph callers authenticateUser
# Find functions called by this function
git-ai ai graph callees authenticateUser
# Trace complete call chain
git-ai ai graph chain authenticateUser --max-depth 3Supports multiple mainstream programming languages:
| Language | File Extensions |
|---|---|
| JavaScript | .js, .jsx |
| TypeScript | .ts, .tsx |
| Java | .java |
| Python | .py |
| Go | .go |
| Rust | .rs |
| C | .c, .h |
| Markdown | .md, .mdx |
| YAML | .yml, .yaml |
git-ai is built for deep code understanding through multiple retrieval strategies:
Combines multiple retrieval methods for deeper understanding:
- Vector Retrieval: Semantic similarity matching using SQ8 quantized embeddings
- Graph Retrieval: Call relationship and dependency analysis via AST graphs
- Intelligent Fusion: Weighted combination of retrieval strategies for optimal results
Indices travel with code, no central server required. checkout, branch, tag—all can use consistent semantic indices immediately.
MCP Server enables any AI Agent to invoke indices, achieving true AI-assisted development.
"Just joined the team, facing 100k lines of code, where do I start?"
# 1. Get project global view
git-ai ai repo-map --max-files 20
# 2. Search core business logic
git-ai ai semantic "order processing flow"
# 3. Trace key function call chains
git-ai ai graph chain processOrder --max-depth 5From design to development, semantic indices remain consistent
"About to refactor this function, what will it affect?"
# Find all callers
git-ai ai graph callers deprecatedFunction
# Analyze complete call chain
git-ai ai graph chain deprecatedFunction --direction upstreamGraph analysis reveals complete impact scope
"User reported an error, but don't know where the problem is"
# Search related error handling code
git-ai ai semantic "user login failure handling"
# View error propagation path
git-ai ai graph chain handleLoginError --direction upstreamFull lifecycle indices, quickly locate problem roots
"Let Claude Desktop help me understand this project"
After configuring git-ai MCP Server in Claude Desktop, you can converse directly:
"Help me analyze this project's architecture, find all payment-related code, and explain their relationships"
Claude will automatically invoke git-ai tools to provide deep analysis. Enabling AI to evolve from "reading code" to "understanding code"
graph TB
A[Git Repository] -->|Index| B[Code Parser\nMulti-Language AST]
B --> C[LanceDB\nVector Database]
B --> D[CozoDB\nGraph Database]
C --> E[MCP Server]
D --> E
E -->|Tool Call| F[AI Agent\nClaude Desktop / Cursor]
E -->|CLI| G[Developer]
B -->|Repo Map| H[PageRank Analysis\nImportance Scoring]
H --> E
style B fill:#e1f5ff,stroke:#333
style C fill:#fff4e1,stroke:#333
style D fill:#fff4e1,stroke:#333
style E fill:#e8f5e9,stroke:#333
style F fill:#f3e5f5,stroke:#333
style H fill:#fce4ec,stroke:#333
Core Components:
- Code Parser: Multi-language AST extraction (TypeScript, Java, Python, Go, Rust, C, Markdown, YAML)
- LanceDB + SQ8: High-performance vector database with quantized embeddings for semantic search
- CozoDB: Graph database for AST-level relationship queries (callers, callees, chains)
- Repo Map: PageRank-based code importance analysis for project overview
- MCP Server: Standard protocol interface for AI Agent invocation
| Feature | git-ai | GitHub Code Search | Sourcegraph |
|---|---|---|---|
| Local Execution | ✅ | ❌ | ❌ |
| AST-Level Analysis | ✅ | ❌ | ✅ |
| AI Agent Integration | ✅ | ❌ | ❌ |
| Free & Open Source | ✅ | ❌ | ❌ |
| Semantic Search | ✅ | ✅ | ✅ |
| Call Chain Analysis | ✅ | ❌ | ✅ |
| Multi-Language Support | ✅ | ✅ | ✅ |
| Repo Map with PageRank | ✅ | ❌ | ❌ |
npm install -g @mars167/git-aicd your-project
git-ai ai index --overwrite# Search code using natural language
git-ai ai semantic "user authentication logic"
# View function call relationships
git-ai ai graph callers authenticateUserActual Output Example:
[
{
"file": "src/auth/service.ts",
"line": 45,
"symbol": "authenticateUser",
"context": "async function authenticateUser(email: string, password: string)"
},
{
"file": "src/controllers/auth.ts",
"line": 23,
"symbol": "loginHandler",
"context": "const user = await authenticateUser(req.body.email, req.body.password)"
}
]That's it! 3 steps to get started, immediately begin deep understanding of your codebase.
From now on, indices are not "one-time artifacts" but "semantic assets" that evolve with your code.
git-ai respects your project's ignore files to control which files are indexed:
Files matching patterns in .gitignore are excluded from indexing by default.
Create a .aiignore file in your repository root to exclude specific files from indexing that should be ignored by git-ai but not necessarily by Git:
# Example .aiignore
test-fixtures/**
*.generated.ts
docs/api-reference/**Sometimes you need to index generated code or files that are in .gitignore but important for code understanding. Create .git-ai/include.txt to force-index specific patterns:
# Example .git-ai/include.txt
# Include generated API clients
generated/api/**
# Include specific build artifacts that contain important types
dist/types/**
# Include code from specific ignored directories
vendor/important-lib/**Priority Order (Highest to Lowest):
.aiignore- Explicit exclusions always win.git-ai/include.txt- Force-include patterns override.gitignore.gitignore- Standard Git ignore patterns
Supported Pattern Syntax:
**- Match any number of directories*- Match any characters within a directorydirectory/- Match entire directory (automatically converts todirectory/**)file.ts- Match specific file- Lines starting with
#are comments
Example Configuration:
# .gitignore
dist/
generated/
*.log
# .git-ai/include.txt
generated/api/**
generated/types/**
# .aiignore (overrides everything)
generated/test-data/**With this configuration:
- ✅
generated/api/client.ts- Indexed (included via include.txt) - ✅
generated/types/models.ts- Indexed (included via include.txt) - ❌
generated/test-data/mock.ts- Not indexed (.aiignore takes priority) - ❌
dist/bundle.js- Not indexed (.gitignore, not in include.txt)
git-ai uses CozoDB for AST graph queries. On Windows, if you encounter installation errors related to cozo-node, try these solutions:
Option 1: Use Gitee Mirror (Recommended for users in China)
npm install -g @mars167/git-ai --cozo_node_prebuilt_binary_host_mirror=https://gitee.com/cozodb/cozo-lib-nodejs/releases/download/Option 2: Configure npm proxy
If you're behind a corporate firewall or proxy:
npm config set proxy http://your-proxy:port
npm config set https-proxy http://your-proxy:port
npm install -g @mars167/git-aiOption 3: Manual binary download
- Download the Windows binary from cozo-lib-nodejs releases
- Look for
6-win32-x64.tar.gz(for 64-bit Windows) - Extract to
node_modules/cozo-node/native/6/
Verify installation:
git-ai ai status --path .If you see graph-related features working, installation was successful.
git-ai also uses these native packages that may require similar troubleshooting:
onnxruntime-node- For semantic embeddingstree-sitter- For code parsing@lancedb/lancedb- For vector database
Most issues are resolved by ensuring a stable network connection or using a mirror.
git-ai provides a standard MCP Server that seamlessly integrates with:
- Claude Desktop: The most popular local AI programming assistant
- Cursor: AI-powered code editor
- Trae: Powerful AI-driven IDE
- Continue.dev: VS Code AI plugin
Add to ~/.claude/claude_desktop_config.json:
{
"mcpServers": {
"git-ai": {
"command": "git-ai",
"args": ["ai", "serve"]
}
}
}When you need multiple AI agents to connect simultaneously (e.g., Claude Code + Cursor):
# Start HTTP server (supports multiple clients)
git-ai ai serve --http --port 3000Then configure each agent to connect to http://localhost:3000/mcp.
HTTP mode features:
- Multiple concurrent sessions
- Health check endpoint:
http://localhost:3000/health - Session management with automatic cleanup
- Session persistence via
mcp-session-idresponse header - Comprehensive error handling with proper HTTP status codes
- Graceful shutdown with SIGTERM/SIGINT signal handlers
- Optional stateless mode for load-balanced setups:
--stateless
Then restart Claude Desktop and start conversing:
"Help me analyze this project's architecture, find all payment-related code"
Claude will automatically invoke git-ai tools to provide deep analysis.
We provide carefully designed Agent templates to help AI use git-ai better:
- Skill Template: Guides Agents on how to use tools
- Rule Template: Constrains Agent behavior
Skills/Rules docs (Markdown/YAML) are indexed as part of semantic search, so agents can retrieve MCP guidance via semantic_search.
One-click install to your project:
git-ai ai agent installAutomatically rebuild indices before commit, verify pack before push:
git-ai ai hooks installpre-commit: Auto incremental index + packpre-push: Verify packpost-checkout: Auto unpack
Recommended for managing index archives:
git lfs track ".git-ai/lancedb.tar.gz"
git-ai ai pack --lfsWelcome contributions, issue reports, and suggestions!
Enabling AI to Evolve from "Reading Code" to "Understanding Code" ⭐ Star us on GitHub!
