Coding super-intelligence to find the most optimized Python code. Use it to optimize existing codebases or new Pull requests as a GitHub Action or a VS Code Extension.
Find a file
mohammed ahmed 8705d5e5f7
Some checks are pending
Claude Code / pr-review (pull_request) Waiting to run
Claude Code / claude-mention (pull_request) Waiting to run
CodeFlash / Optimize new Python code (pull_request) Waiting to run
E2E - Async / async-optimization (pull_request) Waiting to run
E2E - Bubble Sort Benchmark / benchmark-bubble-sort-optimization (pull_request) Waiting to run
E2E - Bubble Sort Pytest (No Git) / bubble-sort-optimization-pytest-no-git (pull_request) Waiting to run
E2E - Bubble Sort Unittest / bubble-sort-optimization-unittest (pull_request) Waiting to run
Coverage E2E / end-to-end-test-coverage (pull_request) Waiting to run
E2E - Futurehouse Structure / futurehouse-structure (pull_request) Waiting to run
E2E - Init Optimization / init-optimization (pull_request) Waiting to run
E2E - Java Fibonacci (No Git) / java-fibonacci-optimization-no-git (pull_request) Waiting to run
E2E - Java Tracer / java-tracer-e2e (pull_request) Waiting to run
E2E - JS CommonJS Function / js-cjs-function-optimization (pull_request) Waiting to run
E2E - JS ESM Async / js-esm-async-optimization (pull_request) Waiting to run
E2E - JS TypeScript Class / js-ts-class-optimization (pull_request) Waiting to run
E2E - Topological Sort (Worktree) / topological-sort-worktree-optimization (pull_request) Waiting to run
E2E - Tracer Replay / tracer-replay (pull_request) Waiting to run
Java E2E Tests / java-e2e (pull_request) Waiting to run
PR Labeler / label-workflow-changes (pull_request) Waiting to run
Mypy Type Checking for CLI / type-check-cli (pull_request) Waiting to run
Lint / prek (pull_request) Waiting to run
unit-tests / unit-tests (ubuntu-latest, 3.10) (pull_request) Waiting to run
unit-tests / unit-tests (ubuntu-latest, 3.11) (pull_request) Waiting to run
unit-tests / unit-tests (ubuntu-latest, 3.12) (pull_request) Waiting to run
unit-tests / unit-tests (ubuntu-latest, 3.13) (pull_request) Waiting to run
unit-tests / unit-tests (ubuntu-latest, 3.14) (pull_request) Waiting to run
unit-tests / unit-tests (ubuntu-latest, 3.9) (pull_request) Waiting to run
unit-tests / unit-tests (windows-latest, 3.13) (pull_request) Waiting to run
Fix: Always disable Jest globalSetup/globalTeardown for Codeflash tests
## Problem
When test files were inside the project root (common case), Codeflash did NOT
create the runtime config that disables globalSetup/globalTeardown. This caused
Jest to use the project's original config WITH globalSetup, leading to failures
when globalSetup required unavailable infrastructure (Docker, databases, etc.):

    Error: Jest: Got error running globalSetup - /workspace/target/globalSetup.ts,
    reason: Command failed: docker context ls --format json
    /bin/sh: 1: docker: not found

## Root Cause
Runtime config was only created when tests were OUTSIDE project root:

    if any(not Path(d).is_relative_to(resolved_root) for d in test_dirs):
        jest_config = _create_runtime_jest_config(...)

But globalSetup should be disabled for ALL Codeflash test runs.

## Solution
Always create runtime config when `jest_config` and `test_files` exist:

    if test_files and jest_config:
        test_dirs = {str(Path(f).resolve().parent) for f in test_files}
        jest_config = _create_runtime_jest_config(jest_config, effective_cwd, test_dirs)

## Impact
- Affected: ALL projects with globalSetup/globalTeardown in Jest config
- Reproducibility: 100% systematic
- Example trace: 04dc4dcf-ca9f-449e-aed5-7a82f28c5e23

## Changes
- test_runner.py: Updated 3 functions (behavioral, benchmarking, line profiling)
- New test file: test_globalsetup_invocation_bug.py (3 test cases)
- All existing tests still pass

