codefetch

Recursively fetches all code files in the current directory, ignoring what's in .gitignore and .codefetchignore,
then outputs them into a single Markdown file with line numbers.
Usage
Basic usage with output file:
npx codefetch -o my-complete-source.md
With token limit (useful for AI models):
npx codefetch --max-tokens 20000 -o output.md
npx codefetch -tok 20000 -o output.md
Filter by file extensions:
npx codefetch -e .ts,.js -o typescript-files.md
npx codefetch --extension ts,js -o typescript-files.md
If no output file is specified (-o or --output), it will print to stdout.
Options
--output <file> | -o | Specify output filename |
--max-tokens <number> | -tok | Limit output tokens (useful for AI models) |
--extension <ext,...> | -e | Filter by file extensions (e.g., .ts,.js) |
Installation
You can run directly with npx:
npx codefetch
Or install globally:
npm install -g codefetch
codefetch -o output.md
Ignoring Files
codefetch supports two ways to ignore files:
.gitignore - Respects your project's existing .gitignore patterns
.codefetchignore - Additional patterns specific to codefetch
The .codefetchignore file works exactly like .gitignore and is useful when you want to ignore files that aren't in your .gitignore. For example:
# .codefetchignore
*.test.js
docs/
temp/
*.md
Both files support standard gitignore patterns including:
- Exact matches (
file.txt)
- Directories (
dir/)
- Wildcards (
*.log)
- Negation (
!important.log)
Use with AI Tools
You can use this command to create code-to-markdown in bolt.new and ask the AI chat for guidance about your codebase. The --max-tokens option helps ensure your output stays within AI model token limits.
License
MIT