code2prompt logo

code2prompt

CLI and TUI that converts a codebase into a single LLM prompt with a source tree, Handlebars templates, git context, and token estimates.

install

code2prompt is a Rust command-line tool that reads a codebase and formats it as a single prompt for large language models. Running code2prompt . writes the prompt to stdout, -c copies it to the clipboard, and --output-file prompt.txt saves it to a file. It also ships an interactive terminal UI for configuring what goes into the prompt.

Input selection uses glob include/exclude patterns and respects .gitignore rules. Output is built from Handlebars templates, so the prompt layout can be customized for different use cases. The tool can also include git diffs, logs, and branch comparisons. It has special handling for formats such as CSV, Jupyter notebooks, and JSONL. Token counts are estimated from parallel per-file counts plus estimated template overhead, with optional line numbers. The README notes that the full rendered prompt is not re-tokenized.

The project is split into a Rust core library, the CLI/TUI, a Python SDK (code2prompt-rs on PyPI) for scripts, agents, and RAG pipelines, and an MCP server that lets agentic applications read a local codebase. An agent skill can be installed with npx skills add mufeedvh/code2prompt. It helps coding agents gather scoped context, using a function and class map when the optional entity-map feature is built, and a directory map otherwise. It suits developers who paste repository context into chat LLMs, and those building automation or agent tooling around codebase context.

Installation

# via Homebrew
brew install code2prompt
# via Cargo
cargo install code2prompt
# via pip (Python SDK)
pip install code2prompt-rs

code2prompt demo

Alternatives & related tools

add a badge to your README

Maintain code2prompt? Show that it's featured on trmn. The badge links back to this page.

Featured on trmn
Markdown
[![Featured on trmn](https://www.trmn.sh/badge/code2prompt.svg)](https://www.trmn.sh/tools/code2prompt?utm_source=badge)
HTML
<a href="https://www.trmn.sh/tools/code2prompt?utm_source=badge"><img src="https://www.trmn.sh/badge/code2prompt.svg" alt="Featured on trmn" height="20"></a>