# Custom Run Functionality - Claude Code CLI Integration Update

## Summary

The custom run functionality has been updated to work with the current Claude Code CLI approach instead of the deprecated `llm_setup_helper.py`. This ensures that custom runs receive the same intelligent setup assistance as standard runs, but with awareness of the specific custom configuration requirements.

## Changes Made

### 1. Enhanced Claude Code CLI Prompts (`scripts/run_optimization.sh`)

**Added Custom Run Context to Claude Prompts:**

- Added `{CUSTOM_RUN_CONTEXT}` placeholder to the Claude setup prompt template
- Implemented dynamic custom run context generation based on optimization mode
- Added mode-specific guidance for single function, trace & optimize, and optimize all modes
- Included custom configuration details (module root, tests root, flags, etc.)
- Added setup requirements specific to each optimization mode

**Custom Run Context Includes:**

- Optimization mode and configuration details
- Mode-specific targets (file/function, script, directory)
- Custom flags and settings
- Setup requirements and focus areas
- Dependency requirements (e.g., codeflash[asyncio] for async mode)

### 2. Removed Deprecated LLM Setup Helper (`server/app.py`)

**Removed Upload of Deprecated Script:**

- Removed upload of `llm_setup_helper.py` from `_complete_instance_setup` function
- Added comment explaining that the script is deprecated
- Maintained all other script uploads (run_optimization.sh, detect_roots.py)

### 3. Updated Documentation

**README.md:**

- Updated description of `llm_setup_helper.py` to indicate it's deprecated
- Clarified that Claude Code CLI is now used directly in `run_optimization.sh`

**docs/CUSTOM_RUN.md:**

- Added new section on Claude Code CLI Integration
- Updated implementation details to reflect Claude Code CLI integration
- Added information about enhanced prompts and mode-specific guidance

## How It Works Now

### 1. Custom Run Detection

When a custom run is executed, the `run_optimization.sh` script detects the custom run mode and loads the custom configuration.

### 2. Claude Code CLI Enhancement

The script enhances the Claude Code CLI prompt with custom run context, including:

- Optimization mode and configuration
- Mode-specific targets and requirements
- Custom settings and flags
- Setup requirements for the specific optimization mode

### 3. Intelligent Setup Assistance

Claude Code CLI receives the enhanced prompt and provides intelligent setup assistance that is:

- Aware of the specific optimization mode
- Focused on the target files/functions/scripts
- Configured for the custom settings
- Optimized for the specific optimization requirements

### 4. Execution

After setup is complete, the script executes the appropriate Codeflash command with the custom configuration.

## Benefits

1. **Consistent Experience**: Custom runs now have the same intelligent setup assistance as standard runs
2. **Mode-Aware Setup**: Claude understands the specific requirements for each optimization mode
3. **Target-Focused**: Claude can focus on the specific files, functions, or scripts being optimized
4. **Configuration-Aware**: Claude knows about custom settings and can ensure they're properly configured
5. **Dependency Management**: Claude ensures all required dependencies are installed for the specific optimization mode

## Example Custom Run Context

For a single function optimization, Claude receives context like:

```
### Custom Optimization Configuration
- **Optimization Mode**: single_function
- **Custom Module Root**: src
- **Custom Tests Root**: tests
- **Async Mode**: true
- **Verbose Output**: true

### Mode-Specific Targets
- **Target File**: src/calculations.py
- **Target Function**: calculate_fibonacci
- **Focus**: Ensure the target function's dependencies are properly installed
- **Note**: This is a single function optimization targeting a specific function in a specific file

### Custom Run Setup Requirements
- Pay special attention to any custom configuration requirements for this optimization mode
- Ensure codeflash[asyncio] is installed if async mode is enabled
- Verify that all target files/scripts exist and are accessible
- Install any additional dependencies needed for the specific optimization mode
- Ensure the custom module root and tests root are properly configured
```

This ensures that Claude provides targeted, intelligent setup assistance that is perfectly aligned with the custom run requirements.
