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
if [ -f"$rc" ] && grep -q 'CODEFLASH_API_KEY.*cf-'"$rc"2>/dev/null;then
133
-
return 0
134
-
fi
135
-
done
136
-
return 1
137
-
}
138
-
139
-
LOGIN_STEP=""
140
-
if! has_api_key;then
141
-
LOGIN_STEP="
142
-
- Run \`${OAUTH_SCRIPT}\` to log in to Codeflash. If it exits with code 0, the key is saved. If it exits with code 2 (headless environment), parse the JSON output for the \`url\` and \`state_file\`, ask the user to visit the URL and provide the authorization code, then run \`${OAUTH_SCRIPT} --exchange-code <state_file> <code>\` to complete the login."
143
-
fi
144
-
145
114
# Walk from $PWD upward to $REPO_ROOT looking for project config.
if [ "$PROJECT_TYPE"="js" ] && [ "$HAS_JS_CHANGES"="true" ];then
204
-
INSTALL_CMD="npm install --save-dev codeflash"
205
-
206
-
# Check if codeflash npm package is available
207
-
CODEFLASH_INSTALLED="false"
208
-
if (cd "$CHECK_DIR"&& npx codeflash --version >/dev/null 2>&1);then
209
-
CODEFLASH_INSTALLED="true"
210
-
fi
211
-
212
-
# Not configured → prompt for config (+ install if needed)
213
-
if [ "$PROJECT_CONFIGURED"!="true" ];then
214
-
if [ -n"$PROJECT_CONFIG_PATH" ];then
215
-
TARGET_MSG="Add a \`\"codeflash\"\` key to \`$PROJECT_CONFIG_PATH\`"
216
-
else
217
-
TARGET_MSG="Create \`$REPO_ROOT/package.json\` (via \`npm init -y\`) and add a \`\"codeflash\"\` key"
218
-
fi
219
-
220
-
INSTALL_STEP=""
221
-
if [ "$CODEFLASH_INSTALLED"!="true" ];then
222
-
INSTALL_STEP="
223
-
- First, install codeflash by running \`${INSTALL_CMD}\` in \`${CHECK_DIR}\`."
224
-
fi
225
-
226
-
SETUP_MSG="JS/TS files were changed in a recent commit, but codeflash is not configured yet.
227
-
228
-
Set up codeflash to optimize the JavaScript/TypeScript code for performance. Automatically determine the following by exploring the project's actual directory structure using Glob and Read (do NOT present options to the user — discover the correct paths yourself):
229
-
1. The relative path with respect to package.json to the root of the JS/TS module — typically \".\" for the root directory or \"src\".
230
-
2. The relative path with respect to package.json to the tests folder — look for existing directories named \`tests\`, \`test\`, \`__tests__\`, or folders containing files that start with \`test_\` or end with \`.test.js\`/\`.spec.ts\`. If none exist, default to \`tests\`.
231
-
232
-
Once determined:${INSTALL_STEP}
233
-
- If the tests folder does not exist, create it with mkdir -p.
234
-
- ${TARGET_MSG}. Read the existing package.json, parse it, add/update the \"codeflash\" key with the discovered values, and write back with 2-space indentation:
Once the configuration is written, run \`npx codeflash --subagent\` as a non-blocking background Bash task (run_in_background: true) with a 10min timeout."
246
-
247
-
# # Append auto-allow setup instructions if not already configured
248
-
# if [ "$CODEFLASH_AUTO_ALLOWED" != "true" ]; then
249
-
# SETUP_MSG="${SETUP_MSG}
250
-
#
251
-
#Then, add \`Bash(*codeflash*)\` to the \`permissions.allow\` array in \`$SETTINGS_JSON\` (create the file and \`.claude\` directory if they don't exist, and preserve any existing settings). This allows codeflash to run automatically in the background without prompting for permission each time."
INSTALL_MSG="JS/TS files were changed in a recent commit, but the codeflash npm package is not installed.
261
-
262
-
Install codeflash to optimize the JavaScript/TypeScript code for performance by running:
263
-
264
-
${INSTALL_CMD}
265
-
266
-
in \`${CHECK_DIR}\`, then run \`npx codeflash --subagent\` as a non-blocking background Bash task (run_in_background: true) with a 10min timeout."
267
-
268
-
# # Append auto-allow setup instructions if not already configured
269
-
# if [ "$CODEFLASH_AUTO_ALLOWED" != "true" ]; then
270
-
# INSTALL_MSG="${INSTALL_MSG}
271
-
#
272
-
#Then, add \`Bash(*codeflash*)\` to the \`permissions.allow\` array in \`$SETTINGS_JSON\` (create the file and \`.claude\` directory if they don't exist, and preserve any existing settings). This allows codeflash to run automatically in the background without prompting for permission each time."
MESSAGE="JS/TS files were changed in a recent commit. Use the codeflash:optimize skill WITHOUT ANY ARGUMENTS to to optimize the JavaScript/TypeScript code for performance."
287
-
288
-
# # Append auto-allow setup instructions if not already configured
289
-
# if [ "$CODEFLASH_AUTO_ALLOWED" != "true" ]; then
290
-
# MESSAGE="${MESSAGE}
291
-
#
292
-
#Then, add \`Bash(*codeflash*)\` to the \`permissions.allow\` array in \`$SETTINGS_JSON\` (create the file and \`.claude\` directory if they don't exist, and preserve any existing settings). This allows codeflash to run automatically in the background without prompting for permission each time."
# Find codeflash binary: check PATH first, then uv run (Java projects don't use venvs)
304
-
CODEFLASH_BIN=""
305
-
CODEFLASH_INSTALLED="false"
306
-
ifcommand -v codeflash >/dev/null 2>&1;then
307
-
CODEFLASH_BIN="codeflash"
308
-
CODEFLASH_INSTALLED="true"
309
-
elif uv run codeflash --version >/dev/null 2>&1;then
310
-
CODEFLASH_BIN="uv run codeflash"
311
-
CODEFLASH_INSTALLED="true"
312
-
fi
313
-
314
-
# Not installed
315
-
if [ "$CODEFLASH_INSTALLED"!="true" ];then
316
-
INSTALL_MSG="Java files were changed in a recent commit, but codeflash is not installed.
317
-
318
-
Install codeflash to optimize the Java code for performance by running:
319
-
320
-
${INSTALL_CMD}
321
-
322
-
Then run \`codeflash --subagent\` as a non-blocking background Bash task (run_in_background: true) with a 10min timeout."
323
-
324
-
# if [ "$CODEFLASH_AUTO_ALLOWED" != "true" ]; then
325
-
# INSTALL_MSG="${INSTALL_MSG}
326
-
#
327
-
#Then, add \`Bash(*codeflash*)\` to the \`permissions.allow\` array in \`$SETTINGS_JSON\` (create the file and \`.claude\` directory if they don't exist, and preserve any existing settings). This allows codeflash to run automatically in the background without prompting for permission each time."
SETUP_MSG="Java files were changed in a recent commit, but codeflash is not configured yet.
337
-
338
-
Run \`${CODEFLASH_BIN} init --yes\` in \`${CHECK_DIR}\` to automatically detect and configure the Java project, then run \`${CODEFLASH_BIN} --subagent\` as a non-blocking background Bash task (run_in_background: true) with a 10min timeout to optimize the code for performance."
339
-
340
-
# if [ "$CODEFLASH_AUTO_ALLOWED" != "true" ]; then
341
-
# SETUP_MSG="${SETUP_MSG}
342
-
#
343
-
#Then, add \`Bash(*codeflash*)\` to the \`permissions.allow\` array in \`$SETTINGS_JSON\` (create the file and \`.claude\` directory if they don't exist, and preserve any existing settings). This allows codeflash to run automatically in the background without prompting for permission each time."
MESSAGE="Java files were changed in a recent commit. Use the codeflash:optimize skill WITHOUT ANY ARGUMENTS to to optimize the Java code for performance."
358
-
359
-
# if [ "$CODEFLASH_AUTO_ALLOWED" != "true" ]; then
360
-
# MESSAGE="${MESSAGE}
361
-
#
362
-
#Then, add \`Bash(*codeflash*)\` to the \`permissions.allow\` array in \`$SETTINGS_JSON\` (create the file and \`.claude\` directory if they don't exist, and preserve any existing settings). This allows codeflash to run automatically in the background without prompting for permission each time."
363
-
# fi
364
-
161
+
MESSAGE="JS/TS files were changed in a recent commit. Use the codeflash:optimize skill WITHOUT ANY ARGUMENTS to to optimize the JavaScript/TypeScript code for performance. Use npx to execute codeflash"
@@ -371,171 +168,6 @@ if [ "$HAS_PYTHON_CHANGES" != "true" ]; then
371
168
exit 0
372
169
fi
373
170
374
-
INSTALL_CMD="pip install codeflash"
375
-
376
-
# Only use codeflash from the current virtual environment.
377
-
# If no venv is active, try to find and activate one automatically.
378
-
# shellcheck disable=SC1091
379
-
source"$(dirname "$0")/find-venv.sh"
380
-
381
-
if [ -z"${VIRTUAL_ENV:-}" ];then
382
-
# No venv found — instruct Claude to create one, install codeflash, configure, and run
383
-
384
-
# Build config setup instructions if not configured
385
-
PYPROJECT_SETUP=""
386
-
if [ "$PROJECT_CONFIGURED"!="true" ];then
387
-
if [ -n"$PROJECT_CONFIG_PATH" ];then
388
-
TARGET_MSG="Append to \`$PROJECT_CONFIG_PATH\`"
389
-
else
390
-
TARGET_MSG="Create \`$REPO_ROOT/pyproject.toml\`"
391
-
fi
392
-
393
-
PYPROJECT_SETUP="
394
-
3. Automatically determine the following two values by exploring the project's actual directory structure using Glob and Read (do NOT present options to the user — discover the correct paths yourself):
395
-
a. The relative path with respect to pyproject.toml to the root of the Python module — the module root is where tests import from. for example, if the module root is abc/ then the tests would be importing code as \`from abc import xyz\`.
396
-
b. The relative path with respect to pyproject.toml to the tests folder — look for existing directories named \`tests\` or \`test\`, or folders containing files that start with \`test_\`. If none exist, default to \`tests\`.
397
-
398
-
4. Once determined:
399
-
- If the tests folder does not exist, create it with mkdir -p.
400
-
- ${TARGET_MSG} (create the file if it does not exist), adding the following section with the discovered values substituted:
401
-
402
-
[tool.codeflash]
403
-
# All paths are relative to this pyproject.toml's directory.
404
-
module-root = \"<module root>\"
405
-
tests-root = \"<tests folder>\"
406
-
ignore-paths = []
407
-
formatter-cmds = [\"disabled\"]
408
-
409
-
5. Run \`codeflash --subagent\` as a non-blocking background Bash task (run_in_background: true) with a 10min timeout."
410
-
else
411
-
PYPROJECT_SETUP="
412
-
3. Run \`codeflash --subagent\` as a non-blocking background Bash task (run_in_background: true) with a 10min timeout."
413
-
fi
414
-
415
-
# # Build auto-allow setup step if not already configured
416
-
# SETUP_PERMISSIONS_STEP=""
417
-
# if [ "$CODEFLASH_AUTO_ALLOWED" != "true" ]; then
418
-
# SETUP_PERMISSIONS_STEP="
419
-
#Then, add \`Bash(*codeflash*)\` to the \`permissions.allow\` array in \`$SETTINGS_JSON\` (create the file and \`.claude\` directory if they don't exist, and preserve any existing settings). This allows codeflash to run automatically in the background without prompting for permission each time."
420
-
# fi
421
-
422
-
VENV_MSG="Python files were changed in a recent commit, but no Python virtual environment was found.
423
-
424
-
Set up codeflash to optimize the Python code for performance. Perform the following steps:
425
-
${LOGIN_STEP}
426
-
1. Create a virtual environment by running: \`python3 -m venv .venv\` in \`$REPO_ROOT\`, then activate it by running: \`source $REPO_ROOT/.venv/bin/activate\`.
427
-
428
-
2. Install codeflash by running: \`${INSTALL_CMD}\`.
if [ -x"$CODEFLASH_BIN" ] &&"$CODEFLASH_BIN" --version >/dev/null 2>&1;then
441
-
CODEFLASH_INSTALLED="true"
442
-
fi
443
-
444
-
# Check if codeflash is configured in this project
445
-
if [ "$PROJECT_CONFIGURED"!="true" ];then
446
-
# Build a human-friendly target path for the setup message
447
-
if [ -n"$PROJECT_CONFIG_PATH" ];then
448
-
TARGET_MSG="Append to \`$PROJECT_CONFIG_PATH\`"
449
-
else
450
-
TARGET_MSG="Create \`$REPO_ROOT/pyproject.toml\`"
451
-
fi
452
-
453
-
# Include install step if codeflash is not installed
454
-
INSTALL_STEP=""
455
-
if [ "$CODEFLASH_INSTALLED"!="true" ];then
456
-
INSTALL_STEP="
457
-
- First, install codeflash by running \`${INSTALL_CMD}\` in \`${CHECK_DIR}\`."
458
-
fi
459
-
460
-
SETUP_MSG="Python files were changed in a recent commit, but codeflash is not configured yet.
461
-
462
-
Set up codeflash to optimize the Python code for performance:
463
-
${LOGIN_STEP}
464
-
Automatically determine the following by exploring the project's actual directory structure using Glob and Read (do NOT present options to the user — discover the correct paths yourself):
465
-
1. The relative path with respect to pyproject.toml to the root of the Python module — the module root is where tests import from. for example, if the module root is abc/ then the tests would be importing code as \`from abc import xyz\`.
466
-
2. The relative path with respect to pyproject.toml to the tests folder — look for existing directories named \`tests\` or \`test\`, or folders containing files that start with \`test_\`. If none exist, default to \`tests\`.
467
-
468
-
Once determined:${INSTALL_STEP}
469
-
- If the tests folder does not exist, create it with mkdir -p.
470
-
- ${TARGET_MSG} (create the file if it does not exist), adding the following section with the discovered values substituted:
471
-
472
-
[tool.codeflash]
473
-
# All paths are relative to this pyproject.toml's directory.
474
-
module-root = \"<module root>\"
475
-
tests-root = \"<tests folder>\"
476
-
ignore-paths = []
477
-
formatter-cmds = [\"disabled\"]
478
-
479
-
Once the pyproject.toml configuration is written, run \`codeflash --subagent\` as a non-blocking background Bash task (run_in_background: true) with a 10min timeout."
480
-
481
-
# # Append auto-allow setup instructions if not already configured
482
-
# if [ "$CODEFLASH_AUTO_ALLOWED" != "true" ]; then
483
-
# SETUP_MSG="${SETUP_MSG}
484
-
#
485
-
#Then, add \`Bash(*codeflash*)\` to the \`permissions.allow\` array in \`$SETTINGS_JSON\` (create the file and \`.claude\` directory if they don't exist, and preserve any existing settings). This allows codeflash to run automatically in the background without prompting for permission each time."
# Codeflash is configured but not installed in the venv
493
-
if [ "$CODEFLASH_INSTALLED"!="true" ];then
494
-
INSTALL_MSG="Python files were changed in a recent commit, but codeflash is not installed in the active virtual environment (\`$VIRTUAL_ENV\`).
495
-
${LOGIN_STEP}
496
-
Install codeflash to optimize the Python code for performance by running:
497
-
498
-
${INSTALL_CMD}
499
-
500
-
in \`${CHECK_DIR}\`, then run \`codeflash --subagent\` as a non-blocking background Bash task (run_in_background: true) with a 10min timeout."
501
-
502
-
# # Append auto-allow setup instructions if not already configured
503
-
# if [ "$CODEFLASH_AUTO_ALLOWED" != "true" ]; then
504
-
# INSTALL_MSG="${INSTALL_MSG}
505
-
#
506
-
#Then, add \`Bash(*codeflash*)\` to the \`permissions.allow\` array in \`$SETTINGS_JSON\` (create the file and \`.claude\` directory if they don't exist, and preserve any existing settings). This allows codeflash to run automatically in the background without prompting for permission each time."
LOGIN_MSG="Python files were changed in a recent commit, but no Codeflash API key was found.
516
-
517
-
Run \`${OAUTH_SCRIPT}\` to log in to Codeflash. If it exits with code 0, the key is saved. If it exits with code 2 (headless environment), parse the JSON output for the \`url\` and \`state_file\`, ask the user to visit the URL and provide the authorization code, then run \`${OAUTH_SCRIPT} --exchange-code <state_file> <code>\` to complete the login.
518
-
519
-
After login, run \`codeflash --subagent\` as a non-blocking background Bash task (run_in_background: true) with a 10min timeout to optimize the code."
MESSAGE="Python files were changed in a recent commit. Use the codeflash:optimize skill WITHOUT ANY ARGUMENTS to to optimize the Python code for performance."
533
172
534
-
## Append auto-allow setup instructions if not already configured
535
-
#if [ "$CODEFLASH_AUTO_ALLOWED" != "true" ]; then
536
-
# MESSAGE="${MESSAGE}
537
-
#
538
-
#Then, add \`Bash(*codeflash*)\` to the \`permissions.allow\` array in \`$SETTINGS_JSON\` (create the file and \`.claude\` directory if they don't exist, and preserve any existing settings). This allows codeflash to run automatically in the background without prompting for permission each time."
0 commit comments