TECH

code2prompt : Streamlining LLM Prompt Generation From Codebases

code2prompt is a command-line tool (CLI) that converts your codebase into a single LLM prompt with a source tree, prompt templating, and token counting.

Table Of Contents

  • Features
  • Installation
  • Usage
  • Templates
  • User Defined Variables
  • Tokenizers
  • Python SDK
  • Contribution
  • License
  • Support The Author

Features

You can run this tool on the entire directory and it would generate a well-formatted Markdown prompt detailing the source tree structure, and all the code.

You can then upload this document to either GPT or Claude models with higher context windows and ask it to:

  • Quickly generate LLM prompts from codebases of any size.
  • Customize prompt generation with Handlebars templates. (See the default template)
  • Respects .gitignore (can be disabled with --no-ignore).
  • Filter and exclude files using glob patterns.
  • Control hidden file inclusion with --hidden flag.
  • Display the token count of the generated prompt. (See Tokenizers for more details)
  • Optionally include Git diff output (staged files) in the generated prompt.
  • Automatically copy the generated prompt to the clipboard.
  • Save the generated prompt to an output file.
  • Exclude files and folders by name or path.
  • Add line numbers to source code blocks.

You can customize the prompt template to achieve any of the desired use cases. It essentially traverses a codebase and creates a prompt with all source files combined.

In short, it automates copy-pasting multiple source files into your prompt and formatting them along with letting you know how many tokens your code consumes.

Installation

Binary Releases

Download the latest binary for your OS from Releases.

Source Build

Requires:

  • Git, Rust and Cargo.
git clone https://github.com/mufeedvh/code2prompt.git
cd code2prompt/
cargo build --release

cargo

installs from the crates.io registry.

cargo install code2prompt

For unpublished builds:

cargo install --git https://github.com/mufeedvh/code2prompt --force

For more information click here.

Varshini

Varshini is a Cyber Security expert in Threat Analysis, Vulnerability Assessment, and Research. Passionate about staying ahead of emerging Threats and Technologies.

Recent Posts

How AI Puts Data Security at Risk

Artificial Intelligence (AI) is changing how industries operate, automating processes, and driving new innovations. However,…

2 hours ago

The Evolution of Cloud Technology: Where We Started and Where We’re Headed

Image credit:pexels.com If you think back to the early days of personal computing, you probably…

4 days ago

The Evolution of Online Finance Tools In a Tech-Driven World

In an era defined by technological innovation, the way people handle and understand money has…

4 days ago

A Complete Guide to Lenso.ai and Its Reverse Image Search Capabilities

The online world becomes more visually driven with every passing year. Images spread across websites,…

5 days ago

How Web Application Firewalls (WAFs) Work

General Working of a Web Application Firewall (WAF) A Web Application Firewall (WAF) acts as…

1 month ago

How to Send POST Requests Using curl in Linux

How to Send POST Requests Using curl in Linux If you work with APIs, servers,…

1 month ago