| Crates.io | agentlens |
| lib.rs | agentlens |
| version | 0.7.0 |
| created_at | 2026-01-07 05:02:30.765282+00 |
| updated_at | 2026-01-22 08:44:20.5547+00 |
| description | CLI tool to prepare codebases for AI agents by generating outlines, memory files, and reading rules |
| homepage | |
| repository | https://github.com/nguyenphutrong/agentlens |
| max_upload_size | |
| id | 2027550 |
| size | 581,476 |
Give your AI assistant X-ray vision into your codebase
AI coding assistants are blind in large codebases. They can't see:
agentlens generates a structured documentation layer that gives AI assistants a map of your codebase:
.agentlens/
βββ INDEX.md # πΊοΈ Global routing table
βββ modules/
β βββ {module}/
β βββ MODULE.md # π¦ Module overview
β βββ outline.md # π Symbol maps
β βββ memory.md # β οΈ Warnings & TODOs
β βββ imports.md # π Dependencies
βββ files/
βββ {file}.md # π Deep docs (complex files only)
Result: AI loads only what it needs. No more context overflow. No more hallucinations about code structure.
Real-world benchmark on a 362K lines PHP/Laravel codebase:
| Scenario | Tokens | Cost (GPT-5.1-codex-mini) |
|---|---|---|
| Read entire source code | ~3,627,260 | $0.91 |
| Read all AgentLens docs | 129,850 | $0.032 |
| Hierarchical (INDEX + 1 module) | ~25,580 | $0.006 |
Token Reduction:
# Analyze your own codebase
agentlens telemetry summary
# npm/pnpm/yarn/bun - Recommended
npx @agentlens/cli # Run without install
npm install -g @agentlens/cli
pnpm add -g @agentlens/cli
yarn global add @agentlens/cli
bun add -g @agentlens/cli
# Homebrew (macOS)
brew install nguyenphutrong/tap/agentlens
# Cargo
cargo install agentlens
# Quick install script
curl -fsSL https://raw.githubusercontent.com/nguyenphutrong/agentlens/main/scripts/install.sh | sh
Alternative: Copy this prompt to your AI coding assistant:
Install and configure agentlens by following the instructions at:
https://github.com/nguyenphutrong/agentlens/blob/main/docs/ai-agent-setup.md
# Generate docs for current directory
agentlens
# That's it. Check .agentlens/INDEX.md
Add to your AI's instructions (.cursorrules, CLAUDE.md, etc.):
Before working on this codebase, read .agentlens/INDEX.md for navigation.
| Feature | What it does |
|---|---|
| π§ Hierarchical Docs | AI loads module-by-module, not entire codebase |
| π Token Telemetry | Measure and verify token savings |
| π¦ Auto Module Detection | Finds mod.rs, __init__.py, index.ts automatically |
| π Symbol Maps | Know what's in 1000-line files without reading them |
| β οΈ Memory Markers | Surfaces TODO, FIXME, WARNING comments |
| π Import Graphs | Shows how modules depend on each other |
| β‘ Incremental Updates | Only regenerates changed modules |
| π Watch Mode | Auto-regenerate on file save |
| πͺ Git Hooks | Keep docs synced across branches |
| π Remote Repos | Analyze GitHub repos directly |
| π MCP Server | Native integration with Claude Desktop & Cursor |
| π Semantic Search | Find code using natural language queries |
agentlens # Generate docs (hierarchical mode)
agentlens -o docs/ai # Custom output directory
agentlens --dry-run # Preview without writing
agentlens -v # Verbose output
agentlens github.com/vercel/next.js
agentlens --depth 3 github.com/facebook/react
agentlens --diff main # Only changed files since main
agentlens --diff HEAD~5 # Compare against specific commit
agentlens --json > analysis.json
agentlens --json | jq '.modules[] | {slug, file_count}'
agentlens watch # Auto-regenerate on file changes
agentlens watch --debounce 500
agentlens hooks install # Auto-detects Husky/Lefthook/native
agentlens hooks remove # Remove hooks
AGENTLENS_SKIP=1 git commit # Skip temporarily
Supported: Husky, Lefthook, pre-commit, native git hooks
agentlens --check # Exit 1 if docs are stale
# .github/workflows/docs.yml
- name: Check docs freshness
run: agentlens --check
npx @agentlens/cli serve --mcp
{
"mcpServers": {
"agentlens": {
"command": "npx",
"args": ["@agentlens/cli", "serve", "--mcp"]
}
}
}
Tools: regenerate, get_module, check_stale, get_outline, semantic_search
Search your codebase using natural language queries. Requires Ollama with nomic-embed-text model.
# First, create the search index
agentlens index
# Search with natural language
agentlens search "authentication flow"
agentlens search "error handling" --limit 20
agentlens search "database queries" --hybrid # combines vector + text search
# Manage the index
agentlens index status # Show index statistics
agentlens index clear # Remove the index
Setup Ollama:
# Install Ollama (macOS)
brew install ollama
# Pull the embedding model
ollama pull nomic-embed-text
# Start Ollama server
ollama serve
Install agentlens skill for AI coding tools (Claude Code, OpenCode, Codex CLI):
agentlens skills install # Auto-detect and install
agentlens skills install --claude # Claude Code only
agentlens skills install --opencode # OpenCode only
agentlens skills install --codex # Codex CLI only
agentlens skills install --all # All supported tools
agentlens skills list # Show installed skills
agentlens skills remove # Remove skills
The skill teaches AI agents how to navigate codebases using agentlens documentation.
| Level | File | Purpose | Size |
|---|---|---|---|
| L0 | INDEX.md |
Global routing table | O(modules) |
| L1 | MODULE.md |
Module summary & file list | O(files) |
| L1 | outline.md |
Symbol maps for large files | O(symbols) |
| L1 | memory.md |
Warnings & TODOs | O(markers) |
| L1 | imports.md |
Dependencies | O(imports) |
| L2 | files/*.md |
Deep docs for complex files | O(symbols) |
| Language | Symbols | Imports | Memory | Modules |
|---|---|---|---|---|
| Rust | β fn, struct, enum, trait, impl | β | β | mod.rs |
| Python | β def, class | β | β | __init__.py |
| TypeScript/JS | β function, class, arrow | β | β | index.{ts,js} |
| PHP | β function, class, method | β | β | implicit |
| Go | β func, struct, interface | β | β | implicit |
| Swift | β func, class, struct, enum, protocol | β | β | implicit |
| Dart | β function, class, mixin | β | β | implicit |
| Ruby | β def, class, module | β | β | implicit |
| C | β function, struct | β | β | implicit |
| C++ | β function, class, struct | β | β | implicit |
| C# | β method, class, struct, interface | β | β | implicit |
| Java | β method, class, interface, enum | β | β | implicit |
agentlens extracts these comment patterns:
| Pattern | Category | Priority |
|---|---|---|
TODO, FIXME, XXX, BUG, HACK |
Technical Debt | Medium |
WARNING, WARN |
Warnings | High |
SAFETY, INVARIANT |
Safety | High |
RULE, POLICY |
Business Rules | High |
DEPRECATED |
Technical Debt | High |
NOTE |
Notes | Low |
agentlens init --config # Generate agentlens.toml
output = ".agentlens"
threshold = 500 # Lines for "large" file
complex_threshold = 1000 # Symbols for L2 docs
ignore = ["*.test.ts", "fixtures/", "__mocks__/"]
[watch]
debounce_ms = 300
[search]
[search.embedder]
provider = "ollama"
model = "nomic-embed-text"
dimensions = 768
# endpoint = "http://localhost:11434" # Custom Ollama endpoint
[search.chunking]
max_tokens = 512
overlap_tokens = 50
strategy = "symbol" # "symbol" or "window"
[search.search]
hybrid_enabled = true # Combine vector + text search
hybrid_k = 60.0 # RRF fusion parameter
default_limit = 10
agentlens init --templates # All templates
agentlens init --templates=cursor # .cursorrules only
agentlens init --templates=claude # CLAUDE.md only
.agentlens/?| Team Size | Recommendation |
|---|---|
| Solo / Small (1-5) | β Commit β docs available on clone |
| Medium (5-15) | β Ignore β avoid merge conflicts |
| Large (15+) | β Ignore β use CI to validate |
| Open Source | β Commit β showcase for contributors |
If ignoring, add .agentlens/ to .gitignore and run agentlens hooks install.
Usage: agentlens [OPTIONS] [PATH]
Arguments:
[PATH] Target directory or GitHub URL [default: .]
Options:
-o, --output <DIR> Output directory [default: .agentlens]
-t, --threshold <N> Large file threshold [default: 500]
-c, --complex-threshold L2 docs threshold [default: 30]
-d, --depth <N> Max directory depth (0 = unlimited)
--diff <REF> Compare against git ref
--json Output JSON to stdout
--check Check if docs are stale
--force Force regenerate all modules
-i, --ignore <PATTERN> Additional ignore patterns
-l, --lang <LANG> Filter by language
--no-gitignore Don't respect .gitignore
--dry-run Preview without writing
-v, --verbose Increase verbosity (-v, -vv, -vvv)
-q, --quiet Suppress output
-h, --help Print help
-V, --version Print version
Commands:
watch Watch for changes and regenerate
hooks Manage git hooks
init Initialize configuration
serve Start MCP server
skills Manage agent skills for AI tools
telemetry Analyze token usage and efficiency
index Build semantic search index
search Search codebase with natural language
update Update to latest version
agentlens telemetry summary # Token analysis for all modules
agentlens telemetry module <SLUG> # Analyze specific module
Example output:
π Token Analysis: All Modules
βββββββββββββββββββββββββββββββββββββββββββββββββββ
| Module | Tokens | Bytes |
|--------|--------|-------|
| app-Models | 23806 | 76021 |
| database-migrations | 15858 | 51106 |
| ... | ... | ... |
|--------|--------|-------|
| **TOTAL (64 modules)** | **128076** | **411225** |
π Estimated Cost (GPT-5.1-codex-mini @ $0.25/1M tokens):
Full codebase read: $0.032
Hierarchical (INDEX + 1 module): $0.006
Savings: 80.3%
MIT License β see LICENSE