Stop manually copying files into ChatGPT/Claude.
contextkit scans any codebase and generates clean, token-counted markdown summaries optimized for LLM context windows.
When asking LLMs about your code, you need to:
- Copy the relevant files
- Stay under the token limit
- Include enough context for good answers
Doing this manually is tedious. contextkit automates it.
pip install contextkit
# Generate context for current directory
contextkit .
# Target a specific model
contextkit . --model claude-3.5-sonnet
contextkit . --model gpt-4o
# Just check token count
contextkit . --count
# Compact overview (tree + key files only)
contextkit . --compact
# Split large codebase into chunks
contextkit . --chunked
# Save to file
contextkit . -o context.md- Token counting for 30+ LLM models (GPT-4, Claude, Llama, Gemini, etc.)
- Respects .gitignore — skips ignored files automatically
- Smart filtering — skips binaries, lock files, node_modules, etc.
- Chunking — splits large codebases to fit context limits
- Multiple modes — full, compact, tree-only, stats-only
- Extension filtering — only include specific file types
- JSON output — for programmatic use
| Model | Context Limit |
|---|---|
| GPT-4 | 8K tokens |
| GPT-4 Turbo / GPT-4o | 128K tokens |
| Claude 3 (all variants) | 200K tokens |
| Gemini 1.5 Pro | 1M tokens |
| Llama 3.1 (all sizes) | 128K tokens |
| Mistral Large | 128K tokens |
| Deepseek V2 | 128K tokens |
| Qwen 2 | 128K tokens |
contextkit .
# Generates full markdown with:
# - Directory tree
# - Codebase statistics
# - All file contents
# - Token count at bottomcontextkit . --count
# Output:
# Model: gpt-4
# Context limit: 8.2K tokens
# Estimated usage: 12.5K tokens (152.4%)
# Remaining: 0 tokens
# Files: 47# Only Python and JavaScript files
contextkit . --ext py js
# Only TypeScript
contextkit . --ext ts tsxcontextkit . --compact
# Shows:
# - Quick stats
# - Directory tree
# - Key files (README, package.json, main files)contextkit . --chunked
# Splits into multiple chunks that each fit context window
# Useful for processing large codebases in parts# Ignore test files
contextkit . --ignore "*.test.js" "*.spec.py"
# Ignore specific directories
contextkit . --ignore "tests/" "docs/"contextkit . --stats-only --json
contextkit . --chunked --jsonfrom contextkit import CodebaseScanner, TokenCounter, ContextGenerator
# Scan a directory
scanner = CodebaseScanner("/path/to/project")
files = scanner.scan()
# Count tokens
counter = TokenCounter("gpt-4o")
print(f"Tokens: {counter.estimate(content)}")
# Generate context
generator = ContextGenerator(scanner, model="claude-3.5-sonnet")
context = generator.generate(instructions="Explain the architecture")
# Generate chunks
chunks = generator.generate_chunked()
for chunk in chunks:
print(f"Chunk {chunk.index}: {chunk.tokens} tokens, {chunk.file_count} files")contextkit . -o context.md
# Paste context.md into ChatGPT/Claude
# Ask questions about your codecontextkit . --ext py --ignore "tests/" -o review.mdcontextkit . --compact -o overview.md
# Ask LLM to generate docs from the overviewcontextkit . -o codebase-summary.md
# Share with new team memberscontextkit . --model gpt-4o --chunked
# Feed chunks sequentially to AI agents# Codebase Context
## Codebase Statistics
- **Files:** 47
- **Lines:** 3,842
- **Size:** 156.3 KB
### By Language
- **Python:** 28 files, 2,341 lines
- **JavaScript:** 12 files, 891 lines
- **Markdown:** 7 files, 610 lines
## Directory Structure
myproject/ ├── src/ │ ├── main.py │ └── utils.py ├── tests/ │ └── test_main.py └── README.md
## File Contents
### `src/main.py`
```python
# ... file contents ...
Context: 4.2K tokens (51.2% of 8.2K limit)
## System Requirements
- Python 3.8+
- No external dependencies (except pathspec)
- Works on Linux, macOS, Windows
## Contributing
Areas where help is needed:
- [ ] Add tiktoken support for exact OpenAI token counts
- [ ] Support for more file types
- [ ] VS Code extension
- [ ] Watch mode (auto-regenerate on file changes)
## License
MIT — Use it however you want.
---
**Built for developers who talk to AI about their code.**