Skip to main content

Smart codebase context extraction for LLMs - with optional AI-powered filtering

Project description

ContextuAIze

PyPI version Python 3.8+ License: MIT

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

pip install contextuaize

Or install from source:

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.


<<<<<<< Updated upstream Author: Arsen Ohanyan โ€ข GitHub

Author: Arsen Ohanyan โ€ข GitHub โ€ข PyPI

Stashed changes

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.1.tar.gz (13.2 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.1-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file contextuaize-0.2.1.tar.gz.

File metadata

  • Download URL: contextuaize-0.2.1.tar.gz
  • Upload date:
  • Size: 13.2 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.1.tar.gz
Algorithm Hash digest
SHA256 5cf82e995074f99f3048579368b478f568ded5cb128b7ba4685b6b47ee77a93e
MD5 3299ccf4e40b00f3da633677d354a27a
BLAKE2b-256 88f5dc88d478b3b20a6f5dca21f09f9eef0efd9dbbf5ec47e31d86a815af94a9

See more details on using hashes here.

File details

Details for the file contextuaize-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: contextuaize-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 5.2 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 db67dedd37d05c9a4e646985b88bd1595dc00bddda2c617dd40e880a46c5d7a5
MD5 661b4dfdac2f800a0da60d859ddaea0e
BLAKE2b-256 19d2aaf20197a122dfce3e441296dbcb6fee95c3c2d1d1180ba094f5ba13a3af

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