Convert your codebase into AI-ready prompts
A fast, token-efficient tool that transforms your code into optimized context for Claude, ChatGPT, and other LLMs.
Documentation โข Installation โข Quick Start โข Examples
Working with AI assistants requires code context, but:
- ๐ด Entire repositories exceed token limits
- ๐ด Manual file selection is tedious and error-prone
- ๐ด Standard formats (JSON, XML) waste precious tokens
- ๐ด You never know if you'll hit the context limit until it's too late
promptext intelligently filters your codebase, ranks files by relevance, and packages them into token-efficient formatsโall within your specified budget.
| Challenge | Manual Approach | promptext Solution |
|---|---|---|
| Selecting relevant files | ๐ Manually browse and choose | ๐ง Automatic relevance scoring |
| Staying within token limits | โ Trial and error, wasted API calls | โ Enforced budgets with preview |
| Efficient formatting | ๐ Verbose markdown/JSON | ๐ฆ 25-60% token reduction |
| Token counting | โ Guesswork | ๐ฏ Accurate tiktoken counting |
| Processing speed | ๐ Copy-paste each file | โก Entire codebase in seconds |
- ๐ Fast: Written in Goโprocesses large codebases in seconds
- ๐ง Smart: Relevance scoring automatically prioritizes important files
- ๐ฐ Budget-Aware: Enforces token limits to prevent context overflow and save on API costs
- ๐ฆ Token-Efficient Formats: PTX (25-30% savings), TOON-strict (30-60% savings), Markdown, or XML
- ๐ฏ Accurate Counting: Uses
cl100k_basetokenizer (GPT-4, GPT-3.5, Claude compatible) - โ๏ธ Highly Configurable: Project-level
.promptext.ymland global settings support
macOS/Linux:
curl -sSL promptext.sh/install | bashWindows:
irm promptext.sh/install.ps1 | iexGo Install (requires Go 1.19+):
go install github.com/1broseidon/promptext/cmd/promptext@latestManual Download: Download pre-built binaries from GitHub Releases
The executable is installed as promptext with prx alias.
# Check for updates
prx --check-update
# Update to latest version
prx --updateUninstall:
curl -sSL promptext.sh/uninstall | bashNote:
promptextautomatically checks for new releases once per day and notifies you when updates are available.
Navigate to your project directory and run:
promptext
# or use the alias
prxThat's it! promptext will:
- Analyze your project structure
- Filter out unnecessary files (node_modules, binaries, etc.)
- Package everything into a token-efficient format (PTX by default)
- Copy the result to your clipboard
Now paste into ChatGPT, Claude, or your favorite LLM and start coding!
Perfect for:
- ๐ AI Code Review โ Feed complete projects to Claude/ChatGPT for comprehensive analysis
- ๐ค AI Pair Programming โ Provide full context to GitHub Copilot, Cursor, or Windsurf
- ๐ Documentation Generation โ Help AI understand your complete project structure
- ๐ Bug Investigation โ Let AI analyze related files together with proper context
- ๐ Code Migration โ Give LLMs full legacy codebase context for refactoring
- ๐ฏ Prompt Engineering โ Create consistent, repeatable AI prompts from code
- ๐ Library Integration โ Use the Go API to integrate code extraction into your AI/ML workflows
- ๐ ๏ธ Build Custom Tools โ Embed promptext capabilities in your own applications
# Process current directory and copy to clipboard
prx
# Process specific directory
prx /path/to/project
# Filter by file extensions
prx -e .go,.js,.ts
# Output to file (format auto-detected from extension)
prx -o context.ptx # PTX format
prx -o context.md # Markdown format
prx -o project.xml # XML format
# Show file list and token counts (no output)
prx -i
# Preview file selection without generating output
prx --dry-runBuild focused prompts with relevance scoring and token budgets. Start simple and combine options as needed:
# Start simple: Find authentication-related files
prx -r "auth login session"
# Add a token budget for smaller context windows
prx -r "auth login session" --max-tokens 8000
# Narrow down by file extensions
prx -r "auth login session" --max-tokens 8000 -e .go,.js
# Save to a file for reuse
prx -r "auth login session" --max-tokens 8000 -e .go,.js -o auth-context.ptx
# Complex example: Database layer with multiple keywords
prx -r "database SQL postgres migration schema" --max-tokens 12000 -e .go,.sql -o db-layer.ptxReal-world scenarios:
# Bug investigation: error handling code for limited context LLM
prx -r "error exception handler logging" --max-tokens 5000
# API routes for models with larger context windows
prx -r "api routes handlers middleware" --max-tokens 20000
# Quick security audit: authentication and authorization
prx -r "auth token jwt security session" --max-tokens 10000 -e .go,.js,.tsFiles are ranked by keyword matches with weighted scoring:
| Match Location | Score | Example |
|---|---|---|
| Filename | 10x | auth.go matches "auth" |
| Directory path | 5x | auth/handlers/ matches "auth" |
| Import statements | 3x | import auth matches "auth" |
| File content | 1x | "auth" appears in code |
Files with the highest scores are included first until the token budget is exhausted.
When --max-tokens is set, promptext shows exactly what was included:
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ ๐ฆ promptext (Go) โ
โ Included: 7/18 files โข ~4,847 tokens โ
โ Full project: 18 files โข ~19,512 tokens โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ ๏ธ Excluded 11 files due to token budget:
โข internal/cli/commands.go (~784 tokens)
โข internal/app/app.go (~60 tokens)
... and 9 more files (~8,453 tokens)
Total excluded: ~9,297 tokens
This helps you understand the trade-offs and adjust your filters or budget as needed.
promptext can be used as a Go library in your own applications, allowing you to programmatically extract code context and integrate it into AI/ML workflows.
go get github.com/1broseidon/promptext/pkg/promptextpackage main
import (
"fmt"
"log"
"github.com/1broseidon/promptext/pkg/promptext"
)
func main() {
// Simple extraction
result, err := promptext.Extract(".")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Extracted %d files (%d tokens)\n",
len(result.ProjectOutput.Files),
result.TokenCount)
// Use the formatted output
fmt.Println(result.FormattedOutput)
}Filter by extensions:
result, err := promptext.Extract(".",
promptext.WithExtensions(".go", ".mod", ".sum"),
promptext.WithExcludes("*_test.go", "vendor/"),
)AI-optimized extraction with token budget:
result, err := promptext.Extract(".",
promptext.WithRelevance("auth", "login"),
promptext.WithTokenBudget(8000),
promptext.WithFormat(promptext.FormatPTX),
)
// Send to AI API
sendToAI(result.FormattedOutput)Reusable extractor:
extractor := promptext.NewExtractor(
promptext.WithExtensions(".go"),
promptext.WithTokenBudget(5000),
)
result1, _ := extractor.Extract("/project1")
result2, _ := extractor.Extract("/project2")Format conversion:
result, _ := promptext.Extract(".", promptext.WithFormat(promptext.FormatPTX))
// Convert to different formats
markdown, _ := result.As(promptext.FormatMarkdown)
jsonl, _ := result.As(promptext.FormatJSONL)WithExtensions(extensions ...string)- Include specific file extensionsWithExcludes(patterns ...string)- Exclude files matching patternsWithGitIgnore(enabled bool)- Respect .gitignore patterns (default: true)WithDefaultRules(enabled bool)- Use built-in filtering rules (default: true)WithRelevance(keywords ...string)- Filter by keyword relevanceWithTokenBudget(maxTokens int)- Limit output to token budgetWithFormat(format Format)- Set output format (PTX, JSONL, Markdown, XML)WithVerbose(enabled bool)- Enable verbose loggingWithDebug(enabled bool)- Enable debug logging with timing
FormatPTX- PTX v2.0 (recommended for AI)FormatJSONL- Machine-friendly JSONLFormatMarkdown- Human-readable markdownFormatXML- Machine-parseable XML
result, err := promptext.Extract("/invalid/path")
if err != nil {
if errors.Is(err, promptext.ErrInvalidDirectory) {
// Handle invalid directory
}
if errors.Is(err, promptext.ErrNoFilesMatched) {
// Handle no matching files
}
}See the examples/ directory for complete working examples:
examples/basic/- Simple usage patternsexamples/token-budget/- AI-focused extraction with token limits
For full API documentation, see pkg.go.dev/github.com/1broseidon/promptext/pkg/promptext
promptext supports multiple output formats optimized for different use cases:
| Format | Token Efficiency | Best For |
|---|---|---|
| PTX (default) | 25-30% reduction | General AI interactions, code analysis |
| TOON-strict | 30-60% reduction | Maximum compression, large codebases |
| Markdown | Baseline (0%) | Human readability, documentation |
| XML | -20% (more verbose) | Structured parsing, tool integration |
PTX is a hybrid format created specifically for promptext. It balances token efficiency with readability by using explicit file paths and preserving multiline code blocks.
Example:
code:
"internal/config.go": |
package config
type Config struct {
Port int
}
"cmd/server/main.go": |
package main
func main() {
// ...
}
files[2]{path,ext,lines}:
internal/config.go,go,67
cmd/server/main.go,go,45Why PTX?
- โ Zero ambiguity โ AI instantly maps code to exact file paths
- โ Token efficient โ ~30% savings vs. markdown
- โ Human readable โ No mental translation needed
- โ LLM-friendly โ Clear structure for better AI comprehension
# PTX (default) โ balanced compression and readability
prx
# TOON-strict โ maximum compression
prx -f toon-strict
# Markdown โ no compression, human-friendly
prx -f markdown
# XML โ structured output
prx -f xmlFormat Reference: PTX and TOON-strict are based on johannschopplich/toon
Customize promptext behavior with configuration files. Settings are applied in order (later overrides earlier):
- Global config:
~/.config/promptext/config.yml - Project config:
.promptext.yml - CLI flags
Generate a starter configuration file in your project:
prx --initThis creates a .promptext.yml file with sensible defaults. Customize it for your project:
# File extensions to include
extensions:
- .go
- .js
- .ts
# Patterns to exclude (supports glob patterns)
excludes:
- "vendor/"
- "node_modules/"
- "*.test.go"
# Default output format
format: ptx # Options: ptx, toon-strict, markdown, xml
# Use .gitignore patterns
gitignore: true
# Enable verbose output
verbose: falseSet defaults for all projects in ~/.config/promptext/config.yml:
extensions:
- .go
- .py
- .js
- .ts
excludes:
- "vendor/"
- "__pycache__/"
format: ptxThe following are always excluded automatically:
- Version control:
.git/,.hg/,.svn/ - Dependencies:
node_modules/,vendor/,__pycache__/ - Lock files:
*-lock.json,*.lock,Gemfile.lock,poetry.lock, etc. - Binary files: Detected by content analysis
- Gitignored files: Respects your
.gitignorepatterns
Tip: Override exclusions with the
-xflag orexcludeslist in your config file.
For comprehensive documentation, visit 1broseidon.github.io/promptext
Topics covered:
- ๐ Configuration Reference โ All options and settings
- ๐ฏ Filtering Rules โ How files are selected and excluded
- ๐งฎ Relevance Scoring โ Algorithm details and tuning
- ๐ข Token Counting โ Methodology and accuracy
- ๐ฆ Format Specifications โ PTX, TOON-strict, Markdown, and XML
- โก Performance โ Benchmarks and optimization tips
Contributions are welcome! Whether it's bug reports, feature requests, or code contributions, we'd love your help.
- ๐ Report bugs โ Open an issue
- ๐ก Suggest features โ Start a discussion
- ๐ Improve docs โ Help make documentation clearer
- ๐ง Submit PRs โ Fix bugs or add features
# Clone the repository
git clone https://github.com/1broseidon/promptext.git
cd promptext
# Build the project
go build -o prx ./cmd/promptext
# Run tests
go test ./...
# Run with coverage
go test -coverprofile=coverage.out ./...- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes and add tests
- Ensure tests pass (
go test ./...) - Commit your changes (
git commit -m 'Add amazing feature') - Push to your fork (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License โ see the LICENSE file for details.
Built with โค๏ธ by the promptext community
โญ Star on GitHub โข ๐ Documentation โข ๐ Report Bug