code2prompt
A CLI tool to convert your codebase into a single LLM prompt with source tree, prompt templating, and token counting.
A command-line tool that packages an entire code project into a single formatted block of text you can paste into an AI assistant, with token counting, gitignore support, and customizable output templates.
code2prompt is a command-line tool that takes a software project on your computer and converts it into a single block of text formatted for use with an AI language model. When you want to ask an AI assistant about a codebase, you typically need to paste the relevant code into the chat. Doing that manually is tedious, especially for large projects with many files. code2prompt automates that process.
You point the tool at a directory, and it walks through the files, collects their contents, and formats everything into a structured prompt. It respects .gitignore rules, which means it skips files your project has already marked as unimportant, like compiled output or environment files. It also tracks token counts, which is useful because AI models have limits on how much text they can process at once.
The tool has several components. The core is a Rust library that handles file reading and formatting at high speed. On top of that is a command-line interface with a minimal interactive mode, and a Python package for developers who want to integrate this behavior into their own scripts or AI agent workflows. There is also a local server mode that allows AI agent applications to access your codebase without you needing to pipe files around manually.
Templating is supported through Handlebars, a templating format, so you can customize how the output is structured for different kinds of questions or tasks. Git integration is also included, letting you add diffs, commit logs, or branch comparisons to the prompt.
Installation is available via Cargo (the Rust package manager), Homebrew on macOS, pip for the Python SDK, or by downloading a pre-built binary. The project is open source under the MIT License.
Where it fits
- Instantly package your entire codebase into a single AI-ready prompt to ask ChatGPT or Claude to review, explain, or refactor it.
- Use the Python SDK to integrate automated codebase-to-prompt conversion into your own AI agent or scripting workflow.
- Add git diffs or commit logs to your AI prompt to ask for a code review of your latest changes.