← Blog

Claude API Webhook Signature Verification Guide

2026-11-15 · 5 min read · SubToAPI Team

Why webhook signature verification matters for Claude-powered apps

If you've built anything on top of the Claude API — a background job that summarizes documents, a batch pipeline, an agent that calls out to Claude and then notifies other systems — you've probably ended up building webhooks somewhere in the stack. Maybe your own backend fires a webhook when a long-running Claude generation finishes. Maybe a billing provider, queue service, or API gateway sends you events about usage or job status. In every one of these cases, the question is the same: how do you know the webhook actually came from the system you expect, and not from someone who guessed your endpoint URL?

Anthropic's Claude API itself is a synchronous request/response API — there's no native "Claude webhook" that pushes events to you directly. What usually needs signature verification is the layer around Claude: your own outbound notifications, a third-party service that wraps Claude usage events, or a payment/usage-alert provider tied to your Claude-powered product. This guide walks through the standard pattern for verifying any HMAC-signed webhook, with code you can drop into a Claude-adjacent service today.

The standard webhook signature pattern

Almost every webhook signing scheme — Stripe, GitHub, Slack, and most custom implementations — follows the same structure:

  1. The sender computes an HMAC-SHA256 hash of the raw request body (sometimes combined with a timestamp) using a shared secret.
  2. The hash is sent in a header, typically something like X-Signature or X-Webhook-Signature.
  3. The receiver recomputes the same hash on their end and compares it to the header value using a constant-time comparison.
  4. A timestamp is included and checked against a tolerance window to prevent replay attacks.

If you're designing your own webhook sender — for example, notifying a customer's system when a Claude job in your product completes — this is the pattern to copy. If you're receiving webhooks from a third party, this is what you should expect them to implement, and what you need to verify.

Signing side (sender)

const crypto = require("crypto");

function signPayload(payload, secret) {
  const timestamp = Math.floor(Date.now() / 1000);
  const body = JSON.stringify(payload);
  const signedContent = `${timestamp}.${body}`;

  const signature = crypto
    .createHmac("sha256", secret)
    .update(signedContent)
    .digest("hex");

  return {
    headers: {
      "X-Webhook-Timestamp": String(timestamp),
      "X-Webhook-Signature": signature,
    },
    body,
  };
}

Note that the signature covers timestamp + raw body, not just the body. That's what lets the receiver reject old, replayed requests.

Verifying side (receiver)

This is the part most developers get wrong — usually by verifying against a re-serialized JSON object instead of the raw bytes that were actually signed.

const crypto = require("crypto");

function verifySignature(rawBody, timestamp, signature, secret, toleranceSeconds = 300) {
  const now = Math.floor(Date.now() / 1000);
  const ts = Number(timestamp);

  if (!ts || Math.abs(now - ts) > toleranceSeconds) {
    return { valid: false, reason: "stale_or_missing_timestamp" };
  }

  const signedContent = `${timestamp}.${rawBody}`;
  const expected = crypto
    .createHmac("sha256", secret)
    .update(signedContent)
    .digest("hex");

  const expectedBuf = Buffer.from(expected, "hex");
  const givenBuf = Buffer.from(signature, "hex");

  if (expectedBuf.length !== givenBuf.length) {
    return { valid: false, reason: "length_mismatch" };
  }

  const isValid = crypto.timingSafeEqual(expectedBuf, givenBuf);
  return { valid: isValid, reason: isValid ? null : "signature_mismatch" };
}

In an Express app, make sure you have access to the raw body, not the parsed JSON object, before verification runs:

app.post(
  "/webhooks/claude-jobs",
  express.raw({ type: "application/json" }),
  (req, res) => {
    const rawBody = req.body.toString("utf8");
    const { valid } = verifySignature(
      rawBody,
      req.headers["x-webhook-timestamp"],
      req.headers["x-webhook-signature"],
      process.env.WEBHOOK_SECRET
    );

    if (!valid) return res.status(401).send("invalid signature");

    const event = JSON.parse(rawBody);
    // process event
    res.status(200).send("ok");
  }
);

Parsing the body into an object and then re-stringifying it for verification is the single most common bug here — JSON key ordering and whitespace differences will silently break signature checks and leave you vulnerable to the exact spoofing you're trying to prevent.

Testing your verification with curl

You can simulate a signed request to sanity-check your endpoint without writing a full test harness:

BODY='{"event":"job.completed","job_id":"job_123"}'
TS=$(date +%s)
SECRET="whsec_test"
SIG=$(printf "%s.%s" "$TS" "$BODY" | openssl dgst -sha256 -hmac "$SECRET" | awk '{print $2}')

curl -X POST https://yourapp.com/webhooks/claude-jobs \
  -H "Content-Type: application/json" \
  -H "X-Webhook-Timestamp: $TS" \
  -H "X-Webhook-Signature: $SIG" \
  -d "$BODY"

If your endpoint rejects this with a mismatch, check that the raw body on the server side exactly matches $BODY byte-for-byte — trailing newlines added by middleware are a frequent cause of false negatives.

Secret rotation and key hygiene

Treat webhook secrets the same way you'd treat an API key: store them in environment variables or a secrets manager, never in source control, and rotate them periodically. A clean rotation pattern is to support two active secrets at once — verify against both, then retire the old one once all senders have switched. This is the same discipline you'd apply to any credential sitting in front of a Claude-powered backend: if you're issuing application keys to your own users through a layer like SubToAPI, each key (sub_live_...) can be rotated independently per app, which makes it straightforward to apply the same rotation habit to webhook secrets tied to those apps. See the docs for how key scoping works if you're managing multiple Claude-backed services under one account.

Common pitfalls to avoid

questions

Does the Claude API itself send webhooks? No. The Claude Messages API is request/response based. Webhooks typically come from your own application logic (notifying systems when a Claude-powered job finishes) or from third-party services you integrate alongside Claude, such as billing or monitoring providers.

What's the best hashing algorithm for webhook signatures? HMAC-SHA256 is the standard choice — it's fast, widely supported, and used by most major webhook senders (Stripe, GitHub, Slack). Avoid plain MD5 or SHA1, and always compare hashes with a constant-time function.

How do I stop replayed webhook requests from being processed twice? Include a timestamp in the signed payload and reject anything outside a reasonable window (5 minutes is common). Pair this with idempotency keys or event IDs on the receiving end so duplicate valid deliveries within the window still only get processed once.

Turn your Claude access into an HTTPS API

SubToAPI gives you application API keys, streaming, tool use and usage insights on top of your existing Claude access — set up in minutes.

Start free  Read the quickstart →