- Codeflash can optimize new java code written in a Pull Request through Github Actions.
- Codeflash can optimize real workloads end to end. It uses a two-stage tracing approach to capture method arguments and profiling data from running Java program, then optimizes the hottest functions with that data.
Prerequisites
Before installing Codeflash, ensure you have:- Java 11 or above installed
- Maven or Gradle as your build tool
- A Java project with source code under a standard directory layout
- Unit tests (JUnit 5 or JUnit 4) — Codeflash uses them alongside traced replay tests to verify correctness
Install Codeflash CLI
Codeflash uses Python to run its CLI. You can use uv as a package manager and installer for Python programs.
To install uv, run the following or see these instructionsThen install Codeflash as a uv tool.
Authenticate with Codeflash
Codeflash uses cloud-hosted AI models. You need to authenticate before running any commands.Option A: Browser login (recommended)This opens your browser to sign in with your GitHub account. Your API key is saved automatically to your shell profile.If you’re on a remote server without a browser, a URL will be displayed that you can open on any device.Option B: API keyAdd this to your shell profile (
- Visit the Codeflash Web App and sign up with your GitHub account (free tier available)
- Navigate to the API Key page to generate your key
- Set it as an environment variable:
~/.bashrc, ~/.zshrc) so it persists across sessions.If you skip this step,
codeflash init will prompt you to authenticate interactively.Initialize your project (recommended)
Navigate to your Java project root (where The init command will:
pom.xml or build.gradle is) and run:- Auto-detect your project — find your build tool, source root (e.g.,
src/main/java), test root (e.g.,src/test/java), and test framework - Confirm settings — show the detected values and ask if you want to change anything
- Configure formatter — let you set up a code formatter (e.g., Spotless, google-java-format)
- Install GitHub App — offer to set up the Codeflash GitHub App for automatic PR creation (see next step)
- Install GitHub Actions — offer to add a CI workflow for automated optimization on PRs
pom.xml properties (Maven) or gradle.properties (Gradle). For standard layouts, no config changes are needed.Can I skip init? Yes. For standard Maven/Gradle projects, Codeflash auto-detects your project structure from
pom.xml or build.gradle at runtime. If you’re already authenticated and your project uses a standard layout (src/main/java, src/test/java), you can skip straight to optimizing.Init is recommended because it also sets up the GitHub App and Actions workflow, and lets you override paths for non-standard project layouts (e.g., multi-module projects where source is under client/src/).Install the Codeflash GitHub App (recommended)
To have Codeflash create pull requests with optimizations automatically, install the GitHub App:Install Codeflash GitHub AppSelect the repositories you want Codeflash to optimize. This allows the codeflash-ai bot to open PRs with optimization suggestions in your repository.
If you prefer to try Codeflash locally first, you can skip this step and use the
--no-pr flag to apply optimizations directly to your local files (see next step).Run your first optimization
Optimize a specific function:If you installed the GitHub App, Codeflash will create a pull request with the optimization. If you haven’t installed the app yet, or prefer to review changes locally first, add Or optimize all functions in your project:Codeflash will:
--no-pr:- Discover optimizable functions in your source code
- Generate tests and optimization candidates using AI
- Verify correctness by running tests (JUnit 5, JUnit 4, or TestNG)
- Benchmark performance improvements
- Create a pull request with the optimization (or apply locally with
--no-pr)
Supported build tools
| Build Tool | Detection | Test Execution |
|---|---|---|
| Maven | pom.xml | Maven Surefire plugin |
| Gradle | build.gradle / build.gradle.kts | Gradle test task |
Supported test frameworks
| Framework | Support Level |
|---|---|
| JUnit 5 | Full support (default) |
| JUnit 4 | Full support |
| TestNG | Basic support |