Fixes #18

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-04-06 16:41:36 +00:00
.claude fix: make post-edit lint hook surface real errors 2026-03-27 18:01:16 -05:00
.codex chore: update tessl agent config files 2026-02-18 20:23:23 -05:00
.gemini chore: update tessl agent config files 2026-02-18 20:23:23 -05:00
.github Merge branch 'main' into java-config-redesign 2026-03-27 14:10:00 +02:00
code_to_optimize fix: update codeflash-runtime version in test fixture pom.xml files 2026-04-01 23:13:37 +00:00
codeflash Fix: Always disable Jest globalSetup/globalTeardown for Codeflash tests 2026-04-06 16:41:36 +00:00
codeflash-benchmark Merge commit '6346c740' into sync-main-batch-4 2026-02-19 21:26:23 -05:00
codeflash-java-runtime chore: bump codeflash-java-runtime version to 1.0.1 2026-04-01 22:33:47 +00:00
docs Merge pull request #1948 from codeflash-ai/docs/codeflash-installation-for-js-and-ts 2026-04-02 14:10:34 +05:30
experiments fix: lint issues in experiments folder and format fixes 2026-01-29 19:26:50 +05:30
packages/codeflash Merge pull request #1899 from codeflash-ai/cf-fix-v8-serializer-cross-context 2026-03-26 23:52:17 +05:30
tests Fix: Always disable Jest globalSetup/globalTeardown for Codeflash tests 2026-04-06 16:41:36 +00:00
.gitignore feat: add Claude Code post-edit lint hook using prek 2026-03-27 08:25:36 -05:00
.mcp.json Add MCP config for .mcp.json 2026-02-15 00:20:41 +00:00
.pre-commit-config.yaml chore: bump ruff-pre-commit to v0.15.8 and update lockfile 2026-03-27 09:06:42 -05:00
CLAUDE.md chore: reorganize Claude rules and add workflow guidelines 2026-03-27 09:43:53 -05:00
codeflash.code-workspace improve codeflash debugging 2025-06-26 15:00:35 -07:00
LICENSE fix: update license format to use license-files 2026-02-17 05:54:21 +00:00
mypy_allowlist.txt fix: remove deleted cli_common.py from mypy_allowlist.txt 2026-03-17 08:18:45 +00:00
pyproject.toml feat: add --memory flag to codeflash compare for peak memory profiling 2026-04-02 10:29:31 -05:00
README.md release/v0.17.0 (#756) 2025-09-23 14:02:30 -07:00
SECURITY.md Create SECURITY.md 2025-08-06 18:50:57 -07:00
tessl.json chore: update tessl tiles and upgrade dependencies 2026-02-18 20:23:23 -05:00
uv.lock feat: add --memory flag to codeflash compare for peak memory profiling 2026-04-02 10:29:31 -05:00

Codeflash-banner

GitHub commit activity PyPI Downloads PyPI Downloads

Codeflash is a general purpose optimizer for Python that helps you improve the performance of your Python code while maintaining its correctness. It uses advanced LLMs to generate multiple optimization ideas for your code, tests them to be correct and benchmarks them for performance. It then creates merge-ready pull requests containing the best optimization found, which you can review and merge.

How to use Codeflash -

  • Optimize an entire existing codebase by running codeflash --all
  • Automate optimizing all future code you will write by installing Codeflash as a GitHub action.
  • Optimize a Python workflow python myscript.py end-to-end by running codeflash optimize myscript.py

Codeflash is used by top engineering teams at Pydantic (PRs Merged), Roboflow (PRs Merged 1, PRs Merged 2), Unstructured (PRs Merged 1, PRs Merged 2), Langflow (PRs Merged) and many others to ship performant, expert level code.

Codeflash is great at optimizing AI Agents, Computer Vision algorithms, PyTorch code, numerical code, backend code or anything else you might write with Python.

Installation

To install Codeflash, run:

pip install codeflash

Add codeflash as a development time dependency if you are using package managers like uv or poetry.

Quick Start

  1. To configure Codeflash for a project, at the root directory of your project where the pyproject.toml file is located, run:

    codeflash init
    
    • It will ask you a few questions about your project like the location of your code and tests
    • Ask you to generate an API Key to access Codeflash's LLMs
    • Install a GitHub app to open Pull Requests on GitHub.
    • Ask if you want to setup a GitHub actions which will optimize all your future code.
    • The codeflash config is then saved in the pyproject.toml file.
  2. Optimize your entire codebase:

    codeflash --all
    

    This can take a while to run for a large codebase, but it will keep opening PRs as it finds optimizations.

  3. Optimize a script:

    codeflash optimize myscript.py
    

Documentation

For detailed installation and usage instructions, visit our documentation at docs.codeflash.ai

Demo

  • Optimizing the performance of new code for a Pull Request through GitHub Actions. This lets you ship code quickly while ensuring it remains performant.

https://github.com/user-attachments/assets/38f44f4e-be1c-4f84-8db9-63d5ee3e61e5

  • Optiming a workflow end to end automatically with codeflash optimize

https://github.com/user-attachments/assets/355ba295-eb5a-453a-8968-7fb35c70d16c

Support

Join our community for support and discussions. If you have any questions, feel free to reach out to us using one of the following methods:

License

Codeflash is licensed under the BSL-1.1 License. See the LICENSE file for details.