code2prompt is an open source command line tool designed to convert an entire codebase into a structured prompt that can be easily used with large language models. It analyzes a project directory, gathers relevant source files, and formats them into a single prompt that includes the source tree and code content. This approach helps developers quickly provide full project context to AI models without manually copying files or assembling prompts. code2prompt is built in Rust and focuses on performance, enabling fast traversal of large repositories while maintaining low resource usage. It also respects common project conventions such as .gitignore, ensuring that unnecessary files are automatically excluded from the generated prompt. The generated output can be saved to a file, printed to standard output, or copied to the clipboard for immediate use. In addition to the core command line interface, the project also includes a library, Python bindings, and an MCP server.
Features
- Generates a complete prompt from an entire codebase including source tree
- Interactive terminal user interface for configuring prompt generation
- Smart file filtering that respects .gitignore and glob patterns
- Customizable prompt templates using the Handlebars templating system
- Token usage tracking to stay within language model context limits
- Optional Git integration to include diffs, logs, or branch comparisons