> ## Documentation Index
> Fetch the complete documentation index at: https://docs.automate.ax/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Automate.ax automations are TypeScript programs.
> Use Bun for installation and command examples.
> Use Automate.ax for the product name and automate.ax for the package, CLI, and domain.
> Treat documented public APIs as current; do not invent transitional or deprecated names.

# Wait for cloud task

> Continue an automation after an existing Codex cloud task finishes.

`waitForCodexCloudTask` durably checks an existing task until it reaches a terminal state.

```ts automations/wait-for-codex-task.automation.ts theme={null}
import { automation, onHttpRequest } from "automate.ax"
import { startCodexCloudTask, waitForCodexCloudTask } from "automate.ax/codex"

export default automation("Wait for Codex", () => {
  onHttpRequest({ scope: "automation" })
  const started = startCodexCloudTask({
    branch: "main",
    environmentId: "env_abc123",
    prompt: "Implement the requested change and validate it.",
  })
  const completed = waitForCodexCloudTask({
    taskId: started.id,
    pollInterval: "5m",
    maxPolls: 36,
  })

  completed.status
  completed.currentTurnId
  completed.pullRequests
})
```

`taskId` accepts a task ID or compatible signal, including `startCodexCloudTask(...).id` or `continueCodexCloudTask(...).taskId`. `pollInterval` defaults to `"5m"`; `maxPolls` defaults to `36` and accepts up to `120`. Optional second argument `{ account }` defaults to the project binding and is reused for every status check.

Automate.ax checks immediately, then performs each remaining check in a durable child continuation, so provider work can outlive any individual Lambda invocation. The result emits when the task status becomes `ready`, `applied`, or `error`. It includes the prompt, attempts, messages, diff, branch, environment, and pull requests. The signal fails if the task remains pending for the complete polling budget.

<Warning>
  Codex Cloud does not currently provide an official public REST API. This
  callable uses undocumented ChatGPT backend endpoints that may change without
  notice.
</Warning>
