Claude Code & OpenClaw Agent Integration
Relevant source files
The following files were used as context for generating this wiki page:
The Claude Code and OpenClaw agent integration provides a robust framework for executing autonomous coding tasks within isolated Vercel Sandbox environments. This system allows the Recoup platform to delegate complex software engineering workflows—such as fixing bugs, syncing repositories, and creating Pull Requests—to AI agents capable of interacting with the file system and Git version control.
The integration leverages Trigger.dev for background task orchestration, ensuring that long-running agent operations are handled reliably outside the main request/response cycle. By utilizing specialized sandboxes, the system maintains security and isolation while providing agents with the necessary tools (e.g., GitHub CLI, Claude Code, and OpenClaw) to complete their assigned objectives.
Sources: src/tasks/codingAgentTask.ts, AGENTS.md:1-5, README.md:33-35
Architecture and Core Components
The integration is built upon a layered architecture where background tasks orchestrate the lifecycle of ephemeral sandboxes. Within these sandboxes, AI agents execute commands to manipulate codebases.
Execution Flow
The standard workflow for a coding agent starts with sandbox creation and environment setup, followed by code retrieval and agent execution.
This diagram illustrates the sequential steps taken by the codingAgentTask to fulfill a coding request.
Sources: src/tasks/codingAgentTask.ts:25-83
Key Integration Functions
| Function | Description | Source File |
|---|---|---|
runClaudeCodeAgent | Executes the claude CLI command with specific flags and prompts. | src/sandboxes/runClaudeCodeAgent.ts |
runOpenClawAgent | Executes the openclaw CLI for repository management and setup. | src/sandboxes/runOpenClawAgent.ts |
pushAndCreatePRsViaAgent | Delegates the logic of committing, pushing, and PR creation to the agent. | src/sandboxes/pushAndCreatePRsViaAgent.ts |
syncMonorepoSubmodules | Uses an agent to ensure submodules are at the latest remote state. | src/sandboxes/git/syncMonorepoSubmodules.ts |
Claude Code Agent Implementation
The Claude Code agent is the primary engine for making code changes. It is invoked using the claude CLI with specialized flags to allow autonomous operation.
Command Configuration
The system invokes Claude Code using the following parameters:
- Command:
claude - Arguments:
["-p", "--dangerously-skip-permissions", prompt] - CWD: Defaults to
/vercel/sandbox/mono - Environment: Requires
CLAUDE_CODE_OAUTH_TOKENfor authentication.
Sources: src/sandboxes/tests/runClaudeCodeAgent.test.ts:39-50, src/sandboxes/runClaudeCodeAgent.ts
Automated PR Creation logic
Rather than using programmatic Git libraries, the system instructs the agent to handle the entire PR lifecycle. This includes branching, committing, and using the GitHub CLI (gh) to open PRs. The agent outputs a specific sentinel line (PR_CREATED: <URL>) which the parent task parses to track results.
Sources: src/sandboxes/pushAndCreatePRsViaAgent.ts:50-77, src/sandboxes/tests/pushAndCreatePRsViaAgent.test.ts:16-30
OpenClaw Agent Integration
OpenClaw is utilized for repository-level operations and environment preparation. It is often used to manage organizational repositories and ensure the sandbox workspace is correctly structured.
Repository Syncing
OpenClaw is specifically tasked with syncing organizational repositories to their latest remote states. This prevents "stale snapshots" from causing force-pushes that might delete merged commits.
Sources: src/tasks/runSandboxCommandTask.ts:74-77, src/sandboxes/git/syncOrgRepos.ts
This sequence shows how OpenClaw interacts with GitHub to maintain repository parity within the sandbox.
Sources: src/sandboxes/tests/syncOrgRepos.test.ts:43-55
Task Orchestration
The system defines specialized tasks for different agentic workflows.
Coding Agent Task (coding-agent)
This task is responsible for high-level code modifications. It creates a sandbox, clones the Recoup monorepo, runs the Claude Code agent, and returns the resulting PR URLs and snapshot IDs.
Sources: src/tasks/codingAgentTask.ts:25-32
Update PR Task (update-pr)
This task handles feedback loops. It resumes a sandbox from a previous snapshotId, applies feedback via the agent, and pushes updates to the existing branch.
Sources: src/tasks/tests/updatePRTask.test.ts:60-70
Security and Git Workflow
Agents are strictly governed by the following rules defined in AGENTS.md:
- No direct pushes to
main: All changes must go through feature branches and Pull Requests. - Commit Requirements: Every change must be followed by a descriptive commit.
- Environment Isolation: Agents operate in ephemeral Linux microVMs.
Sources: AGENTS.md:7-13, src/sandboxes/writeReadme.ts:40-45
Summary
The Claude Code and OpenClaw integration provides a high-degree of automation for the Recoup development lifecycle. By wrapping AI agents in controlled sandbox environments and orchestrating them via Trigger.dev, the system enables autonomous code generation and repository management while maintaining strict version control standards and operational security.