# code2prompt

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

Stars: 7.7k · Language: Rust · License: MIT · Categories: AI

- Repository: https://github.com/mufeedvh/code2prompt
- Website: https://code2prompt.dev
- Page: https://www.trmn.sh/tools/code2prompt

## Install

- Homebrew: `brew install code2prompt`
- Cargo: `cargo install code2prompt`
- pip (Python SDK): `pip install code2prompt-rs`

## Overview

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

```bash
# via Homebrew
brew install code2prompt
```

```bash
# via Cargo
cargo install code2prompt
```

```bash
# via pip (Python SDK)
pip install code2prompt-rs
```

![code2prompt demo](https://media.trmn.sh/cached/5fe4fd61d58480afa843ef3258a1536716b896b30c89436343d883bef8ee0dfe.gif)

## Alternatives

- [AIChat](https://www.trmn.sh/tools/aichat.md): LLM CLI with a shell assistant, chat REPL, RAG, function calling and agents, supporting 20+ providers including OpenAI, Claude, Gemini and Ollama. (Rust, 10.5k stars)
- [models](https://www.trmn.sh/tools/models.md): TUI and CLI for browsing AI models, benchmarks, coding agents, and provider statuses from multiple data sources. (Rust, 517 stars)
- [Codewhale](https://www.trmn.sh/tools/codewhale.md): Rust terminal coding agent that reads a repo, edits files, runs commands and checks results using hosted or local models (Ollama, vLLM, SGLang). (Rust, 41.1k stars)
- [herdr](https://www.trmn.sh/tools/herdr.md): Terminal multiplexer written in Rust that runs coding agents in persistent panes, tracks working/blocked/idle state, and manages local and SSH machines. (Rust, 46.3k stars)
- [Goose](https://www.trmn.sh/tools/goose.md): Open source AI agent for desktop, CLI, and API with 15+ provider integrations and Model Context Protocol extensions (Rust, 55.9k stars)

---

Canonical: https://www.trmn.sh/tools/code2prompt
