Phase 2: Claude Code Integration
Enable autonomous decision-making during workflow replay via Claude Code API integration.
Goals
- Prompt handling: Claude Code makes decisions when workflow encounters prompts
- Error recovery: Automatic retry, adaptation, or graceful failure
- UI adaptation: Handle UI changes that break exact replay
- Background execution: Run workflows without user intervention
Tasks
1. ClaudeCodeIntegration Class
API Design:
class ClaudeCodeIntegration:
def handle_prompt(
self,
prompt: str,
context: dict,
screenshot: Image.Image | None = None
) -> str:
"""Ask Claude Code what to do when encountering a prompt."""
pass
def handle_error(
self,
error: Exception,
context: dict
) -> Action:
"""Propose fix for error: retry, skip, or abort."""
pass
def adapt_action(
self,
original_action: Action,
current_screenshot: Image.Image
) -> Action:
"""Adapt action coordinates if UI has changed."""
pass
2. Integrate with WorkflowExecutor
Files: workflows/base.py
3. Prompt Handling
Scenarios:
- File save dialog: "What filename should I use?"
- Confirmation dialog: "Should I proceed?"
- Dropdown menu: "Which option should I select?"
Implementation:
- Capture screenshot when prompt detected
- Send to Claude Code with context
- Parse response into action
- Execute action
Files: playback/claude_code_integration.py, playback/executor.py
4. Error Recovery
Error types:
- Element not found (UI changed)
- Timeout waiting for element
- Unexpected dialog/popup
- File/directory not found
Recovery strategies:
- Retry: Try action again with backoff
- Adapt: Use vision to find similar element
- Skip: Continue without action (if non-critical)
- Abort: Fail gracefully with detailed error
Files: playback/error_recovery.py
5. UI Adaptation
Challenge: Recorded actions use exact coordinates, which break if UI changes
Solution: Use vision models to locate UI elements
- Extract element description from original recording
- Use Claude Code vision to find element in current screenshot
- Translate to new coordinates
- Execute adapted action
Example:
Original: CLICK(x=500, y=300) on "Save button"
Current UI: Save button moved to (x=550, y=320)
Adapted: CLICK(x=550, y=320)
Files: playback/ui_adaptation.py
6. Background Execution
Integration with openadapt-tray:
- Use tray notifications for workflow status
- "Screenshot workflow completed: 12 images generated"
Files: playback/background_executor.py
7. Testing
Files: tests/test_claude_code_integration.py, tests/mocks.py
Dependencies
anthropic: Already in dependencies
ANTHROPIC_API_KEY: Environment variable
- Phase 1 complete (recording/replay working)
Success Criteria
✅ Claude Code handles prompts during replay
✅ Error recovery adapts to UI changes
✅ Workflows run in background without user
✅ Results posted to GitHub for mobile review
✅ Comprehensive tests with mocked API
Estimated Effort
12-16 hours (Claude Code integration, error handling, UI adaptation, testing)
Related Issues
Resources
Phase 2: Claude Code Integration
Enable autonomous decision-making during workflow replay via Claude Code API integration.
Goals
Tasks
1. ClaudeCodeIntegration Class
playback/claude_code_integration.pyhandle_prompt()methodhandle_error()methodadapt_action()for UI changesAPI Design:
2. Integrate with WorkflowExecutor
claude_code_enabledparameter toWorkflowExecutorFiles:
workflows/base.py3. Prompt Handling
Scenarios:
Implementation:
Files:
playback/claude_code_integration.py,playback/executor.py4. Error Recovery
Error types:
Recovery strategies:
Files:
playback/error_recovery.py5. UI Adaptation
Challenge: Recorded actions use exact coordinates, which break if UI changes
Solution: Use vision models to locate UI elements
Example:
Files:
playback/ui_adaptation.py6. Background Execution
Integration with openadapt-tray:
Files:
playback/background_executor.py7. Testing
Files:
tests/test_claude_code_integration.py,tests/mocks.pyDependencies
anthropic: Already in dependenciesANTHROPIC_API_KEY: Environment variableSuccess Criteria
✅ Claude Code handles prompts during replay
✅ Error recovery adapts to UI changes
✅ Workflows run in background without user
✅ Results posted to GitHub for mobile review
✅ Comprehensive tests with mocked API
Estimated Effort
12-16 hours (Claude Code integration, error handling, UI adaptation, testing)
Related Issues
Resources