A navigable graph of your codebase for LLMs. Supports Python, JavaScript/TypeScript, Go, Rust, and Java.
Project description
Kontexto
A CLI tool to explore codebases efficiently. Designed for LLMs and coding agents as a smarter alternative to ls, grep, and find.
All output is JSON for easy parsing by LLMs and programmatic consumption.
๐ Supported Languages
| Language | Extensions | Entities Extracted |
|---|---|---|
| Python | .py |
functions, classes, methods |
| JavaScript | .js, .jsx, .mjs |
functions, classes, methods, arrow functions |
| TypeScript | .ts, .tsx |
functions, classes, methods, interfaces, types |
| Go | .go |
functions, methods, structs, interfaces |
| Rust | .rs |
functions, structs, enums, traits, impl blocks, methods |
| Java | .java |
classes, interfaces, enums, methods, constructors |
All parsers use tree-sitter for fast, accurate AST-based parsing.
๐ฆ Installation
pip install kontexto
๐ Quick Start
# 1. Index your project
cd /path/to/your/project
kontexto index
# 2. Explore the codebase
kontexto map # See project structure
kontexto expand src/api # Expand a directory
kontexto search "authentication" # Search for code
kontexto inspect src/api:UserController # Inspect entity details
kontexto hierarchy BaseModel # Find all subclasses
kontexto read src/api/users.py 10 50 # Read specific lines
๐ Commands
kontexto index [path]
Index a project and build the navigation graph. Automatically detects and parses all supported languages.
kontexto index # Index current directory
kontexto index /path/to/project # Index specific project
kontexto index -i # Incremental update (faster)
Creates a .kontexto/index.db database with:
- File and directory structure
- Classes, methods, functions (and language-specific entities)
- Signatures and docstrings
- Call relationships
- Class inheritance (base classes)
- TF-IDF search index
- Language metadata for each entity
kontexto map [path]
Show a compact map of the project structure.
$ kontexto map
{
"command": "map",
"project": "myapp",
"root": "/path/to/myapp",
"stats": {"files": 20, "classes": 8, "functions": 45, "methods": 32},
"children": [
{"id": "src", "stats": {"files": 12, "classes": 8, "functions": 45}},
{"id": "tests", "stats": {"files": 8, "classes": 0, "functions": 24}}
]
}
kontexto expand <path>
Expand a node to see its children.
$ kontexto expand src/api/users.py
{
"command": "expand",
"node": {
"id": "src/api/users.py",
"name": "users.py",
"type": "file",
"line_end": 95
},
"children": [
{
"id": "src/api/users.py:UserController",
"name": "UserController",
"type": "class",
"line_start": 10,
"line_end": 89,
"signature": "class UserController",
"docstring": "Handles user API endpoints",
"base_classes": ["BaseController"]
}
]
}
kontexto inspect <entity>
Show detailed info about an entity: signature, docstring, relationships.
$ kontexto inspect src/api/users.py:UserController.get_user
{
"command": "inspect",
"node": {
"id": "src/api/users.py:UserController.get_user",
"name": "get_user",
"type": "method",
"file_path": "src/api/users.py",
"line_start": 15,
"line_end": 25,
"signature": "def get_user(self, user_id: int) -> User",
"docstring": "Retrieve user by ID from database."
},
"calls": ["find_by_id"],
"called_by": ["src/api/routes.py:user_routes"]
}
kontexto search <query>
Search for entities by keyword (names, docstrings, signatures).
$ kontexto search "authentication"
{
"command": "search",
"query": "authentication",
"count": 3,
"results": [
{
"node": {
"id": "src/api/auth.py:require_auth",
"name": "require_auth",
"type": "function",
"signature": "def require_auth(func: Callable) -> Callable"
},
"score": 0.8521
}
]
}
Options:
--limit, -l: Maximum number of results (default: 10)
kontexto hierarchy <base_class>
Find all classes that inherit from a given base class.
$ kontexto hierarchy BaseModel
{
"command": "hierarchy",
"base_class": "BaseModel",
"count": 5,
"subclasses": [
{
"id": "src/models/user.py:User",
"name": "User",
"type": "class",
"base_classes": ["BaseModel"],
"signature": "class User(BaseModel)"
},
{
"id": "src/models/product.py:Product",
"name": "Product",
"type": "class",
"base_classes": ["BaseModel"],
"signature": "class Product(BaseModel)"
}
]
}
kontexto read <file> [start] [end]
Read source code from a file. Outputs raw code (not JSON).
$ kontexto read src/api/users.py 15 20
def get_user(self, user_id: int) -> User:
"""Retrieve user by ID from database."""
user = self.user_service.find_by_id(user_id)
if not user:
raise NotFoundError(f"User {user_id} not found")
return user
Use line ranges from expand or inspect to read specific functions.
๐ค Use with LLMs
Kontexto is designed for coding agents like Claude Code. Instead of using ls, grep, and find:
# Before: multiple commands, unstructured output
ls -la src/
grep -r "authenticate" src/
cat src/api/auth.py
# After: JSON output, easy to parse
kontexto map
kontexto search "authenticate"
kontexto expand src/api/auth.py
โจ Benefits for LLMs
| Tool | Output | Structure | Relationships |
|---|---|---|---|
ls |
File names only | None | None |
grep |
Matching lines | None | None |
find |
File paths | None | None |
| kontexto | Structured JSON | Classes, functions, methods | Calls, called-by, inheritance |
Features
- JSON output - All commands return structured JSON for easy parsing
- Class hierarchy - Track inheritance with
base_classesfield andhierarchycommand - Search caching - Repeated searches are cached for faster response
- Incremental indexing - Only changed files are re-indexed, with incremental search index updates
โ๏ธ How It Works
Kontexto uses tree-sitter to parse source files and builds a navigable graph:
Project Root
โโโ Directories
โ โโโ Files (.py, .js, .ts, .go, .rs, .java)
โ โโโ Classes/Structs/Traits (with base_classes)
โ โ โโโ Methods
โ โโโ Functions
โ โโโ Interfaces
โ โโโ Enums
The graph is stored in SQLite with:
- TF-IDF search index for keyword search
- Call relationships tracking who calls what
- Class inheritance tracking base classes
- Language metadata for each entity
- Incremental updates for large codebases (both graph and search index)
Architecture
โโโโโโโโโโโโโโโโโโโ
โ CLI Commands โ
โโโโโโโโโโฌโโโโโโโโโ
โ
โโโโโโโโโโผโโโโโโโโโ
โ CodeGraph โ
โโโโโโโโโโฌโโโโโโโโโ
โ
โโโโโโโโโโผโโโโโโโโโ
โ ParserRegistry โ
โโโโโโโโโโฌโโโโโโโโโ
โ
โโโโโโดโโโโโฌโโโโโโโโโฌโโโโโโโโโฌโโโโโโโโโ
โผ โผ โผ โผ โผ
โโโโโโโโโ โโโโโโโโ โโโโโโโโ โโโโโโโโ โโโโโโโโ
โPython โ โ JS โ โ Go โ โ Rust โ โ Java โ
โParser โ โParserโ โParserโ โParserโ โParserโ
โโโโโฌโโโโ โโโโฌโโโโ โโโโฌโโโโ โโโโฌโโโโ โโโโฌโโโโ
โ โ โ โ โ
โโโโโโโโโโดโโโโโโโโโดโโโโโโโโโดโโโโโโโโโ
โ
โโโโโโโโโผโโโโโโโโ
โ tree-sitter โ
โโโโโโโโโโโโโโโโโ
๐ ๏ธ Development
# Install dev dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Run linter
ruff check src/ tests/
๐ License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kontexto-0.1.0.tar.gz.
File metadata
- Download URL: kontexto-0.1.0.tar.gz
- Upload date:
- Size: 53.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d1dd9bf22df22e007bb05a12c6a67d2fbbf7927112e788a6eb0786835e0db8e5
|
|
| MD5 |
be5f289826a478a2ffc165ed8dc294b9
|
|
| BLAKE2b-256 |
f4f1cd1ccc82beab4900a522b96c4b825517c89cb8630e3c80d9caa4c7de4f4e
|
File details
Details for the file kontexto-0.1.0-py3-none-any.whl.
File metadata
- Download URL: kontexto-0.1.0-py3-none-any.whl
- Upload date:
- Size: 43.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dfb19a1e430c7f2ad4ac73f44e858ab6708af910761ae63776dc270851673614
|
|
| MD5 |
d29dd7385747e9c09037e1255f65cf02
|
|
| BLAKE2b-256 |
6410b2c2619615f63fbc69b26ee2bfe11296de9798f05a450fe71ff9e3374f87
|