CPE is a powerful command-line tool that enables developers to leverage AI for codebase analysis, modification, and improvement through natural language interactions. It supports multiple programming languages and seamlessly integrates with your development workflow through standard Unix pipes and redirection.
- Multi-Language Support: Analyzes and modifies code in multiple programming languages including Go, Java, Python, and more
- Automatically identifies and selects relevant files for analysis using Tree-sitter (For supported languages)
- Token counting and visualization to understand and pinpoint large files
- Powerful File Operations:
- Analyze existing code
- Modify files with precision
- Create new files
- Remove files
- Multiple LLM Providers:
- Anthropic
- OpenAI (or any OpenAI-like API)
- Flexible Input/Output:
- Accept input from stdin or file
- Pipe results to other commands
- Integrates naturally with Unix tools
- Highly Configurable Generation:
- Choice of AI model
- Adjustable generation parameters
- Customizable file ignore patterns
To install CPE, make sure you have Go 1.22 or later installed on your system. Then, run the following command:
go install github.com/spachava753/cpe@latest
If no -model
flag is provided, Clause Sonnet 3.5 is used by default. To use CPE, run the following command:
cpe [flags] < input.txt
or
cpe [flags] -input input.txt
or
echo "Hi!" | cpe [flags]
-
Quick code analysis:
echo "What does main.go do?" | cpe
-
Using a specific model:
cpe -model claude-3-opus -input query.txt
-
Pipe git diff for review:
echo "git diff:\n\n$(git diff)\n\nReview these changes and suggest improvements" | cpe -model gpt-4o
-
Analyze code coverage report:
go test -coverprofile=coverage.out ./... echo "$(go tool cover -func=coverage.out)\n\nAnalyze this coverage report and suggest areas needing more tests" | cpe
-
Token counting for project analysis:
cpe -token-count ./src
-
Configuring generation parameters:
cpe -model gpt-4o -temperature 0.8 -top-p 0.9 -frequency-penalty 0.5 < prompt.txt
-
Custom API endpoint:
cpe -model gemini-1.5-pro -custom-url https://custom-endpoint.com/v1 < query.txt
-
Version information:
cpe -version
To use specific LLM providers, set the corresponding API keys:
- Anthropic:
ANTHROPIC_API_KEY
- Google:
GEMINI_API_KEY
- OpenAI:
OPENAI_API_KEY
CPE uses a .cpeignore
file to specify patterns for files and directories that should be ignored when executing (
Helpful to exclude large generated files). The file follows .gitignore
syntax:
# Example .cpeignore
node_modules/
*.log
build/
dist/
.git/
CPE includes a token counting feature to help you understand your codebase's size and complexity:
# Count tokens in the entire project
cpe -token-count .
# Count tokens in a specific directory
cpe -token-count ./src
# Count tokens in specific file types
find . -name "*.go" | xargs cpe -token-count
The token count visualization shows:
- Total tokens per file
- Directory summaries
- Token distribution across the codebase
CPE can perform the following file operations based on model tool calls:
- Modify Files: Update existing file content with precise replacements
- Create Files: Generate new files with specified content
- Remove Files: Delete existing files when necessary
All file operations:
- Are validated before execution
- Require explicit content or paths
- Are logged for transparency
This project is licensed under the MIT License.