A utility for generating LLM-friendly context files from codebases with intelligent filtering and structure visualization.
- Recursive directory traversal
- Gitignore-style pattern matching
- File size limits
- Visual directory tree with ignored/size-exceeded annotations
- Markdown output with syntax highlighting
- Context description integration
pip install pathspecpython code2llm.py [OPTIONS]| Flag | Description | Default |
|---|---|---|
--target-dir |
Directory to process | . (current dir) |
--ignore-file |
Path to ignore rules file | .context.ignore |
--output |
Output file path | context.md |
--max-size |
Maximum file size in bytes | 102400 (100KB) |
--context-file |
Path to optional context description file | None |
-
Basic usage:
python code2llm.py
-
Process specific directory with custom ignore rules:
python code2llm.py --target-dir ./src --ignore-file .custom-ignore
-
Generate output with 2MB size limit and project description:
python code2llm.py --max-size 2097152 --context-file project-info.md
# Common ignore patterns
*.env
*.log
*.bin
*.hex
*.pdf
*.jpg
*.png
*.zip
.DS_Store
# Directories
node_modules/
__pycache__/
.vscode/
dist/
build/-
Context Overview (optional):
Contains content from --context-file -
Codebase Structure:
Visual directory tree showing all files with ignored/size-exceeded annotations -
File Contents:
All included files with syntax-highlighted content
- Use
--context-fileto provide architectural overview - Keep generated files under 1MB for chat-based LLMs
- Regularly update
.context.ignoreas project evolves - Combine with manual context descriptions for best results