Skip to content

[Phase 4] Claude Code Engine Adapter #411

Description

@frankbria

Summary

Implement an AgentAdapter for Claude Code CLI, allowing CodeFrame to delegate code writing to Claude Code as a subprocess while retaining orchestration control.

Parent issue: #408

Motivation

Claude Code is Anthropic's dedicated coding agent with sophisticated tool use, file editing, and project understanding. Rather than replicating its capabilities in CodeFrame's built-in ReactAgent, delegate to it directly and let CodeFrame handle what it does best: orchestration, verification, and lifecycle management.

Scope

New module: core/engines/claude_code.py

  1. ClaudeCodeAdapter implementing AgentAdapter:
class ClaudeCodeAdapter:
    name = "claude-code"
    requires_api_key = {"ANTHROPIC_API_KEY": "Anthropic API key"}
    
    def execute(self, task_prompt, workspace_path, context, timeout_ms):
        # 1. Write task prompt to temp file
        # 2. Launch: claude --print --dangerously-skip-permissions -p <prompt>
        #    with cwd=workspace_path
        # 3. Stream stdout, capture file changes
        # 4. Parse exit code and output into AgentResult
        ...
  1. Subprocess management:

    • Launch Claude Code CLI with appropriate flags
    • --print mode for non-interactive output
    • --dangerously-skip-permissions for automated execution (configurable)
    • Set cwd to workspace path
    • Capture stdout/stderr
    • Enforce timeout via timeout_ms
  2. Output parsing:

    • Detect file modifications from Claude Code's output
    • Parse success/failure from exit code
    • Extract summary from final output
    • Detect if Claude Code created a blocker-like question
  3. Event streaming:

    • Parse Claude Code's streaming output into AgentEvents
    • Forward progress messages to CodeFrame's event system
  4. Configuration:

    • claude_code_path: path to Claude Code binary (default: claude)
    • claude_code_flags: additional CLI flags
    • approval_mode: skip (default for automation) or interactive

Key Design Decisions

  • Subprocess, not API: Claude Code is a CLI tool, so we launch it as a subprocess. This is the same pattern Symphony uses for Codex.
  • Non-interactive by default: For automated batch execution, use --dangerously-skip-permissions. For single-task interactive use, can be configured otherwise.
  • File change detection: After Claude Code exits, diff the workspace to detect what changed (using git diff or filesystem timestamps).

Acceptance Criteria

  • ClaudeCodeAdapter implements AgentAdapter protocol
  • Claude Code launched as subprocess with correct cwd
  • Task prompt passed via --print -p flag
  • Timeout enforced (process killed after timeout_ms)
  • Exit code mapped to AgentResultStatus
  • Modified files detected via git diff after execution
  • Streaming output forwarded as AgentEvents
  • Works with cf work start <id> --execute --engine claude-code
  • Integration test with mock Claude Code binary

Dependencies

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestphase-4.2Phase 4.2: First Adapter Implementations (Claude Code, Codex)

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions