mufeedvh/code2prompt
A CLI tool to convert your codebase into a single LLM prompt with source tree, prompt templating, and token counting.
What it solves
It eliminates the tedious manual process of copying and formatting multiple files from a codebase when providing context to Large Language Models (LLMs). It solves the problem of "context engineering" by automating the ingestion and structuring of local codebases into a single, LLM-ready prompt.
How it works
Built in Rust for high performance, the tool traverses directories and reads files while respecting .gitignore rules. It uses Handlebars templates to format the gathered code and metadata into a structured prompt. It offers multiple interfaces: a CLI for quick use, a TUI for interactive configuration, a Python SDK for integration into agents or RAG pipelines, and an MCP server for agentic applications to access local codebases efficiently.
Who it’s for
It is designed for developers who manually provide code context to AI chat interfaces (like ChatGPT), developers building AI agents, and engineers implementing RAG (Retrieval-Augmented Generation) pipelines that require codebase ingestion.
Highlights
- Smart Filtering: Supports glob patterns and automatically respects
.gitignoresettings. - Git Integration: Can include Git diffs, logs, and branch comparisons in the generated prompt.
- Token Estimation: Provides parallel per-file token counts to estimate the prompt size.
- Flexible Output: Supports outputting to stdout, saving to a file, or copying directly to the clipboard.
- Multi-language Support: Includes specialized reading for formats like CSV, Notebooks, and JSONL.
Related
- Project
- Project
- Project
- Dispatch
- Project