code2prompt is a codebase-to-prompt converter and LLM context generator that transforms source code and directory structures into formatted text blocks for large language models. It functions as both a utility for generating prompts and an AI agent context server that exposes codebase files and metadata to coding assistants via a standardized server protocol.
The tool distinguishes itself through git-aware capabilities, integrating commit messages and branch diffs to provide version control context for AI-generated code changes. It also utilizes the Model Context Protocol to allow external AI assistants to programmatically query project files.
The system manages context through glob-based file filtering and gitignore rule adherence to refine source file selection. It includes a token counter to ensure the aggregated codebase fits within a model's context window and employs custom templates to define the structural layout of the final output.