code2prompt
ModelFreeA CLI tool to convert your codebase into a single LLM prompt with source tree, prompt templating, and token counting.
Capabilities13 decomposed
gitignore-aware recursive directory traversal with intelligent file discovery
Medium confidenceRecursively discovers files in a codebase while respecting .gitignore rules through native git integration, building an in-memory file tree that filters out ignored paths before processing. Uses the ignore crate to parse .gitignore patterns and applies them during traversal, avoiding unnecessary I/O on excluded directories. This enables developers to automatically exclude vendor directories, build artifacts, and other non-essential files without manual configuration.
Integrates the Rust `ignore` crate for native .gitignore parsing during traversal rather than post-filtering, eliminating I/O on ignored paths and providing performance benefits on large repositories with deep ignore rules
Faster than tools that traverse all files then filter (e.g., simple glob-based tools) because it skips I/O on ignored directories entirely, and more reliable than regex-based .gitignore emulation because it uses the standard ignore crate
glob pattern-based file filtering with user override capability
Medium confidenceApplies glob patterns to filter files discovered during directory traversal, supporting both inclusion and exclusion patterns with explicit user overrides that take precedence over defaults. The filtering engine evaluates patterns in sequence (include patterns first, then exclusions) and allows users to force-include files that would normally be filtered out via CLI flags or configuration. This enables fine-grained control over which files appear in the final prompt without re-running the entire traversal.
Implements a two-pass filtering system where user-specified overrides (via --include and --exclude flags) take precedence over default patterns, allowing developers to surgically override filtering rules without modifying configuration files
More flexible than static .gitignore-only filtering because it supports dynamic inclusion/exclusion patterns, and more intuitive than regex-based filtering because it uses familiar glob syntax
session-based state management for multi-step prompt generation workflows
Medium confidenceImplements a Code2PromptSession struct that maintains state across multiple configuration and generation steps, enabling developers to build multi-step workflows (configure filters, select files, generate prompt) without re-traversing the filesystem. Sessions encapsulate the file tree, token map, configuration, and template state, allowing incremental modifications and multiple prompt generations from the same session. This is particularly useful for interactive workflows where users make multiple selections before final output.
Implements a stateful session object that encapsulates the entire processing pipeline (file tree, token map, configuration, template) and allows incremental modifications without re-traversal, enabling efficient multi-step workflows and interactive tools
More efficient than stateless tools because it avoids repeated filesystem traversals, and more flexible than single-shot tools because it supports incremental modifications and multiple generations
binary file detection and safe handling with encoding options
Medium confidenceDetects binary files using magic byte analysis (checking file headers for known binary signatures) and handles them safely by either skipping them or base64-encoding them for inclusion in prompts. This prevents binary data from corrupting text-based prompts while preserving the option to include binary metadata if needed. The detection uses heuristics (null bytes, non-UTF8 sequences) to identify binary files with high accuracy.
Uses magic byte analysis (checking file headers for known binary signatures) combined with heuristic detection (null bytes, non-UTF8 sequences) to identify binary files with high accuracy, preventing corruption of text-based prompts
More robust than extension-based detection because it identifies binaries by content rather than filename, and more efficient than reading entire files because it only examines headers
sorting and organization of files in prompt output with customizable ordering
Medium confidenceOrganizes files in the generated prompt using customizable sorting strategies (alphabetical, by size, by modification time, by directory depth) to improve readability and enable LLMs to process related files together. Files can be grouped by directory, sorted within groups, and presented in a hierarchical structure that mirrors the filesystem. This enables developers to control how files appear in the prompt without modifying the underlying file tree.
Implements multiple sorting strategies (alphabetical, by size, by modification time, by directory depth) that can be applied independently or combined, allowing developers to optimize file presentation for different use cases
More flexible than fixed ordering because it supports multiple strategies, and more efficient than manual file organization because it's automated and reproducible
specialized file format conversion to llm-readable text
Medium confidenceProcesses specialized file types (CSV, JSONL, Jupyter notebooks, binary files) into structured text representations suitable for LLM consumption, with format-specific handlers that preserve semantic information. CSV files are converted to markdown tables, JSONL is pretty-printed with indentation, Jupyter notebooks extract code cells and markdown, and binary files are detected and either skipped or base64-encoded. Each processor is modular and can be extended to support additional formats without modifying the core pipeline.
Implements a pluggable processor architecture where each file format has a dedicated handler (CSVProcessor, JSONLProcessor, NotebookProcessor) that can be extended independently, allowing developers to add custom processors without touching the core pipeline
More comprehensive than simple text extraction because it preserves semantic structure (tables for CSV, code cells for notebooks), and more robust than naive file reading because it detects binary files and prevents corruption
token counting and context window management with per-file accounting
Medium confidenceCounts tokens using tiktoken-rs (OpenAI's tokenizer) to track context usage and prevent exceeding LLM context window limits, providing per-file token counts and cumulative totals. The system tracks tokens for file content, templates, and metadata separately, allowing developers to see exactly which files consume the most tokens and make informed decisions about inclusion. A token map is maintained during processing to enable interactive token-aware file selection in the TUI.
Maintains a detailed token map during processing that tracks tokens per file and enables interactive token-aware file selection in the TUI, allowing users to see real-time token impact of including/excluding files
More granular than simple total token counts because it breaks down tokens by file, enabling informed decisions about which files to include; more accurate than manual estimation because it uses tiktoken-rs
git-aware context generation with diff, log, and branch comparison
Medium confidenceIntegrates with git to include version control information in prompts, supporting git diffs (staged/unstaged changes), commit logs, and branch comparisons. Developers can include recent commits, changes between branches, or the current diff to provide LLMs with context about recent modifications. This is implemented via git2-rs bindings that query the repository's git objects directly, avoiding shell invocations and enabling cross-platform compatibility.
Uses git2-rs for direct git object access rather than shelling out to git commands, enabling cross-platform compatibility and avoiding subprocess overhead while maintaining full access to git history and diff generation
More efficient than shell-based git integration because it avoids subprocess overhead, and more reliable than parsing git CLI output because it uses the native libgit2 library
template-based prompt generation with variable substitution and conditional blocks
Medium confidenceGenerates prompts using Handlebars-style templates that support variable substitution, conditional blocks, and iteration over file lists. Templates are rendered with context variables (codebase structure, file contents, git information) and can include conditional sections (e.g., 'if has_git_info'). This enables developers to create reusable prompt templates that adapt to different codebases without manual editing, with built-in templates for common scenarios (code review, documentation generation, etc.).
Implements a Handlebars-based template system with built-in context variables for codebase structure, file contents, and git information, allowing developers to create sophisticated prompts without writing code
More flexible than hardcoded prompt generation because templates are reusable and adaptable, and more powerful than simple string interpolation because it supports conditionals and iteration
interactive tui-based file selection with real-time token feedback
Medium confidenceProvides a terminal user interface (TUI) built with ratatui using an Elm/Redux architecture for state management, enabling interactive file selection with real-time token counting feedback. Users can navigate a file tree, toggle files on/off, see token impact of each selection, and preview the generated prompt before output. The TUI maintains a Redux-style state machine where user actions (select file, toggle, navigate) dispatch events that update the model and re-render the view.
Implements a full Elm/Redux-style state machine in Rust for TUI state management, where each user action (file selection, navigation, template editing) is a discrete event that updates an immutable model and triggers re-renders, enabling predictable and testable UI behavior
More user-friendly than CLI-only tools because it provides visual feedback and interactive exploration, and more maintainable than imperative TUI code because the Redux pattern separates state management from rendering
multi-interface api exposure via cli, python sdk, and mcp server
Medium confidenceExposes the core code2prompt_core library through three distinct interfaces: a CLI binary (via clap argument parsing), Python bindings (via PyO3), and an MCP (Model Context Protocol) server for agentic applications. Each interface wraps the core library with domain-specific concerns (argument parsing for CLI, Python type conversion for SDK, MCP message handling for agents). This architecture allows the same business logic to be consumed by shell scripts, Python applications, and AI agents without duplication.
Implements a three-tier architecture where code2prompt_core is the single source of truth, with three independent interface layers (CLI, Python, MCP) that each wrap the core without duplicating business logic, enabling consistent behavior across all interfaces
More flexible than single-interface tools because it supports CLI, Python, and agent access from the same codebase, and more maintainable than separate implementations because business logic is centralized in the core library
configuration file-based settings with yaml/toml support and cli override
Medium confidenceSupports configuration files (YAML or TOML format) that specify default settings for file filtering, templates, output formats, and token limits, with CLI arguments taking precedence over file-based settings. Configuration files are loaded from standard locations (.code2prompt.yaml, code2prompt.toml) and can be overridden per-invocation via CLI flags. This enables teams to establish project-wide defaults while allowing individual developers to customize behavior without modifying shared configuration.
Implements a two-level configuration system where file-based defaults are merged with CLI overrides using a precedence system (CLI > file > hardcoded defaults), allowing teams to establish baselines while preserving per-invocation customization
More flexible than hardcoded defaults because it supports project-wide configuration, and more convenient than CLI-only tools because developers don't need to repeat flags for common workflows
output routing to multiple destinations with format selection
Medium confidenceRoutes generated prompts to multiple output destinations (stdout, file, clipboard) with support for different output formats (plain text, JSON, markdown). The output system abstracts destination handling so the same prompt can be written to different targets without code changes. Clipboard output uses the arboard crate for cross-platform compatibility, and file output supports automatic path resolution and directory creation.
Implements an abstraction layer for output destinations that decouples prompt generation from output handling, allowing the same prompt to be routed to stdout, file, or clipboard without conditional logic in the core pipeline
More convenient than piping to separate tools because it supports clipboard output natively, and more flexible than single-destination tools because it supports multiple formats and destinations
Capabilities are decomposed by AI analysis. Each maps to specific user intents and improves with match feedback.
Related Artifactssharing capabilities
Artifacts that share capabilities with code2prompt, ranked by overlap. Discovered automatically through the match graph.
auto-md
Convert Files / Folders / GitHub Repos Into AI / LLM-ready Files
get-llms-txt
Generate LLM-friendly llms.txt files from markdown and MDX content files
GenAIScript
Generative AI Scripting.
Gito
AI code reviewer for GitHub Actions or local use, compatible with any LLM and integrated with...
DesktopCommanderMCP
This is MCP server for Claude that gives it terminal control, file system search and diff file editing capabilities
grepmax
Semantic code search for coding agents. Local embeddings, LLM summaries, call graph tracing.
Best For
- ✓developers managing large codebases with complex .gitignore rules
- ✓teams working with monorepos where selective file inclusion is critical
- ✓engineers building LLM context for code analysis without manual file selection
- ✓developers needing selective file inclusion beyond .gitignore rules
- ✓teams with project-specific filtering requirements (e.g., exclude all .test.js files)
- ✓engineers building context for domain-specific LLM tasks (e.g., only documentation files)
- ✓developers building interactive prompt generation tools
- ✓teams creating multi-step workflows that need to preserve state
Known Limitations
- ⚠Respects only .gitignore at repository root and subdirectories; nested .gitignore files are processed but may have unexpected precedence
- ⚠Symlinks are followed by default which may cause infinite loops in circular symlink structures
- ⚠Performance degrades on filesystems with >100k files due to single-threaded traversal
- ⚠Glob patterns are evaluated sequentially; complex pattern interactions may be unintuitive
- ⚠No support for negative lookahead or advanced regex features; limited to standard glob syntax
- ⚠Pattern matching is case-sensitive on Unix-like systems and case-insensitive on Windows, which may cause cross-platform inconsistencies
Requirements
Input / Output
UnfragileRank
UnfragileRank is computed from adoption signals, documentation quality, ecosystem connectivity, match graph feedback, and freshness. No artifact can pay for a higher rank.
Repository Details
Last commit: Apr 14, 2026
About
A CLI tool to convert your codebase into a single LLM prompt with source tree, prompt templating, and token counting.
Categories
Alternatives to code2prompt
Are you the builder of code2prompt?
Claim this artifact to get a verified badge, access match analytics, see which intents users search for, and manage your listing.
Get the weekly brief
New tools, rising stars, and what's actually worth your time. No spam.
Data Sources
Looking for something else?
Search →