A CLI tool that bundles a codebase into a single Markdown file for uploading to Claude Projects or custom ChatGPTs.
mufeedvh/code2prompt
A Rust CLI that packs a codebase into a single prompt for LLMs, with a source tree, Handlebars templates, and token estimates.
- Stars
- 7,747
- Forks
- 457
- Open issues
- 19
- Last commit
- 3 days ago
What is it?
Code2Prompt converts a project directory into one structured prompt that can be pasted into ChatGPT, Claude, or another LLM, or passed to an agent. The output includes a source tree and the contents of the selected files, so a model receives the surrounding context without manual copying.
Files are selected with glob include and exclude patterns and filtered by .gitignore rules. Prompts are rendered through Handlebars templates, and the tool can add git diffs, logs, and branch comparisons. It also reads some non-code formats such as CSV, Jupyter notebooks, and JSONL in a simplified form.
The project provides a Rust core library, a command-line tool with an interactive TUI, a Python SDK published on PyPI, and an MCP server for local agent applications. Token counts are estimated per file rather than by re-tokenizing the full rendered prompt.
Key features
- 01Builds a source tree and file contents into one prompt.
- 02Filters files with glob patterns and respects .gitignore.
- 03Customizes output with Handlebars templates.
- 04Estimates token counts per file, with optional line numbers.
- 05Includes git diffs, logs, and branch comparisons.
- 06Available as a CLI, Python SDK, and MCP server.
Use cases
- Pasting a project's context into a chat LLM for code review or debugging.
- Feeding a repository to an AI agent through the Python SDK or MCP server.
- Sharing only the relevant files and recent diffs with a model.
- Estimating how many tokens a codebase will consume before sending it.
Quick start
- 1
Install the CLI with Cargo
cargo install code2prompt - 2
Or install with Homebrew
brew install code2prompt - 3
Generate a prompt from the current directory
code2prompt . - 4
Save the prompt to a file
code2prompt path/to/project --output-file prompt.txt
Things to know
- Requires a Rust toolchain if installed through Cargo or built from source.
In collections
Topics
FAQ
- What is code2prompt?
- A Rust CLI that packs a codebase into a single prompt for LLMs, with a source tree, Handlebars templates, and token estimates. Code2Prompt converts a project directory into one structured prompt that can be pasted into ChatGPT, Claude, or another LLM, or passed to an agent. The output includes a source tree and the contents of the selected files, so a model receives the surrounding context without manual copying.
- Is code2prompt free to use? What license does it have?
- code2prompt is open source under the MIT license. Check the license terms before using it in commercial products.
- Is code2prompt still maintained?
- Actively maintained. The last commit to code2prompt was on Nov 3, 2026.
- What can I use code2prompt for?
- Pasting a project's context into a chat LLM for code review or debugging. Feeding a repository to an AI agent through the Python SDK or MCP server. Sharing only the relevant files and recent diffs with a model. Estimating how many tokens a codebase will consume before sending it.
- How do I install code2prompt?
- Install the CLI with Cargo: cargo install code2prompt Or install with Homebrew: brew install code2prompt Generate a prompt from the current directory: code2prompt . Save the prompt to a file: code2prompt path/to/project --output-file prompt.txt
- Where can I get code2prompt?
- The source code and installation instructions are on GitHub: https://github.com/mufeedvh/code2prompt
Summary generated by AI from the project's README. GitHub stats refresh daily.
Related projects
Turns a Git repository or local directory into a single prompt-friendly text digest for feeding code to LLMs.
A CLI and web tool that packs an entire code repository into one AI-friendly file for feeding to LLMs like Claude or ChatGPT.
A structured, reusable prompt design framework for LLMs, with a template of Role, Profile, Goal, Skills, Rules and Workflow sections.
A community-curated open-source library of prompts for AI chat models, with a website, CSV/Hugging Face datasets, CLI and MCP server integration.
A suite of developer tools for building, testing, evaluating and deploying LLM-based applications, with a VS Code flow designer and a pf CLI.