---
title: Code2Prompt Documentation
description: Official Code2prompt Documentation
template: splash
hero:
  tagline: Transform Your Code into AI-Optimized Prompts in Seconds
  image:
    file: ../../../assets/logo_dark_v0.0.1.svg
  actions:
    - text: Get Started 🚀
      link: /docs/tutorials/getting_started
    - text: Installation 📥
      link: /docs/how_to/install
---

import { Card, CardGrid } from "@astrojs/starlight/components";
import { LinkCard } from "@astrojs/starlight/components";

## Quick Start

<LinkCard title="Getting Started 🚀" href="/docs/tutorials/getting_started" />
<LinkCard title="Installation 📥" href="/docs/how_to/install" />
<LinkCard title="Learn Filtering 🔍" href="/docs/tutorials/learn_filters" />
<LinkCard title="Learn Templating 📝" href="/docs/tutorials/learn_templates" />
<LinkCard title="Vision 🔮" href="/docs/vision" />

`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:

<CardGrid>
  <Card title="Core" icon="seti:rust">
    Core library blazingly fast for code ingestion
  </Card>
  <Card title="CLI" icon="seti:powershell">
    Command Line Interface specially designed for humans
  </Card>
  <Card title="SDK" icon="seti:python">
    Software Development Kit for AI agents and automation scripts
  </Card>
  <Card title="MCP" icon="seti:folder">
    Model Context Protocol server for LLMs on steroids
  </Card>
</CardGrid>
---

## Key Features

- **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.

---

## Why `code2prompt`?

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.

---

## Example Use Cases

- **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.
