Phase 3: Claude Code Delegation
Goal
LARS can hand off complex tasks to Claude Code.
When to Delegate
- Multi-file code changes
- Complex refactoring
- Tasks requiring tool access
- Long-running operations
- Things LARS can't do locally
Implementation
1. Delegation Trigger
Train LARS to recognize when to delegate:
User: "Hey LARS, refactor the auth module"
LARS: <think>This requires multi-file changes and deep code analysis. I should delegate to Claude Code.</think>
<answer>That's a complex task. Let me hand this off to Claude Code for you.</answer>
2. SSH Execution
import subprocess
import uuid
def delegate_to_claude(task: str, project_path: str = None):
session_id = str(uuid.uuid4())
cmd = ["claude", "-p", task, "--session-id", session_id]
if project_path:
cmd = ["bash", "-c", f"cd {project_path} && {' '.join(cmd)}"]
result = subprocess.run(cmd, capture_output=True, text=True, timeout=300)
return {
"output": result.stdout,
"session_id": session_id,
"success": result.returncode == 0
}
3. Result Reporting
LARS summarizes what Claude Code did:
LARS: "Claude Code finished the refactor. It updated 5 files:
- auth/login.py - Added token validation
- auth/middleware.py - New rate limiting
- tests/test_auth.py - Added 12 new tests
All tests passing. Want me to explain any changes?"
Success Criteria
- Seamless handoff from voice to Claude Code
- Session persistence for follow-ups
- Clear status updates during execution
- Results summarized by LARS