A powerful CLI tool to recursively collect and concatenate source code files from your project into a single, AI-friendly context file.
contextify is designed to help you share your project's codebase with AI agents (like ChatGPT, Claude, or Copilot) for analysis, code review, or debugging. Instead of manually copying and pasting files, contextify creates a single, well-organized file containing all relevant source code.
✨ Recursive Directory Traversal: Automatically finds all relevant source files in your project.
🎯 Smart File Filtering: Include specific file types (Python, JavaScript, TypeScript, etc.) with extensible configuration.
🚫 Intelligent Exclusion: Respects .gitignore rules and supports custom exclusion patterns via .aicontextignore.
🔧 Zero Configuration: Works out-of-the-box with sensible defaults for common development artifacts.
📋 Structured Output: Generates clean Markdown with file path headers for easy navigation.
🔍 Verbose Logging: Understand exactly which files are being processed and why.
Install contextify globally from PyPI:
pip install contextifyOr with uv:
uv pip install contextifyClone the repository and install in editable mode:
git clone https://github.com/yourusername/contextify.git
cd contextify
uv venv
source .venv/bin/activate # On Windows: .venv\Scripts\Activate.ps1
uv pip install -e .From any directory, run:
contextifyThis generates ai_context.md in the current directory containing all recognized source files.
contextify --helpArguments:
-
--output OUTPUT_FILE(default:ai_context.md)- Path where the aggregated context file will be written.
-
--extensions EXTS(default:.py,.js,.ts,.jsx,.tsx,.html,.css,.scss,.md,.json,.toml,.yaml,.yml,.xml,.sql,.sh,.bash)- Comma-separated list of file extensions to include.
- Example:
--extensions ".py,.js,.md"
-
--ignore-file FILE- Path to a custom ignore file (e.g.,
.aicontextignore). - Overrides
.gitignoreif provided.
- Path to a custom ignore file (e.g.,
-
--verbose- Enable verbose DEBUG logging to see detailed processing information.
contextify --extensions ".py" --verbosecontextify --ignore-file .aicontextignore --output ./project_context.mdcontextify --extensions ".js,.jsx,.ts,.tsx,.html,.css,.json" --output ./web_context.md- Configuration: Loads ignore patterns from
.gitignoreand optional.aicontextignore. - Traversal: Recursively walks your project directory.
- Filtering: Includes files matching specified extensions, excludes those matching ignore patterns.
- Aggregation: Reads each file and concatenates contents with path headers.
- Output: Writes formatted Markdown to the specified output file.
# src/main.py
def main():
print("Hello, World!")
# src/utils.js
function greet(name) {
return `Hello, ${name}!`;
}By default, contextify ignores:
- Version control:
.git/,.gitignore - Python:
__pycache__/,*.pyc,.venv/,venv/,*.egg-info/,dist/,build/ - Node.js:
node_modules/,npm-debug.log - IDE/Editors:
.vscode/,.idea/,*.sublime-project - OS files:
.DS_Store,Thumbs.db - Logs and environment:
*.log,.env
Create a .aicontextignore file in your project root with patterns (gitignore format):
# Example .aicontextignore
tests/
docs/
*.test.py
secrets/
Patterns follow gitignore syntax:
dirname/matches directories*.extmatches files by extension!patternnegates a rule (re-inclusion)- Lines starting with
#are comments
The generated ai_context.md is formatted specifically for sharing with AI systems:
- Clear headers show file paths for easy reference
- Raw code without syntax highlighting for universal compatibility
- Structured format aids AI parsing and understanding
- Minimal metadata keeps the file focused on actual code
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
contextify/
├── src/contextify/
│ ├── __init__.py
│ ├── main.py # CLI interface
│ ├── core.py # Traversal and aggregation logic
│ ├── patterns.py # Ignore strategies and pattern matching
│ └── logger.py # Logging configuration
├── tests/ # Unit tests
├── pyproject.toml # Project metadata and dependencies
└── README.md
uv pip install -e ".[dev]"
pytest
pytest --version
#Run with Coverage Report
pytest --cov=src/contextify --cov-report=html
#Then open htmlcov/index.html in your browser to see coverage.
The project adheres to:
- PEP 8 via
ruff - Type hints for all functions and classes
- SOLID principles for maintainable architecture
- Comprehensive docstrings for all public APIs
MIT License. See LICENSE file for details.
Created with ❤️ for developers who work with AI agents.
Questions or suggestions? Open an issue on GitHub.