Skip to main content

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

  1. Walks the directory tree
  2. Respects .gitignore rules automatically
  3. Skips universal noise (node_modules, .git, lockfiles, binaries)
  4. Concatenates all text files with clear markers

Smart Mode

  1. Two-pass scanning: First scans structure, then uses LLM to select files
  2. Relevance scoring: Files ranked as essential โ†’ important โ†’ optional โ†’ skip
  3. Query-driven: When you specify --query, only files relevant to that task are included
  4. 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 files
  • test* โ€” 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

contextuaize-0.2.0.tar.gz (13.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

contextuaize-0.2.0-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

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

Hashes for contextuaize-0.2.0.tar.gz
Algorithm Hash digest
SHA256 f1bdd69a192ce2911be3ffdba3b37fec2fda8f92d9a227556c03a193210b50cf
MD5 cec4aab03b530a251e65725d13950fd4
BLAKE2b-256 b1e1a84f59f46700aff1fb731f1de865d80cb780d5529a3f707f94c1fcee90d3

See more details on using hashes here.

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

Hashes for contextuaize-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 aaa3381c0dd1e5b9c0723f1c435bae61d8e2d28b540b814c0ec9742c07380105
MD5 924c61d1f14fe0dac6d18aa926f7d92e
BLAKE2b-256 a00da3122be440c666780f6d69eed69a2ffa611c19a4e3852760eab8a951c7b1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page