# Coding Agent Task Runner - Codex & OpenCode, Patch Out (`automa-flow/coding-agent-task-runner`) Actor

Give a repository and a task, get a patch, changed files, test results and the agent's summary in one call. Codex CLI or OpenCode, models through Apify's OpenRouter proxy, no API key of your own.

- **URL**: https://apify.com/automa-flow/coding-agent-task-runner.md
- **Developed by:** [Vadim Bezrukov](https://apify.com/automa-flow) (community)
- **Categories:** AI, Agents, Developer tools
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $20.00 / 1,000 task starts

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Coding Agent Task Runner - Codex & OpenCode, Patch Out

Give it a Git repository and a task in plain words. The Actor clones the repository, runs a
coding agent (OpenAI's **Codex CLI** or **OpenCode**) headless with a deadline, and returns:

- `patch.diff`: a binary-safe `git diff` you can apply with `git apply`
- the changed files, insertions and deletions
- the result of your test command (`npm test`, `pytest -q`, ...) if you give one
- the agent's own summary, its log and a status you can branch on

One call: task in, patch out. Models run through Apify's OpenRouter proxy, so you need no
OpenAI, Anthropic or OpenRouter key of your own.

**Try the prefill.** It asks the agent to add a CONTRIBUTING.md to `octocat/Hello-World`.
On our test runs Codex CLI with `deepseek/deepseek-v4-flash` finished in 7 to 14 seconds
with 4 to 8 model requests and about $0.003 of tokens, and returned a two-file patch (new
CONTRIBUTING.md, a link in the README). The whole run took 20 to 30 seconds and its Actor
events come to $0.06.

### Use it from n8n, Make or your own code

An agent run often takes longer than the 300 seconds a synchronous API call waits, so start
the run asynchronously and wait for it:

1. **Trigger**: for example a GitHub issue that gets the label `agent`.
2. **Start the run**: Apify node "Run an Actor" (or `POST
   https://api.apify.com/v2/acts/automa-flow~coding-agent-task-runner/runs?maxTotalChargeUsd=1`)
   with `{"repoUrl": "https://github.com/you/repo", "task": "<issue title and body>",
   "testCommand": "npm test"}`.
3. **Wait**: Apify node "Wait for run to finish", or poll `GET /v2/actor-runs/{runId}` every
   30 seconds until the run is no longer `RUNNING`.
4. **Branch on the row**: read the one Dataset item; `status` is `DONE`, `NO_CHANGES`,
   `TIMEOUT`, ... and `testsPassed` tells you whether your tests passed.
5. **Use the patch**: fetch `patch.diff` from the run's Key-Value Store (`GET
   /v2/key-value-stores/{defaultKeyValueStoreId}/records/patch.diff`). Post it as an issue
   comment for review, or send it to a GitHub Actions workflow (`repository_dispatch`) that
   runs `git apply` and `gh pr create`.

The Actor never pushes to your repository and never opens pull requests: you decide what
happens with the patch.

### Pricing

Pay per event, Apify platform usage included:

| Event | Price | When |
| --- | --- | --- |
| Actor start | $0.0003 per GB of memory | each run (2 GB default: $0.0006) |
| Task start | $0.02 | once, when the agent starts and the model answers |
| Agent minute | $0.04 | each started minute of agent plus test time, 2 GB included |
| Extra GB-minute | $0.01 | each started GB-minute above 2 GB (4 GB adds $0.02 a minute) |

Nothing past the start event is charged when the input is invalid, the clone fails, the
model is refused, the proxy is down or the budget cannot cover one minute. Retries and time
after the deadline are never charged.

**Model tokens are billed separately** by Apify's OpenRouter proxy, on your Apify account at
the provider's price. The row shows `tokenCostUsd` as the proxy reported it. Your
`maxTotalChargeUsd` limits this Actor's events, not tokens: `maxModelRequests` is what bounds
your token bill.

Example bills at 2 GB:

- the prefill (1 minute): $0.06 plus about $0.003 of tokens
- a 10-minute task: $0.42 plus tokens (cheap models: cents; frontier models: dollars)
- 100 such tasks a month: about $42 plus tokens

A small `maxTotalChargeUsd` shortens the agent's deadline to the minutes it covers, and the
run says so in RUN_SUMMARY. One minute with its start events costs $0.061 at 2 GB, $0.082 at
4 GB and $0.123 at 8 GB; a lower cap ends in `BUDGET_EXCEEDED` before any work.

### Input

| Field | What it does |
| --- | --- |
| `repoUrl` | `https://` clone URL. SSH, `git@`, `file:` and URLs with a token inside are refused. |
| `task` | What to change, 10-8,000 characters, for example an issue body. |
| `agent` | `codex` (default) or `opencode`. With the default model Codex is the more reliable: in our tests OpenCode stopped early without changes in 3 of 9 runs (`NO_CHANGES`, charged). |
| `model` | OpenRouter model ID, default `deepseek/deepseek-v4-flash`. |
| `gitRef` | Branch, tag or 40-character commit SHA. Default: the default branch. |
| `gitToken` | Read token for a private repository. Used for the clone only. |
| `testCommand` | Shell command run with `bash -lc` after the agent, up to 500 characters. |
| `testTimeoutSeconds` | 10-1,800, default 300. Counts toward agent minutes. |
| `maxMinutes` | Agent deadline, 1-60, default 10. |
| `maxModelRequests` | Model calls allowed, 1-2,000, default 200. |
| `includeUntracked` | Include new files in the patch (default on). |
| `failRunOnError` | End the run FAILED when the status is not `DONE` or `NO_CHANGES`. |
| `secrets` | Environment variables for the agent and the tests, for example a registry token. |

### Output

One Dataset row per run (views: Overview and Details). Abridged, from a test run of the prefill:

```json
{
  "status": "DONE",
  "message": "The agent changed 2 files.",
  "repoUrl": "https://github.com/octocat/Hello-World",
  "gitRef": "master",
  "baseCommit": "7fd1a60b01f91b314f59955a4e4d4e80d8edf11d",
  "agent": "codex",
  "agentVersion": "codex-cli 0.167.0",
  "model": "deepseek/deepseek-v4-flash",
  "filesChanged": 2,
  "insertions": 9,
  "deletions": 0,
  "changedFiles": ["CONTRIBUTING.md", "README"],
  "skippedLargeFiles": [],
  "patchKey": "patch.diff",
  "patchBytes": 895,
  "testCommand": null,
  "testsPassed": null,
  "agentSummary": "Created CONTRIBUTING.md with three bullet points and added a link to it at the bottom of the README.",
  "agentMinutes": 1,
  "modelRequests": 8,
  "promptTokens": 75028,
  "completionTokens": 990,
  "tokenCostUsd": 0.002634,
  "fingerprint": "67104d66b493041387daacba4f8a221e2c90148c0e88aa16d805ec3c487148cb"
}
```

The Key-Value Store holds `patch.diff`, `agent-log.txt` and `test-log.txt` (redacted, at
most 1 MiB each), `RUN_SUMMARY` (the row plus phases, durations, model request counts,
charged events and CLI versions) and `BILLING_RECEIPT`.

### Statuses

| Status | Meaning | Charged |
| --- | --- | --- |
| `DONE` | The patch is not empty. Failing tests still give `DONE` with `testsPassed: false`. | yes |
| `NO_CHANGES` | The agent finished without changing files. | yes |
| `AGENT_FAILED` | The agent exited with an error and changed nothing, or got no model answer in 5 minutes and was stopped. | if the model answered |
| `TIMEOUT` | The deadline was reached; the patch so far is returned. | yes |
| `REQUEST_LIMIT` | `maxModelRequests` was used up; the patch so far is returned. | yes |
| `MODEL_UNAVAILABLE` | The proxy refuses the model. | no |
| `PROXY_FAILED` | The model proxy did not answer. | no |
| `REPO_NOT_FOUND` | Wrong URL or ref, or a private repository without a token. | no |
| `REPO_AUTH_FAILED` | The git host refused the token. | no |
| `REPO_TOO_LARGE` | Over 500 MiB or 50,000 files after the clone. | no |
| `REPO_UNAVAILABLE` | The git host did not answer after 3 attempts. | no |
| `INPUT_INVALID` | An input field is wrong; the run fails. | no |
| `BUDGET_EXCEEDED` | `maxTotalChargeUsd` cannot cover one agent minute; the run fails. | no |

Every other status writes the row and ends the run normally, so a pipeline can branch on
`status`. Turn on `failRunOnError` if you want a failed run instead.

### Security model and privacy

The agent approves every command it decides to run, and a task or repository can come from
someone you do not trust. The Actor protects what matters to you:

- The agent and the test command run as an unprivileged user with an environment built
  from scratch: no Apify token, no proxy password, no `gitToken`, no `APIFY_*` variable.
- Model calls go through a local forwarder that adds your Apify token itself, allows only
  the model endpoints and stops at `maxModelRequests` and at the deadline. The model
  provider comes from the run: an `opencode.json` or `.codex/config.toml` in the repository
  cannot point the agent elsewhere.
- `gitToken` is used for the clone only and is never written to `.git/config`.
- Every secret value is removed from logs, the row and the KVS files, also in its URL and
  base64 forms. The task text is never logged (only its length and hash).
- At the deadline the agent's whole process group is stopped and every leftover process of
  the sandbox user is killed.

This is a container, not a virtual machine. Outbound network stays open, so the agent and
your tests can install packages. Put only the secrets your tests need into `secrets`.

**Privacy:** the repository content and the task are sent to the chosen model provider
through OpenRouter. Do not run it on code you may not share with that provider.

### Limits

- One repository and one task per run; agent deadline up to 60 minutes.
- Repository up to 500 MiB and 50,000 files after a shallow clone.
- Files over 5 MiB are left out of `patch.diff` and listed in `skippedLargeFiles`; a patch
  over 8 MiB is not stored.
- The image has git, ripgrep, Node.js 22 and Python 3.12. Other toolchains can be installed
  by the test command or the agent at run time.
- Memory 2-8 GB (default 2 GB). Bigger builds need more memory, which adds extra
  GB-minutes.
- No pushing, no pull requests, no interactive sessions.

### Use it from an AI agent (MCP)

Add the Actor as a tool through Apify's MCP server:
`https://mcp.apify.com?tools=automa-flow/coding-agent-task-runner`. An assistant can then
hand a coding task to a separate agent, wait for the run and read `status`, `changedFiles`,
`testsPassed` and `patch.diff` before it decides what to do next. Set `maxModelRequests` and
`maxTotalChargeUsd` in the call to bound the bill.

If a run fails or looks wrong, open an Issue and include the run URL. Release notes are in
the [changelog](https://apify.com/automa-flow/coding-agent-task-runner/changelog).

# Changelog

This Actor's version history is a separate document: https://apify.com/automa-flow/coding-agent-task-runner/changelog.md

# Actor input Schema

## `repoUrl` (type: `string`):

https:// clone URL of a Git repository, for example https://github.com/octocat/Hello-World. SSH, git@, file: and local paths are refused. Never put a token in the URL: use Git token below.

## `task` (type: `string`):

What the agent should change, 10 to 8,000 characters, for example the body of a GitHub issue. The agent runs every command it decides on inside the run container, so treat the task like code you run.

## `agent` (type: `string`):

codex runs OpenAI's Codex CLI, opencode runs OpenCode. Both use the model below through Apify's OpenRouter proxy, so no API key of your own is needed. With the default model codex is the more reliable: in our tests opencode sometimes stopped early without changes.

## `model` (type: `string`):

OpenRouter model ID, for example deepseek/deepseek-v4-flash (default, cheap and passed our fixture with both agents) or a larger model for harder tasks. A model the proxy does not list ends MODEL_UNAVAILABLE before the agent starts, with no charge. Model tokens are billed by the proxy, outside this Actor's events.

## `gitRef` (type: `string`):

Branch or tag name, or a 40-character commit SHA. Empty means the repository's default branch.

## `gitToken` (type: `string`):

Read token for a private repository (a GitHub fine-grained token with Contents read, a GitLab read_repository token). Used only for the clone; never given to the agent or the test command, never written to .git/config and removed from every log and output.

## `testCommand` (type: `string`):

Optional shell command run with bash -lc in the repository after the agent, for example npm test or pytest -q. Its exit code becomes testsPassed; failing tests still return the patch (status DONE). Up to 500 characters.

## `testTimeoutSeconds` (type: `integer`):

Wall time for the test command, 10-1,800. Test time counts toward billed agent minutes.

## `maxMinutes` (type: `integer`):

Deadline for the agent, 1-60 minutes. At the deadline the agent is stopped and the patch so far is returned with status TIMEOUT. A smaller maxTotalChargeUsd shortens it to what the budget covers.

## `maxModelRequests` (type: `integer`):

Model calls the agent may make, 1-2,000. This bounds your token bill. After the limit the agent is stopped and the patch so far is returned with status REQUEST_LIMIT.

## `includeUntracked` (type: `boolean`):

Include files the agent created in patch.diff. Turn off to return only changes to files already in the repository.

## `failRunOnError` (type: `boolean`):

When on, the run ends FAILED after storing the row and RUN_SUMMARY if the status is not DONE or NO_CHANGES, so an n8n or Make step stops. When off, pipelines branch on the status field.

## `secrets` (type: `object`):

Environment variables for the agent and the test command, for example {"NPM_TOKEN": "..."} for a private package registry. Stored encrypted and removed from logs, the row and KVS files. Up to 50 keys of A-Z, 0-9 and *; names starting with APIFY*, ACTOR\_, CRAWLEE\_, CATR\_, GIT\_, CODEX\_, OPENCODE\_, XDG\_, LD\_ or LC\_ and system names such as HOME or PATH are refused.

## `resource` (type: `object`):

Present on some webhook bodies; not read.

## `payload` (type: `object`):

Added by Actor-to-Actor integrations; not read.

## Actor input object example

```json
{
  "repoUrl": "https://github.com/octocat/Hello-World",
  "task": "Add a CONTRIBUTING.md with three short bullet points on how to contribute and link it from the README.",
  "agent": "codex",
  "model": "deepseek/deepseek-v4-flash",
  "testTimeoutSeconds": 300,
  "maxMinutes": 3,
  "maxModelRequests": 30,
  "includeUntracked": true,
  "failRunOnError": false
}
```

# Actor output Schema

## `results` (type: `string`):

No description

## `patch` (type: `string`):

No description

## `runSummary` (type: `string`):

No description

## `agentLog` (type: `string`):

No description

## `testLog` (type: `string`):

No description

## `billingReceipt` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "repoUrl": "https://github.com/octocat/Hello-World",
    "task": "Add a CONTRIBUTING.md with three short bullet points on how to contribute and link it from the README.",
    "maxMinutes": 3,
    "maxModelRequests": 30
};

// Run the Actor and wait for it to finish
const run = await client.actor("automa-flow/coding-agent-task-runner").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "repoUrl": "https://github.com/octocat/Hello-World",
    "task": "Add a CONTRIBUTING.md with three short bullet points on how to contribute and link it from the README.",
    "maxMinutes": 3,
    "maxModelRequests": 30,
}

# Run the Actor and wait for it to finish
run = client.actor("automa-flow/coding-agent-task-runner").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "repoUrl": "https://github.com/octocat/Hello-World",
  "task": "Add a CONTRIBUTING.md with three short bullet points on how to contribute and link it from the README.",
  "maxMinutes": 3,
  "maxModelRequests": 30
}' |
apify call automa-flow/coding-agent-task-runner --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,automa-flow/coding-agent-task-runner"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/nlErWsqAxjzLP8m5u/builds/LgBDpnepjY6bb0RQ5/openapi.json
