Skip to main content

Share your codebase with LLMs - codebase export tool for AI conversations

Project description

contextr (ctxr)

A streamlined command-line tool designed for developers to easily share their codebase with Large Language Models (LLMs). contextr helps you monitor specific files and directories, intelligently handles ignore patterns, and lets you instantly export formatted code context to your clipboard - perfect for pasting into ChatGPT, Claude, or other AI chat interfaces.

Think of it as "git add" but for AI conversations - select the files you want your AI assistant to see, and export them in a Markdown format optimized for LLM comprehension.

Features

  • 🔍 Smart File Selection: Watch specific file patterns and automatically track changes
  • 🚫 Git-Style Ignores: Full support for ignore patterns including negation with !
  • 📋 One-Click Export: Sync changes and copy formatted context to clipboard instantly
  • 🎨 LLM-Optimized Output: Markdown formatting with syntax highlighting for 40+ languages
  • 💾 Context Profiles: Save and instantly switch between different context configurations
  • 🔄 Auto-Sync: Automatically detect when watched files are added or removed
  • 🌐 Cross-Platform: Works seamlessly on Linux, macOS, and Windows
  • 🔗 Path Intelligence: Handles symlinks, ~ expansion, and environment variables
  • 🤖 Modern Development: Type-safe code with 62% test coverage and strict linting

Installation

Method 1: Install from PyPI (Recommended)

The easiest way to install (requires Python 3.12+):

pip install contextr

This makes both ctxr (short alias) and contextr commands available globally.

Method 2: Install from source

# Clone the repository
git clone https://github.com/your-username/contextr.git
cd contextr

# Install using uv (recommended for development)
uv sync --extra dev

# Or install with pip
pip install -e .

Quick Start

# Initialize contextr in your project
ctxr init

# Add files to watch (supports glob patterns)
ctxr watch "src/**/*.py" "docs/*.md" "*.yaml"

# Ignore test files and build artifacts
ctxr ignore "**/__pycache__/**" "**/node_modules/**" "*.pyc"

# Sync watched files and copy to clipboard
ctxr sync

# Paste into your favorite LLM and start coding!

Core Commands

File Selection & Monitoring

  • watch <patterns> - Add file patterns to monitor

    ctxr watch "src/**/*.py" "tests/**/*.py" "*.md"
    
  • unwatch <patterns> - Remove patterns from watch list

    ctxr unwatch "tests/**"
    
  • watch-list - Display all watched patterns

    ctxr watch-list
    
  • list - Show current file context as a tree

    ctxr list
    

Context Management

  • sync - Refresh context from watched files and export to clipboard

    ctxr sync
    
  • init - Initialize contextr in current directory

    ctxr init
    

Ignore Patterns

  • ignore <pattern> - Add pattern to ignore list

    ctxr ignore "**/*.log" "build/**"
    
  • unignore <pattern> - Remove pattern from ignore list

    ctxr unignore "**/*.log"
    
  • ignore-list - Show all ignored patterns

    ctxr ignore-list
    
  • gitignore-sync - Import patterns from .gitignore

    ctxr gitignore-sync
    

Advanced Usage

Pattern Examples

contextr supports standard glob patterns and git-style ignore syntax:

# Watch all Python files
ctxr watch "**/*.py"

# Watch specific directories
ctxr watch "src/" "lib/" "tests/"

# Watch with multiple extensions
ctxr watch "**/*.{js,jsx,ts,tsx}"

# Ignore patterns with negation
ctxr ignore "**/*.test.py"    # Ignore all test files
ctxr ignore "!important.test.py"  # But include this specific test

Context Profiles

Save and instantly switch between different context configurations:

# Save current context as a profile
ctxr profile save backend --description "Backend API development"

# Load a saved profile
ctxr profile load backend

# List all saved profiles
ctxr profile list

# Delete a profile
ctxr profile delete backend

Output Format

contextr generates clean, LLM-friendly Markdown output:

# Project Context: your-project
Files selected: 5

## File Structure

src/ ├── main.py ├── utils/ │ ├── helpers.py │ └── config.py └── models/ └── user.py README.md


## File Contents

### src/main.py
```python
# Your code here with proper syntax highlighting

src/utils/helpers.py

# More code with language detection

## How It Works

1. **Pattern Matching**: Uses glob patterns to match files, with full support for `**` recursive matching
2. **Ignore System**: Implements git-style ignore rules including directory-specific patterns and negation
3. **File Detection**: Automatically detects programming languages for syntax highlighting
4. **Smart Formatting**: Escapes code blocks properly to prevent Markdown rendering issues
5. **Clipboard Integration**: Uses pyperclip for cross-platform clipboard support

## Configuration

contextr stores its configuration in a `.contextr/` directory in your project:

- `.contextr/state.json` - Current context state and watched patterns
- `.contextr/.ignore` - Custom ignore patterns
- `.contextr/states/` - Saved named states (coming soon)

## Development

```bash
# Install development dependencies
uv sync --extra dev

# Run tests
uv run pytest

# Type checking
uv run pyright

# Linting and formatting
uv run ruff check .
uv run ruff format .

Why Use contextr?

For Developers:

  • 🚀 Save time by automating code context preparation
  • 🎯 Ensure you include all relevant files for LLM understanding
  • 🔄 Keep context updated as your code changes
  • 📦 Manage different contexts for different features/discussions

For LLMs:

  • 📝 Consistent, well-formatted code presentation
  • 🗂️ Clear file structure visualization
  • 🏷️ Proper syntax highlighting for better comprehension
  • 📍 Complete file paths for precise references

Requirements

  • Python >= 3.12
  • Cross-platform: Linux, macOS, Windows

License

MIT License

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Roadmap

  • Context Profiles - Save and switch between different contexts
  • Profile templates for common project types
  • Interactive file selection mode
  • Custom output templates
  • Integration with popular IDEs
  • Direct LLM API integration
  • Context size optimization
  • Team profile sharing

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

contextr-1.1.1.tar.gz (24.5 kB view details)

Uploaded Source

Built Distribution

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

contextr-1.1.1-py3-none-any.whl (25.6 kB view details)

Uploaded Python 3

File details

Details for the file contextr-1.1.1.tar.gz.

File metadata

  • Download URL: contextr-1.1.1.tar.gz
  • Upload date:
  • Size: 24.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for contextr-1.1.1.tar.gz
Algorithm Hash digest
SHA256 4e268f77ba3f00e6f2d24bdbfc8bb455c0db8ddc753610ff38bedf73e3ff45cb
MD5 229fade3a5591bb9682673614c304c81
BLAKE2b-256 ad2bb94992b160bec113957a0711580ccbde92d6b7bdb36a955e75781d06b9a6

See more details on using hashes here.

Provenance

The following attestation bundles were made for contextr-1.1.1.tar.gz:

Publisher: release.yml on nathan-luo/contextr

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file contextr-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: contextr-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 25.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for contextr-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 000df2bfd660dca74b741460ddfe963c5af1c9a43064bc76a823cc65167e176c
MD5 217f9b6c425780f9fa7bc60bc9de9df4
BLAKE2b-256 4aa6baffbcd2e7d2e83e6d027ff14245c0c6e029a3e282f72c11e7200ead5f78

See more details on using hashes here.

Provenance

The following attestation bundles were made for contextr-1.1.1-py3-none-any.whl:

Publisher: release.yml on nathan-luo/contextr

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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