Skip to content

Code2Prompt Documentation

Transform Your Code into AI-Optimized Prompts in Seconds

code2prompt is a powerful code ingestion tool designed to generate prompts for code analysis, generation, and other tasks. It works by traversing directories, building a tree structure, and gathering informations about each file.

It simplifies the process of combining and formatting code, making it easy to analyze, document, or refactor code using LLMs

You can use code2prompt the following ways:

Core

Core library blazingly fast for code ingestion

CLI

Command Line Interface specially designed for humans

SDK

Software Development Kit for AI agents and automation scripts

MCP

Model Context Protocol server for LLMs on steroids


  • Generate LLM Prompts: Quickly convert entire codebases into structured LLM prompts.
  • Glob Pattern Filtering: Include or exclude specific files and directories using glob patterns.
  • Customizable Templates: Tailor prompt generation with Handlebars templates.
  • Token Counting: Analyze token usage and optimize for LLMs with varying context windows.
  • Git Integration: Include Git diffs and commit messages in prompts for code reviews.
  • Respects .gitignore: Automatically ignores files listed in .gitignore to streamline prompt generation.

  1. Save Time:

    • Automates the process of traversing a codebase and formatting files for LLMs.
    • Avoids repetitive copy-pasting of code.
  2. Improve Productivity:

    • Provides a structured and consistent format for code analysis.
    • Helps identify bugs, refactor code, and write documentation faster.
  3. Handle Large Codebases:

    • Designed to work seamlessly with large codebases, respecting context limits of LLMs.
  4. Customizable Workflows:

    • Flexible options for filtering files, using templates, and generating targeted prompts.

  • Code Documentation: Automatically generate documentation for public functions, methods, and classes.

  • Bug Detection: Find potential bugs and vulnerabilities by analyzing your codebase with LLMs.

  • Refactoring: Simplify and optimize code by generating prompts for code quality improvements.

  • Learning and Exploration: Understand new codebases by generating summaries and detailed breakdowns.

  • Git Commit and PR Descriptions: Generate meaningful commit messages and pull request descriptions from Git diffs.