Smart code context extractor for AI assistants
22
stars
668
commits
Go
primary language
Apr 12, 2026
updated
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.
Working with AI assistants requires code context, but:
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 |
cl100k_base tokenizer (GPT-4, GPT-3.5, Claude compatible).promptext.yml and global settings supportmacOS/Linux:
curl -sSL chain.sh/promptext/scripts/install.sh | bash
Windows:
irm chain.sh/promptext/scripts/install.ps1 | iex
Go Install (requires Go 1.19+):
go install github.com/1broseidon/promptext/cmd/promptext@latest
Manual 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 --update
Uninstall:
curl -sSL chain.sh/promptext/scripts/uninstall.sh | bash
Note:
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
prx
That's it! promptext will:
Now paste into ChatGPT, Claude, or your favorite LLM and start coding!
Perfect for:
# 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-run
Build 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.ptx
Real-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,.ts
Files 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/promptext
package 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 timingFormatPTX - PTX v2.0 (recommended for AI)FormatJSONL - Machine-friendly JSONLFormatMarkdown - Human-readable markdownFormatXML - Machine-parseable XMLresult, 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 limitsFor 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,45
Why PTX?
# 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 xml
Format Reference: PTX and TOON-strict are based on johannschopplich/toon
Customize promptext behavior with configuration files. Settings are applied in order (later overrides earlier):
~/.config/promptext/config.yml.promptext.ymlGenerate a starter configuration file in your project:
prx --init
This 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: false
Set defaults for all projects in ~/.config/promptext/config.yml:
extensions:
- .go
- .py
- .js
- .ts
excludes:
- "vendor/"
- "__pycache__/"
format: ptx
The following are always excluded automatically:
.git/, .hg/, .svn/node_modules/, vendor/, __pycache__/*-lock.json, *.lock, Gemfile.lock, poetry.lock, etc..gitignore patternsTip: Override exclusions with the
-xflag orexcludeslist in your config file.
For comprehensive documentation, visit chain.sh/promptext
Topics covered:
Contributions are welcome! Whether it's bug reports, feature requests, or code contributions, we'd love your help.
# 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 ./...
git checkout -b feature/amazing-feature)go test ./...)git commit -m 'Add amazing feature')git push origin feature/amazing-feature)This project is licensed under the MIT License — see the LICENSE file for details.
Built with ❤️ by the promptext community
658 commits
10 commits
Go
84.0%
Astro
5.9%
Shell
4.3%
PowerShell
2.3%
CSS
1.6%
Makefile
1.3%
Smart code context extractor for AI assistants
22
stars
668
commits
Go
primary language
Apr 12, 2026
updated
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.
Working with AI assistants requires code context, but:
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 |
cl100k_base tokenizer (GPT-4, GPT-3.5, Claude compatible).promptext.yml and global settings supportmacOS/Linux:
curl -sSL chain.sh/promptext/scripts/install.sh | bash
Windows:
irm chain.sh/promptext/scripts/install.ps1 | iex
Go Install (requires Go 1.19+):
go install github.com/1broseidon/promptext/cmd/promptext@latest
Manual 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 --update
Uninstall:
curl -sSL chain.sh/promptext/scripts/uninstall.sh | bash
Note:
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
prx
That's it! promptext will:
Now paste into ChatGPT, Claude, or your favorite LLM and start coding!
Perfect for:
# 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-run
Build 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.ptx
Real-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,.ts
Files 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/promptext
package 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 timingFormatPTX - PTX v2.0 (recommended for AI)FormatJSONL - Machine-friendly JSONLFormatMarkdown - Human-readable markdownFormatXML - Machine-parseable XMLresult, 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 limitsFor 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,45
Why PTX?
# 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 xml
Format Reference: PTX and TOON-strict are based on johannschopplich/toon
Customize promptext behavior with configuration files. Settings are applied in order (later overrides earlier):
~/.config/promptext/config.yml.promptext.ymlGenerate a starter configuration file in your project:
prx --init
This 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: false
Set defaults for all projects in ~/.config/promptext/config.yml:
extensions:
- .go
- .py
- .js
- .ts
excludes:
- "vendor/"
- "__pycache__/"
format: ptx
The following are always excluded automatically:
.git/, .hg/, .svn/node_modules/, vendor/, __pycache__/*-lock.json, *.lock, Gemfile.lock, poetry.lock, etc..gitignore patternsTip: Override exclusions with the
-xflag orexcludeslist in your config file.
For comprehensive documentation, visit chain.sh/promptext
Topics covered:
Contributions are welcome! Whether it's bug reports, feature requests, or code contributions, we'd love your help.
# 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 ./...
git checkout -b feature/amazing-feature)go test ./...)git commit -m 'Add amazing feature')git push origin feature/amazing-feature)This project is licensed under the MIT License — see the LICENSE file for details.
Built with ❤️ by the promptext community
658 commits
10 commits
Go
84.0%
Astro
5.9%
Shell
4.3%
PowerShell
2.3%
CSS
1.6%
Makefile
1.3%