c2ctx
v2.0.0
Published
Convert source code folders into LLM-optimized context files with intelligent compression and analysis
Downloads
6
Maintainers
Readme
🤖 c2ctx - Code to Context Converter
Convert your source code folders into LLM-optimized context files with intelligent compression, statistics, and multiple output formats. Perfect for feeding code context to ChatGPT, Claude, or other AI models.
✨ Features
- 🗜️ Smart Compression: Removes unnecessary whitespace and comments while preserving code structure
- 📊 Project Analytics: Detailed statistics about your codebase (files, lines, languages)
- 🎯 Language Detection: Automatically detects and categorizes 15+ programming languages
- 📁 Large File Handling: Summarizes large files instead of including full content
- 🚫 Smart Ignoring: Comprehensive default ignore list + custom patterns
- 📝 Multiple Formats: Output in Markdown or plain text
- ⚡ Fast & Lightweight: Zero dependencies, pure Node.js
🚀 Quick Start
Global Installation
npm install -g c2ctx
c2ctx ./srcNPX (Recommended - No Installation)
npx c2ctx ./srcLocal Installation
npm install --save-dev c2ctx
npx c2ctx ./src📖 Usage
Basic Usage
# Convert src folder to context.txt
c2ctx ./src
# Also available as full name
code-to-context ./srcAdvanced Usage
# Custom output file and format
c2ctx ./src --output my-context.md --format markdown
# Ignore additional files/patterns
c2ctx ./src --ignore "*.test.js" "temp" "__tests__"
# Adjust max file size (default: 50KB)
c2ctx ./src --max-size 100000
# Disable compression and metrics
c2ctx ./src --no-compression --no-metrics
# Quiet mode
c2ctx ./src --quiet🎛️ Options
| Option | Alias | Default | Description |
| ------------------ | ----- | ------------- | ------------------------------------------ |
| --output | -o | context.txt | Output file name |
| --format | -f | markdown | Output format (markdown or text) |
| --ignore | | [] | Additional files/patterns to ignore |
| --max-size | | 50000 | Max file size before summarization (bytes) |
| --no-compression | | false | Disable code compression |
| --no-metrics | | false | Disable statistics generation |
| --quiet | -q | false | Suppress progress messages |
| --help | -h | | Show help message |
📁 Default Ignore List
The tool automatically ignores common files and directories:
.git, node_modules, .vscode, .idea, dist, build, coverage
.env*, *.log, package-lock.json, yarn.lock, pnpm-lock.yaml
.DS_Store, thumbs.db, *.tmp, *.temp, .cache, .next
__pycache__, *.pyc, .pytest_cache, venv, env
target, *.class, .gradle, bin, obj🗂️ Supported Languages
- Web: JavaScript, TypeScript, HTML, CSS, SCSS
- Backend: Python, Java, C++, C#, Go, Rust, PHP, Ruby
- Mobile: Swift, Kotlin
- Config: JSON, YAML, TOML, ENV files
- Others: Shell scripts, SQL, Docker, Markdown
📊 Example Output
# 🤖 LLM Context File
Generated: 2024-01-15T10:30:00.000Z
Source: /path/to/your/project
## 📦 Project: my-awesome-app
- **Version**: 1.0.0
- **Description**: An awesome application
- **Main**: index.js
## 📁 src/index.js
```javascript
import express from "express";
const app = express();
// ... rest of your code
```📊 Project Statistics
- Total Files: 25
- Total Lines: 1,250
- Total Size: 125.5 KB
- Large Files Skipped: 0
Language Breakdown:
- javascript: 15 files
- typescript: 8 files
- json: 2 files
## 🔧 Programmatic Usage
```javascript
const CodeContextConverter = require('c2ctx');
const converter = new CodeContextConverter({
maxFileSize: 100000,
enableCompression: true,
format: 'markdown'
});
const success = converter.createContextFile(
'./src',
'output.md',
['custom-ignore-pattern'],
false // quiet mode
);🤝 Use Cases
- LLM Context: Feed your codebase to ChatGPT, Claude, or other AI models
- Code Reviews: Generate comprehensive code summaries
- Documentation: Create project overviews with statistics
- Onboarding: Help new team members understand project structure
- Analysis: Get insights into your codebase composition
🛠️ Development
git clone https://github.com/yourusername/c2ctx.git
cd c2ctx
npm test📄 License
MIT © [Your Name]
🤔 FAQ
Q: Why is my output file large?
A: Try reducing --max-size or adding more patterns to --ignore.
Q: Can I use this in CI/CD?
A: Yes! Use --quiet flag for clean automation.
Q: Does it work with monorepos? A: Absolutely! Point it to any folder structure.
Q: How does compression work? A: Removes excessive whitespace, empty lines, and non-essential comments while preserving code structure.
⭐ Found this useful? Star the repo! ⭐
