4.2 KiB
Codeflash Installation Guide
I need to install and configure Codeflash for my project to enable AI-powered performance optimization.
Objective
Install Codeflash CLI and configure it for either Python or JavaScript/TypeScript project with proper test data serialization and GitHub integration.
Success Condition
Codeflash is successfully installed, configured with API key, connected to GitHub, and can run optimization commands without errors.
TODO
- Install Codeflash CLI for your language
- Run initialization and configuration
- Generate and configure API key
- Install GitHub App
- Verify installation
Installation Steps
For Python Projects
Prerequisites:
- Python 3.9 or above
- Virtual environment activated
- Project dependencies installed
Commands:
# Activate virtual environment
source venv/bin/activate # Linux/Mac
# or
venv\Scripts\activate # Windows
# Install Codeflash
pip install codeflash
# Or as dev dependency with modern tools
uv add --dev codeflash
# or
poetry add codeflash@latest --group dev
# Initialize configuration
cd /path/to/project/root
codeflash init
Configuration prompts:
- Enter Codeflash API key
- Specify Python module to optimize (e.g.,
my_module) - Specify test location (e.g.,
tests/) - Select code formatter (black/ruff/other/disabled)
- Select git remote for PRs
- Opt-in to anonymous usage data
- Install GitHub app
- Install GitHub actions
For JavaScript/TypeScript Projects
Prerequisites:
- Node.js 16 or above
- Package manager (npm/yarn/pnpm/bun)
- Project dependencies installed
Commands:
# Verify Node.js version
node --version # Should be v16.0.0+
# Install Codeflash as dev dependency
npm install --save-dev codeflash
# or
yarn add --dev codeflash
# or
pnpm add --save-dev codeflash
# or
bun add --dev codeflash
# Or install globally
npm install -g codeflash
# Initialize configuration
cd /path/to/project/root
codeflash init
Configuration prompts:
- Enter Codeflash API key
- Specify JavaScript/TypeScript module (e.g.,
src/) - Specify test location (e.g.,
tests/,__tests__/,*.test.js) - Select test framework (jest/vitest/mocha/ava/other)
- Select code formatter (prettier/eslint/biome/disabled)
- Select git remote for PRs
- Opt-in to anonymous usage data
- Install GitHub app
- Install GitHub actions
Serialization Strategy: JavaScript/TypeScript projects use V8 serialization automatically for optimal test data capture:
- Binary storage format
- Perfect type preservation (Date, Map, Set, TypedArrays, BigInt, etc.)
- 2-3x faster than alternatives
- Framework agnostic (React, Vue, Angular, Svelte, etc.)
API Key Generation
Steps:
- Visit https://app.codeflash.ai/
- Sign up with GitHub account (free tier available)
- Navigate to https://app.codeflash.ai/app/apikeys
- Generate new API key
- Copy and paste when prompted during
codeflash init
GitHub App Installation
Steps:
- Visit https://github.com/apps/codeflash-ai/installations/select_target
- Select the repository to install Codeflash
- Grant necessary permissions
- Confirm installation
Verification
Test the installation:
# Python - Optimize single function
codeflash --file path/to/file.py --function function_name
# JavaScript/TypeScript - Optimize single function
codeflash --file path/to/file.js --function functionName
# Optimize entire codebase (both languages)
codeflash --all
# Verbose output for debugging
codeflash optimize --verbose
Configuration Files
Python:
- Configuration stored in
pyproject.toml - Serialization: SQLite + pickle
JavaScript/TypeScript:
- Configuration stored in
codeflash.config.js - Serialization: V8 binary format
Framework Support
Python:
- All Python projects with pytest, unittest, or similar
JavaScript/TypeScript:
- Frontend: React, Vue, Angular, Svelte, Solid.js
- Backend: Express, NestJS, Fastify, Koa, Hono
- Testing: Jest, Vitest, Mocha, AVA, Playwright, Cypress
- Runtimes: Node.js (✅ Recommended), Bun/Deno (Coming soon)
Execute Installation
Run the commands above for your specific language and answer the configuration prompts to complete Codeflash installation.