code2prompt logo

Code2prompt

by mufeedvh

293 forks
5,105 stars
Free

What is code2prompt

code2prompt is a versatile tool developed by mufeedvh that allows you to transform your entire codebase into a single prompt for Large Language Models (LLMs). Designed to streamline the process of generating prompts from your code, code2prompt simplifies code analysis and automation tasks by converting your directory's structure and files into a comprehensive prompt. This is particularly useful for tasks such as generating documentation, finding security vulnerabilities, and enhancing code quality.

How to Use code2prompt

Using code2prompt is straightforward, whether you prefer the command-line interface (CLI) or integrating it into your Python applications using the SDK.

CLI Usage

  1. Installation: Install code2prompt using Cargo or pip, depending on your preference.

    • For CLI: cargo install code2prompt
    • For Python SDK: pip install code2prompt-rs
  2. Basic Prompt Generation: To generate a prompt from your codebase, simply use:

    code2prompt path/to/codebase
    
  3. Customization: Customize your prompt generation with various options:

    • Use Handlebars templates to tailor the output.
    • Filter files using glob patterns to include or exclude specific files.
    • Display the token count of the generated prompt for better insight.
  4. Output Management: The generated prompt can be automatically copied to your clipboard or saved to a file.

Python SDK

  1. Integration: Import the code2prompt module in your Python application.

    from code2prompt import CodePrompt
    
  2. Prompt Generation: Create a CodePrompt object and generate prompts programmatically.

    prompt = CodePrompt("./my_project", include_patterns=["*.py"])
    result = prompt.generate(encoding="cl100k")
    print(result["prompt"])
    

Key Features of code2prompt

  • Comprehensive Prompt Generation: Quickly generate prompts from codebases of any size by traversing directory structures and compiling all relevant information.
  • Custom Templates: Leverage built-in Handlebars templates for various scenarios, or create your own to suit specific needs.
  • Token Management: Easily manage and display token counts for the generated prompts, with support for multiple tokenizer encodings.
  • Codebase Interaction: The Python SDK allows for seamless integration into automation scripts and AI agents, making it versatile for various programming needs.
  • Efficient Output: Automatically copy prompts to the clipboard or save them to files, enhancing workflow efficiency.
  • Flexible Filtering: Use glob patterns to include or exclude files, control hidden file inclusion, and manage .gitignore settings for precise prompt generation.
  • Git Integration: Generate prompts including Git diff outputs or create Git commit messages and pull request descriptions, all with customizable templates.

With code2prompt, transforming your codebase into a structured prompt for LLMs becomes a streamlined and efficient process, enabling enhanced code analysis, documentation, and automation.

How to Use

To use the code2prompt, follow these steps:

  1. Visit https://github.com/mufeedvh/code2prompt
  2. Follow the setup instructions to create an account (if required)
  3. Connect the MCP server to your Claude Desktop application
  4. Start using code2prompt capabilities within your Claude conversations

Additional Information

Created

March 9, 2024

Company

mufeedvh

Start building your own MCP Server

Interested in creating your own MCP Server? Check out the official documentation and resources.

Learn More