Smart codebase context extraction for LLMs - with optional AI-powered filtering
Project description
Contextuaize
Smart codebase context extraction for LLMs โ Transform your codebase into optimized context for Claude, GPT-4, Gemini, and other large language models.
What's New in v0.2
- ๐ง Smart Mode โ LLM-powered intelligent file filtering
- ๐ฏ Query-Driven Context โ Focus on specific features or tasks
- ๐ Auto-Summarization โ Large files get smart summaries
- ๐ Respects .gitignore โ No more manual exclusion lists
- ๐ณ Tech Stack Detection โ Automatically identifies your stack
Features
| Feature | Basic Mode | Smart Mode (--smart) |
|---|---|---|
| .gitignore support | โ | โ |
| Binary file filtering | โ | โ |
| Directory tree | โ | โ |
| Stack detection | โ | โ |
| Intelligent file selection | โ | โ |
| Query-driven filtering | โ | โ |
| Large file summarization | โ | โ |
Installation
# From GitHub
pip install git+https://github.com/ohharsen/contextuaize.git
# Local development
git clone https://github.com/ohharsen/contextuaize.git
cd contextuaize
pip install -e .
Quick Start
Basic Usage
# Scan current directory
contextuaize
# Scan specific project
contextuaize /path/to/project -o context.txt
# Only Python files
contextuaize --include "*.py"
# Exclude tests
contextuaize --exclude "test*" --exclude "*_test.py"
# Just see the tree structure
contextuaize --tree-only
Smart Mode (LLM-Powered)
Smart mode uses Claude to intelligently select relevant files and summarize large ones.
# Set your API key
export ANTHROPIC_API_KEY="sk-ant-..."
# Let AI decide what's important
contextuaize --smart
# Focus on specific functionality
contextuaize --smart --query "authentication and user sessions"
# Focus on a bug
contextuaize --smart --query "database connection handling"
How It Works
Basic Mode
- Walks the directory tree
- Respects
.gitignorerules automatically - Skips universal noise (node_modules, .git, lockfiles, binaries)
- Concatenates all text files with clear markers
Smart Mode
- Two-pass scanning: First scans structure, then uses LLM to select files
- Relevance scoring: Files ranked as essential โ important โ optional โ skip
- Query-driven: When you specify
--query, only files relevant to that task are included - Smart summarization: Files over 100KB get intelligent summaries instead of full content
CLI Reference
contextuaize [directory] [options]
Arguments:
directory Directory to scan (default: current directory)
Options:
-o, --output FILE Output file path (default: codebase_context.txt)
Filtering:
--include PATTERN Include only matching files (can repeat)
--exclude PATTERN Exclude matching files (can repeat)
--no-gitignore Ignore .gitignore rules
Smart Mode:
--smart Enable LLM-powered intelligent filtering
--query, -q TEXT Focus on specific task/feature (enables --smart)
--api-key KEY Anthropic API key (or use ANTHROPIC_API_KEY env)
--model MODEL Model to use (default: claude-sonnet-4-20250514)
Output Destination (mutually exclusive):
-o, --output FILE Write to file (default)
-c, --clipboard Copy to system clipboard
--stdout Print to stdout (for piping)
Output Control:
--quiet Suppress progress output
--tree-only Only show project tree, no file contents
Output Modes
File (default)
contextuaize # โ codebase_context.txt
contextuaize -o context.txt # โ context.txt
Clipboard
contextuaize -c # Copy directly to clipboard
contextuaize --clipboard # Same thing
Works on macOS (pbcopy), Windows (clip), and Linux (xclip/xsel/wl-copy).
Stdout
contextuaize --stdout # Print to stdout
contextuaize --stdout | head # Pipe to other commands
contextuaize --stdout | pbcopy # Manual clipboard on macOS
Progress messages go to stderr, so piping works cleanly.
Examples
Understanding a New Codebase
contextuaize --smart --query "explain the overall architecture"
Preparing to Add a Feature
contextuaize --smart --query "payment processing and Stripe integration"
Debugging an Issue
contextuaize --smart --query "WebSocket connection handling and reconnection logic"
Code Review Context
contextuaize --smart --query "user authentication flow"
Just the Backend
contextuaize --include "*.py" --exclude "test*" --exclude "migrations/*"
Output Format
The generated context file includes:
================================================================================
PROJECT CONTEXT SNAPSHOT
================================================================================
Detected Stack: Python, React, Docker
Context Focus: authentication flow
Total Files: 15
PROJECT STRUCTURE
----------------------------------------
my-project/
โโโ src/
โ โโโ auth/
โ โ โโโ login.py
โ โ โโโ session.py
โ โโโ api/
โ โโโ routes.py
โโโ tests/
================================================================================
FILE CONTENTS
================================================================================
--- START FILE: src/auth/login.py ---
[file content or summary]
--- END FILE: src/auth/login.py ---
...
Configuration
Environment Variables
| Variable | Description |
|---|---|
ANTHROPIC_API_KEY |
API key for smart mode |
Patterns
Both --include and --exclude support glob patterns:
*.pyโ All Python filestest*โ Files/dirs starting with "test"src/**/*.tsโ TypeScript files in src/!important.pyโ Negation (in .gitignore)
Using with LLMs
After generating context, upload to your LLM with a prompt like:
"I've attached my project context. Please analyze the architecture and wait for my questions."
Or for focused tasks:
"Here's context focused on authentication. Help me add OAuth2 support."
License
MIT License โ see LICENSE for details.
Author: Arsen Ohanyan โข GitHub
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 contextuaize-0.2.0.tar.gz.
File metadata
- Download URL: contextuaize-0.2.0.tar.gz
- Upload date:
- Size: 13.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f1bdd69a192ce2911be3ffdba3b37fec2fda8f92d9a227556c03a193210b50cf
|
|
| MD5 |
cec4aab03b530a251e65725d13950fd4
|
|
| BLAKE2b-256 |
b1e1a84f59f46700aff1fb731f1de865d80cb780d5529a3f707f94c1fcee90d3
|
File details
Details for the file contextuaize-0.2.0-py3-none-any.whl.
File metadata
- Download URL: contextuaize-0.2.0-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aaa3381c0dd1e5b9c0723f1c435bae61d8e2d28b540b814c0ec9742c07380105
|
|
| MD5 |
924c61d1f14fe0dac6d18aa926f7d92e
|
|
| BLAKE2b-256 |
a00da3122be440c666780f6d69eed69a2ffa611c19a4e3852760eab8a951c7b1
|