---
title: "Apply a repository's automation files"
method: POST
path: "/code/automations/apply"
---

# Apply a repository's automation files

`POST /code/automations/apply`

## Request

- Base URL: `https://api.caveman.so/api/v1`
- URL: `https://api.caveman.so/api/v1/code/automations/apply`
- Auth: one of:
  - OAuth 2
    - Authorization code: `/api/v1/oauth/authorize`
    - Token URL: `/api/v1/oauth/token` scopes: `code:write`
  - HTTP bearer
  - API key in cookie `cave_access`
  - API key in cookie `__Secure-cave_identity.session_token`

POST /api/v1/code/automations/apply on the Caveman Cloud control plane. Requires the code:write scope. Not exposed to autonomous agents: Cloud automations are applied from a repository's .caveman/ files by the Code app, a code:run key or a push to the default branch, and a person approves wider authority (ADR 0133). An agent works inside a run's session and never applies, approves, enables or fires automations from a control-plane connection.

## Request body

- object
  - `repo` string, required: owner/name
  - `commit_sha` string
  - `files` object, required: .caveman/automations/<name>.yaml and .caveman/agents/<name>.md files by path.
  - `service_account_id` string, uuid: A person's apply: the service account the automations run as. A code:run key binds its own.

## Response `200`

What the apply did to each automation

- object
  - `automations` CodeAutomationApplied[], required
    - `id` string, uuid, required
    - `name` string, required
    - `path` string
    - `revision_id` string
    - `state` 'active' | 'pending_approval' | 'unchanged' | 'removed', required
    - `authority_diff` object, required: What a revision adds over the active one. widens: it waits for approval.
      - `widens` boolean, required
      - `new` boolean
      - `changes` object[], required
        - `key` string, required
        - `change` 'added' | 'removed' | 'changed', required
        - `before` unknown
        - `after` unknown
        - `widens` boolean, required
    - `reason` string: not_owner: the change widens nothing but waits, the applier does not answer for this automation.
    - `hook` object: The automation's signed hook, once, when its first webhook revision becomes active. Sign each request with X-Caveman-Signature: sha256=<hex HMAC-SHA256 of the body> and name each event in X-Caveman-Delivery; without it, identical bodies that arrive in the same minute are one run.
      - `id` string
      - `path` string
      - `secret` string

## Other responses

- `401`: A person's sign-in or a code:run key is required.
- `403`: The role, the key's scope, or an inactive service account (cave_code_service_account_inactive) refuses.
- `2XX`: Successful response. Exact status depends on synchronous or durable delivery outcome.
- `4XX`: Structured failure. `error.code` is stable; `error.request_id` is echoed in the x-cave-request-id header.
- `5XX`: Structured failure. `error.code` is stable; `error.request_id` is echoed in the x-cave-request-id header.

---

[API](https://skmtc.dev/caveman/apis/caveman-cloud-api.md) - [All operations](https://skmtc.dev/caveman/apis/caveman-cloud-api/llms.txt) - [OpenAPI document](https://skmtc.dev/caveman/apis/caveman-cloud-api/revisions/508312d01cfc?raw)
