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

# Push webhooks

> Get a signed HTTPS request for every push and commit to your repos, and verify it with the SDK.

Set one webhook endpoint for your account, and the git service sends it a signed `POST` each time a push or a
[commit](https://docs.archil.com/git/commits.md) updates a repo's refs. Use it to start CI, index new code, or wake an agent when a branch moves.

## Set the endpoint

```typescript TypeScript theme={null}
const { secret } = await archil.git.webhook.set({ url: "https://example.com/hooks/git" });
// Store the secret now: it can't be read back.
```

```python Python theme={null}
secret = archil.git.webhook.set(url="https://example.com/hooks/git")
# Store the secret now: it can't be read back.
```

* **One endpoint per account,** for every repo. Calling `webhook.set()` again replaces the URL.
* **The URL must be `https`** and reachable from the internet.
* **Each call returns a new signing secret** and replaces the old one. There's no call to read a secret back, so to
  rotate it, call `webhook.set()` again and deploy the new secret to your receiver.

## The event

Each delivery is a JSON `push` event. The SDK's verify functions return it parsed, with camelCase fields in TypeScript
and snake\_case in Python.

```json theme={null}
{
  "type": "push",
  "id": "<event ID>",
  "created_at": "2026-12-01T18:04:05Z",
  "data": {
    "repo_id": "repo_...",
    "account_id": "org_...",
    "updates": [
      {
        "ref": "refs/heads/main",
        "before": "3f786850e387550fdab836ed7e6dc881de23001b",
        "after": "9fceb02d0ae598e95dc970b74767f19372d61af8"
      }
    ],
    "pushed_at": "2026-12-01T18:04:05Z"
  }
}
```

| TypeScript | Python | |
| - | - | - |
| `id` | `id` | The event's ID, also sent as the `X-Archil-Event-ID` header. De-duplicate on it |
| `createdAt` | `created_at` | When the event was created |
| `data.repoId` | `data.repo_id` | The repo that changed. For a fork, the fork's ID |
| `data.accountId` | `data.account_id` | Your account |
| `data.updates` | `data.updates` | Each ref the push or commit changed: `ref`, `before`, and `after` |
| `data.pushedAt` | `data.pushed_at` | When the push happened |

A ref that was created has a `before` of 40 zeros, and a ref that was deleted has an `after` of 40 zeros.

## Verify deliveries

Each request carries an `X-Archil-Signature` header:

```
X-Archil-Signature: t=<unix seconds>,v1=<hex HMAC-SHA256(secret, "<t>.<raw body>")>
```

Verify it with the SDK before you trust the body. Pass the raw request body exactly as it arrived: a body that was
parsed and serialized again won't verify. Signatures more than 5 minutes old are rejected, which you can change with
`toleranceSeconds` (`tolerance_seconds` in Python).

* `verifyWebhook` (`verify_webhook`) returns the parsed event, and throws `WebhookVerificationError`, with the reason,
  if the signature is missing, wrong, or too old.
* `verifySignature` (`verify_signature`) returns `true` or `false` instead.

In TypeScript they're in `disk/webhooks`, which also exports `SIGNATURE_HEADER` and `EVENT_ID_HEADER`. In Python
they're in `archil.git`. Both run anywhere, including edge runtimes.

```typescript TypeScript theme={null}
import { createServer } from "node:http";
import { EVENT_ID_HEADER, SIGNATURE_HEADER, WebhookVerificationError, verifyWebhook } from "disk/webhooks";

const secret = process.env.ARCHIL_GIT_WEBHOOK_SECRET!;
const seen = new Set<string>(); // use a durable store in production

createServer(async (req, res) => {
  const chunks: Buffer[] = [];
  for await (const chunk of req) chunks.push(chunk as Buffer);
  const body = Buffer.concat(chunks); // the raw bytes

  try {
    const signature = req.headers[SIGNATURE_HEADER.toLowerCase()] as string | undefined;
    const event = await verifyWebhook(body, signature, secret);
    if (!seen.has(event.id)) {
      seen.add(event.id);
      for (const u of event.data.updates) {
        console.log(`${event.data.repoId} ${u.ref}: ${u.before} -> ${u.after}`);
      }
    }
    res.writeHead(204).end();
  } catch (err) {
    if (!(err instanceof WebhookVerificationError)) throw err;
    console.warn(`rejected ${req.headers[EVENT_ID_HEADER.toLowerCase()]}: ${err.message}`);
    res.writeHead(401).end();
  }
}).listen(8787);
```

```python Python theme={null}
import os
from archil.git import WebhookVerificationError, verify_webhook

secret = os.environ["ARCHIL_GIT_WEBHOOK_SECRET"]
seen: set[str] = set()  # use a durable store in production

def handle(raw_body: bytes, headers) -> int:
    """Call from your web framework with the raw request body. Returns the status to send."""
    try:
        event = verify_webhook(raw_body, headers.get("X-Archil-Signature"), secret)
    except WebhookVerificationError as e:
        print("rejected:", e)
        return 401
    if event.id not in seen:
        seen.add(event.id)
        for u in event.data.updates:
            print(event.data.repo_id, u.ref, u.before, "->", u.after)
    return 204
```

## Delivery

* **At least once.** If your endpoint doesn't answer with a 2xx within 10 seconds, the git service retries the delivery
  with backoff until it does. The same event can arrive more than once, so de-duplicate on `id`.
* **In order per repo.** Events for one repo arrive in the order its refs changed. Events for different repos aren't
  ordered relative to each other.
* **Durable.** Each event is recorded on the repo's disk as part of the push, so an event isn't lost if the git service
  restarts before delivering it.
* **Forks** send no event for their starting state, only for their own pushes and commits afterward. See
  [Forks](https://docs.archil.com/git/forks.md#what-a-fork-gets).

Answer quickly and do slow work after responding: an endpoint that takes longer than 10 seconds is treated as a failed
delivery, and the event is sent again.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.