You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,12 @@
1
1
# Codeflash Claude Code Plugin
2
2
3
-
A minimal Claude Code plugin that runs [Codeflash](https://codeflash.ai) as a background agent to optimize Python code for performance.
3
+
A minimal Claude Code plugin that runs [Codeflash](https://codeflash.ai) as a background agent to optimize Python, JavaScript, and TypeScript code for performance.
4
4
5
5
## Prerequisites
6
6
7
7
- Claude Code v2.1.38 or later
8
-
-[codeflash](https://pypi.org/project/codeflash/) installed in your project
9
-
-Project initialized with `codeflash init` (creates `[tool.codeflash]`in `pyproject.toml`)
8
+
-**Python projects**: [codeflash](https://pypi.org/project/codeflash/) installed in a virtual environment, configured via `[tool.codeflash]` in `pyproject.toml`
9
+
-**JS/TS projects**: [codeflash](https://www.npmjs.com/package/codeflash) installed as a dev dependency (`npm install --save-dev codeflash`), configured via a `"codeflash"` key in `package.json`
10
10
11
11
## Installation
12
12
@@ -69,7 +69,7 @@ Run `/plugin` to open the plugin manager and confirm codeflash appears under the
69
69
70
70
### Auto-suggest after commits
71
71
72
-
When you make a git commit that includes Python file changes, the plugin suggests running `/optimize` on those files.
72
+
When you make a git commit that includes Python, JavaScript, or TypeScript file changes, the plugin suggests running `/optimize` on those files.
73
73
74
74
## Plugin Structure
75
75
@@ -84,7 +84,7 @@ codeflash-cc-plugin/
84
84
│ └── hooks.json # Stop hook for commit detection
85
85
├── scripts/
86
86
│ ├── find-venv.sh # Shared helper: find and activate a Python venv
Copy file name to clipboardExpand all lines: agents/optimizer.md
+114-9Lines changed: 114 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
name: optimizer
3
3
description: |
4
-
Optimizes Python code for performance using Codeflash. Use when asked to optimize, speed up, or improve performance of Pythoncode. Also triggered automatically after commits that change Python files.
4
+
Optimizes Python and JavaScript/TypeScript code for performance using Codeflash. Use when asked to optimize, speed up, or improve performance of Python, JavaScript, or TypeScript code. Also triggered automatically after commits that change Python/JS/TS files.
5
5
6
6
<example>
7
7
Context: User explicitly asks to optimize code
@@ -21,6 +21,24 @@ description: |
21
21
</commentary>
22
22
</example>
23
23
24
+
<example>
25
+
Context: User explicitly asks to optimize JS/TS code
26
+
user: "Optimize src/utils.ts for performance"
27
+
assistant: "I'll use the optimizer agent to run codeflash on that file."
28
+
<commentary>
29
+
Direct optimization request for a TypeScript file — trigger the optimizer agent with the file path.
30
+
</commentary>
31
+
</example>
32
+
33
+
<example>
34
+
Context: User wants to speed up a JS/TS function
35
+
user: "Can you make the parseData function in src/parser.js faster?"
36
+
assistant: "I'll use the optimizer agent to optimize that function with codeflash."
37
+
<commentary>
38
+
Performance improvement request targeting a specific JS function — trigger with file and function name.
39
+
</commentary>
40
+
</example>
41
+
24
42
<example>
25
43
Context: Hook detected Python files changed in a commit
26
44
user: "Python files were changed in the latest commit. Use the Task tool to optimize..."
@@ -36,7 +54,7 @@ color: cyan
36
54
tools: Read, Glob, Grep, Bash, Write, Edit
37
55
---
38
56
39
-
You are a thin-wrapper agent that runs the codeflash CLI to optimize Python code.
57
+
You are a thin-wrapper agent that runs the codeflash CLI to optimize Python and JavaScript/TypeScript code.
Walk upward from the current working directory to the git repository root (`git rev-parse --show-toplevel`) looking for `pyproject.toml`. Use the **first** (closest to CWD) file found. Record:
143
-
-**Project directory**: the directory containing the discovered `pyproject.toml`
144
-
-**Configured**: whether the file contains a `[tool.codeflash]` section
160
+
Walk upward from the current working directory to the git repository root (`git rev-parse --show-toplevel`) looking for a project configuration file. Check for both `pyproject.toml` (Python) and `package.json` (JavaScript/TypeScript) at each directory level. Use the **first** (closest to CWD) file found.
161
+
162
+
**Determine the project type:**
163
+
- If `pyproject.toml` is found first → **Python project**. Record:
164
+
-**Project directory**: the directory containing `pyproject.toml`
165
+
-**Configured**: whether the file contains a `[tool.codeflash]` section
166
+
- If `package.json` is found first → **JS/TS project**. Record:
167
+
-**Project directory**: the directory containing `package.json`
168
+
-**Configured**: whether the JSON has a `"codeflash"` key at the root level
169
+
- If both exist in the same directory, determine the project type from the file being optimized (`.py` → Python, `.js`/`.ts`/`.jsx`/`.tsx` → JS/TS). If ambiguous, prefer `pyproject.toml`.
170
+
171
+
If neither file is found, use the git repository root as the project directory.
145
172
146
-
If no `pyproject.toml` is found, use the git repository root as the project directory.
173
+
### 2. Verify Environment and Installation
147
174
148
-
### 2. Verify Virtual Environment and Installation
175
+
The verification process depends on the project type determined in Step 1.
176
+
177
+
#### 2a. Python projects
149
178
150
179
First, check that a Python virtual environment is active by running `echo $VIRTUAL_ENV`.
151
180
@@ -182,8 +211,30 @@ pip install codeflash
182
211
183
212
If the user agrees, run the installation command in the project directory. If installation succeeds, proceed to Step 3. If the user declines or installation fails, stop.
184
213
214
+
#### 2b. JS/TS projects
215
+
216
+
Check whether the `codeflash` npm package is installed in the project by running:
217
+
218
+
```bash
219
+
npx codeflash --version
220
+
```
221
+
222
+
If it succeeds, proceed to Step 3.
223
+
224
+
If it fails (command not found or package not available), codeflash is not installed. Ask the user whether they'd like to install it now:
225
+
226
+
```bash
227
+
npm install --save-dev codeflash
228
+
```
229
+
230
+
If the user agrees, run the installation command in the project directory (from Step 1). If installation succeeds, proceed to Step 3. If the user declines or installation fails, stop.
231
+
185
232
### 3. Verify Setup
186
233
234
+
The setup process depends on the project type determined in Step 1.
235
+
236
+
#### 3a. Python projects (`pyproject.toml`)
237
+
187
238
Use the `pyproject.toml` discovered in Step 1:
188
239
189
240
-**If `[tool.codeflash]` is already present** → check the formatter (see sub-step 5 below), then proceed to Step 4.
5.**Verify formatter**: Read the `formatter-cmds` value from the `[tool.codeflash]` section. If it is set to `["disabled"]` or is empty, skip this check. Otherwise, for each command in the `formatter-cmds` list, extract the base command name (the first word, e.g. `black` from `"black --line-length 88 {file}"`) and run `which <command>` to check if it is installed. If any formatter command is **not found**, inform the user which formatter(s) are missing and ask if they'd like to install them (e.g. `pip install <formatter>`). If the user agrees, run the install. If the user declines, warn that codeflash may fail to format optimized code and proceed to Step 4 anyway.
215
266
267
+
#### 3b. JS/TS projects (`package.json`)
268
+
269
+
Use the `package.json` discovered in Step 1:
270
+
271
+
-**If a `"codeflash"` key already exists at the root of the JSON** → check the formatter (see sub-step 5 below), then proceed to Step 4.
272
+
-**If `package.json` exists but has no `"codeflash"` key** → add the config to that file.
273
+
-**If no `package.json` was found** → create one at the git repository root with `npm init -y`, then add the config.
274
+
275
+
When configuration is missing, interactively set it up:
276
+
277
+
1.**Ask the user two questions** (use AskUserQuestion or prompt directly):
278
+
-**Module root**: "What is the relative path to the root of your JavaScript/TypeScript module?" (e.g. `.` for the root directory, `src`, `src/lib`)
279
+
-**Tests folder**: "What is the relative path to your tests folder?" (e.g. `tests`, `test`, `__tests__`, `src/__tests__`)
280
+
281
+
2.**Validate directories**: Check whether the tests folder the user provided exists. If it does **not** exist, create it with `mkdir -p`.
282
+
283
+
3.**Write the configuration**: Read the existing `package.json`, parse it as JSON, add a `"codeflash"` key at the root level, and write the file back. Use exactly this structure, substituting the user's answers:
**Important**: When writing to `package.json`, you must preserve all existing content. Read the file, parse the JSON, add/update only the `"codeflash"` key, then write the full JSON back with 2-space indentation.
297
+
298
+
4. Confirm to the user that the configuration has been written.
299
+
300
+
5.**Verify formatter**: Read the `formatterCmds` value from the `"codeflash"` config. If it is set to `["disabled"]` or is empty, skip this check. Otherwise, for each command in the `formatterCmds` array, extract the base command name (the first word, ignoring `npx` — e.g. `prettier` from `"npx prettier --write {file}"`). If the command is invoked via `npx`, check that the package is available with `npx <command> --version`. If invoked directly, run `which <command>`. If any formatter command is **not found**, inform the user which formatter(s) are missing and ask if they'd like to install them (e.g. `npm install --save-dev <formatter>`). If the user agrees, run the install. If the user declines, warn that codeflash may fail to format optimized code and proceed to Step 4 anyway.
301
+
216
302
Then proceed to Step 4.
217
303
218
304
### 4. Parse Task Prompt
219
305
220
306
Extract from the prompt you receive:
221
-
-**file path**: Python file to optimize (e.g. `src/utils.py`)
307
+
-**file path**: file to optimize (e.g. `src/utils.py`, `src/utils.ts`)
222
308
-**function name**: Specific function to target (optional)
223
309
- Any other flags: pass through to codeflash
224
310
225
311
If no file and no `--all` flag, run codeflash without `--file` or `--all` to let it detect changed files automatically. Only use `--all` when explicitly requested.
226
312
227
313
### 5. Run Codeflash
228
314
229
-
If the project directoryfrom Step 1 differs from the current working directory, **`cd` to the project directory first** so that relative paths in the config resolve correctly.
315
+
**Always `cd` to the project directory** (from Step 1) before running codeflash, so that relative paths in the config resolve correctly.
230
316
231
317
Execute the appropriate command **in the background** (`run_in_background: true`) with a **10-minute timeout** (`timeout: 600000`):
If CWD is already the project directory, omit the `cd`. Always include the `source $VIRTUAL_ENV/bin/activate` prefix to ensure the virtual environment is active in the shell that runs codeflash.
245
333
334
+
#### JS/TS projects
335
+
336
+
**Important**: Codeflash must always be run from the project root (the directory containing `package.json`).
If CWD is already the project directory, omit the `cd`. Use `npx codeflash` (no virtual environment activation needed).
350
+
246
351
**IMPORTANT**: Always use `run_in_background: true` when calling the Bash tool to execute codeflash. This allows optimization to run in the background while Claude continues other work. Tell the user "Codeflash is optimizing in the background, you'll be notified when it completes" and do not wait for the result.
0 commit comments