Skip to content

Protect a GitHub repository for agents

POST
/github/repositories/{name}/agent-protection
Code sample: Shell / cURL
curl --request POST \
--url https://example.com/api/v1/github/repositories/example/agent-protection \
--header 'Authorization: Bearer <token>'

Adds Chelsea’s own rule sets to the repository where it does not already hold agents back: a branch rule set when its branches do not and a tag rule set when its tags are open (contents: write can create tags and releases). Each restricts creations, updates and deletions, on every branch outside agent/ or on every tag. When one of Chelsea’s own rule sets already exists in an older shape (people with bypass mode always, or a pull request rule in place of Restrict updates), it is brought to this one in place with one write, keeping its branches, its bypass list and any rule the team added; one already in this shape is not written. Then runs the check linking a repository to a project runs, and answers whether the repository now holds agents back (isProtected) and what is missing when it does not (problem). No other rule set or branch protection is edited, deleted or bypassed. People with the Write, Maintain or Admin role in the repository are exempt from both rule sets, so they create branches, push and merge with no bypass box; the integrations the organization chose in Settings, Integrations, GitHub (Shopify by default) can bypass them, and the GitHub App never can, so agents stay on agent/ branches, never create or move tags and cannot merge a pull request outside agent/. When GitHub refuses an integration because it is not installed in the organization, the rule set is added without it and droppedBypass names it. Needs the App’s Administration write access (424 GITHUB_ACCESS_MISSING names the step). Requires github.view and github.manage.

name
required

The repository’s name inside the organization

string

The repository’s name inside the organization

What the repository holds back now.

Media typeapplication/json
object
data
required
object
defaultBranch
required
string
droppedBypass

The integrations the rule set was meant to let through (such as Shopify) that GitHub refused because they are not installed in the organization, so the rule set was added without them. Empty when none was dropped; absent on an older server.

Array<string>
fullName
required
string
isProtected
required

Whether the repository now holds the App back the way a code agent’s token requires: the default branch blocks direct pushes, and every branch outside agent/ and every tag restricts creations, updates and deletions through rule sets the App cannot bypass, so no agent token can merge a pull request outside agent/.

boolean
isRulesetAdded
required

Whether Chelsea added its branch or tag rule set now or brought one of them from an older shape to the current one, with people exempt. false when nothing was written.

boolean
problem
required

What is still missing, in words, when isProtected is false; else null.

string | null

Example generated

{
"data": {
"defaultBranch": "example",
"droppedBypass": [
"example"
],
"fullName": "example",
"isProtected": true,
"isRulesetAdded": true,
"problem": "example"
}
}

Validation error. Parse failures include field paths and expectations.

Media typeapplication/json

Validation error with safe field paths and expected values; submitted values are never returned.

object
error
required
object
code
required

Stable machine-readable error code.

string
issues
Array<object>
object
expected
required
string
message
required
string
path
required
Array<string | number>
message
required

Human-readable error message.

string
status
required

HTTP status code, mirrored in the body.

integer
>= -9007199254740991 <= 9007199254740991

Example

{
"error": {
"code": "UNAUTHORIZED"
}
}

Unauthorized.

Media typeapplication/json

Standard error envelope.

object
error
required
object
code
required

Stable machine-readable error code.

string
message
required

Human-readable error message.

string
status
required

HTTP status code, mirrored in the body.

integer
>= -9007199254740991 <= 9007199254740991

Example

{
"error": {
"code": "UNAUTHORIZED"
}
}

Forbidden.

Media typeapplication/json

Standard error envelope.

object
error
required
object
code
required

Stable machine-readable error code.

string
message
required

Human-readable error message.

string
status
required

HTTP status code, mirrored in the body.

integer
>= -9007199254740991 <= 9007199254740991

Example

{
"error": {
"code": "UNAUTHORIZED"
}
}

Not found.

Media typeapplication/json

Standard error envelope.

object
error
required
object
code
required

Stable machine-readable error code.

string
message
required

Human-readable error message.

string
status
required

HTTP status code, mirrored in the body.

integer
>= -9007199254740991 <= 9007199254740991

Example

{
"error": {
"code": "UNAUTHORIZED"
}
}

Conflict.

Media typeapplication/json

Standard error envelope.

object
error
required
object
code
required

Stable machine-readable error code.

string
message
required

Human-readable error message.

string
status
required

HTTP status code, mirrored in the body.

integer
>= -9007199254740991 <= 9007199254740991

Example

{
"error": {
"code": "UNAUTHORIZED"
}
}

Invalid input.

Media typeapplication/json

Standard error envelope.

object
error
required
object
code
required

Stable machine-readable error code.

string
message
required

Human-readable error message.

string
status
required

HTTP status code, mirrored in the body.

integer
>= -9007199254740991 <= 9007199254740991

Example

{
"error": {
"code": "UNAUTHORIZED"
}
}

GitHub failed (GITHUB_API_ERROR), or Chelsea’s GitHub App or the organization has not granted the access this needs (GITHUB_ACCESS_MISSING; the message names the step in Settings, Integrations, GitHub).

Media typeapplication/json

Standard error envelope.

object
error
required
object
code
required

Stable machine-readable error code.

string
message
required

Human-readable error message.

string
status
required

HTTP status code, mirrored in the body.

integer
>= -9007199254740991 <= 9007199254740991

Example

{
"error": {
"code": "UNAUTHORIZED"
}
}

Rate limit exceeded. Wait for Retry-After before retrying.

Media typeapplication/json

Standard error envelope.

object
error
required
object
code
required

Stable machine-readable error code.

string
message
required

Human-readable error message.

string
status
required

HTTP status code, mirrored in the body.

integer
>= -9007199254740991 <= 9007199254740991

Example

{
"error": {
"code": "UNAUTHORIZED"
}
}
RateLimit-Limit
string
/^\d+$/

Maximum requests in the current quota window.

RateLimit-Policy
string

Quota policy in requests and window seconds, for example 60;w=60.

RateLimit-Remaining
string
/^\d+$/

Requests left in this quota window (zero when blocked).

RateLimit-Reset
string
/^\d+$/

Seconds until the current quota window resets, when available from the rate-limit store.

Retry-After
string
/^\d+$/

Seconds until another request may be attempted.