@avinashchby/repopack
v0.1.0
Published
Pack an entire codebase into a single LLM-optimized markdown file
Downloads
17
Maintainers
Readme
repopack
Pack an entire codebase into a single LLM-optimized markdown file.
Install
npm install -g repopackOr run without installing:
npx repopackRequires Node.js >= 18.
Usage
# Pack current directory → repopack-output.md
npx repopack
# Pack a specific directory with a custom output file
npx repopack ./src -o context.md
# Truncate largest files first to stay under a token budget
npx repopack --max-tokens 100000
# Only include TypeScript files, skip tests
npx repopack --include "*.ts,*.tsx" --exclude "*.test.*"
# Strip comments and collapse blank lines (shrinks token count)
npx repopack --compress
# Print token stats without writing any file
npx repopack --stats
# Copy output to clipboard instead of writing a file
npx repopack --copyAll options
| Flag | Default | Description |
|------|---------|-------------|
| [dir] | . | Directory to pack |
| -o, --output <file> | repopack-output.md | Output file path |
| --include <globs> | **/* | Comma-separated glob patterns to include |
| --exclude <globs> | — | Comma-separated glob patterns to exclude |
| --max-tokens <n> | — | Token budget; drops largest files first until under limit |
| --compress | off | Strip comments and collapse blank lines |
| --stats | off | Print token stats to stdout, skip file write |
| --copy | off | Copy output to clipboard instead of writing a file |
Output format
# Repository: my-project
Generated by repopack | 42 files | ~18,400 tokens
## File Treemy-project ├── src │ ├── index.ts │ └── utils.ts └── package.json
## src/index.ts
```typescript
// ... file contentssrc/utils.ts
// ... file contents
Each file gets a level-2 heading with its relative path and a fenced code block with the correct language tag. Paste the whole file directly into any chat or API call.
---
## Smart defaults
The following are excluded automatically, with no configuration needed:
- `node_modules/`
- `.git/`
- Lock files: `package-lock.json`, `yarn.lock`, `pnpm-lock.yaml`, `bun.lockb`
- Environment files: `.env`, `.env.*`
- Binary files: images, fonts, audio, video, archives, executables, PDFs
Your `.gitignore` rules are also respected automatically.
---
## Token counting
repopack uses `cl100k_base` (tiktoken) to count tokens — the same encoding used by GPT-4. Claude and Gemini token counts are approximated with the same encoder, which is accurate to within ~5% for typical source code.
`--stats` output shows usage against each model's context window:
Total tokens: 18,400
Model context usage: GPT-4 18,400 / 128,000 tokens (14.4%) Claude 18,400 / 200,000 tokens (9.2%) Gemini 18,400 / 1,000,000 tokens (1.8%)
**Context limits used for comparison:**
| Model | Limit |
|-------|-------|
| GPT-4 | 128,000 tokens |
| Claude | 200,000 tokens |
| Gemini | 1,000,000 tokens |
Use `--max-tokens` to truncate when you need to stay within a specific limit. Files are dropped largest-first until the output fits.
---
## .repopackignore
Place a `.repopackignore` file in your project root to exclude files that you don't want in `.gitignore`. Uses the same syntax as `.gitignore`.
.repopackignore
dist/ *.generated.ts fixtures/
Priority order (highest to lowest): `--exclude` flag → `.repopackignore` → `.gitignore` → built-in defaults.
---
## Compression
`--compress` reduces token count by:
1. Stripping comments (JS/TS/Python; other languages are left untouched)
2. Collapsing consecutive blank lines to a single blank line
3. Trimming trailing whitespace per line
Typical reduction is 10–30% depending on how comment-heavy the codebase is.
---
## License
MIT — see [LICENSE](LICENSE).