---
title: "Write Your Own AgentRQ Hook in WebAssembly | AgentRQ Guidelines"
url: https://agentrq.com/guidelines/hooks/write-your-own-agentrq-hook-in-webassembly
description: "Write your own AgentRQ hook for any service: a small WebAssembly program with manifest and handle calls, built in Go with the hook SDK and uploaded."
---

![](https://agentrq.com/assets/guideline-icons/code.svg) Checked November 26, 2026 | [All Hooks guides](https://agentrq.com/guidelines/hooks/)

# Write Your Own AgentRQ Hook in WebAssembly

To connect a service no built-in hook covers, write your own hook: a small WASI preview1 program that prints a manifest of its inputs and events when called with `manifest`, and checks a request and picks its events when called with `handle`. In Go, AgentRQ's hook SDK does the plumbing, so a hook is a manifest and one function. Build it with `GOOS=wasip1 GOARCH=wasm go build`, upload it, and register it like the built-in ones.

This page is one of our [Hooks guidelines](https://agentrq.com/guidelines/hooks/). It follows the [Hooks docs](https://github.com/agentrq/agentrq/blob/main/docs/HOOKS.md) and the SDK in [wasm-hooks/sdk](https://github.com/agentrq/agentrq/tree/main/wasm-hooks/sdk), and was checked against AgentRQ v0.19.6 on November 26, 2026.

## Before You Start

- → **A self-hosted AgentRQ server.** On a server with `AGENTRQ_HOOKS_ALLOW_USER_HOOKS=true`, **Events → Hooks → Your hooks** uploads your own hooks. Otherwise, ask the server's operator to add yours as a built-in hook: see [install a built-in hook](https://agentrq.com/guidelines/hooks/check-hook-deliveries-replay-rotate-and-reach-your-server#install-a-built-in-hook-on-a-self-hosted-server).
- → **A recent Go.** Go builds `wasip1` since 1.21; the SDK's module follows the AgentRQ repository's Go version. Any language that compiles to WASI preview1 works; the SDK is for Go.
- → **First check the generic hook.** If the service can send a fixed secret in a header, the [generic hook](https://agentrq.com/guidelines/hooks/start-an-agent-task-from-any-webhook-with-the-generic-hook) already works. Write your own when the service signs requests its own way, or when one request should fire different events.

## How a Hook Runs

A hook runs in a sandbox, a fresh one for every request: no files, no network, no environment, 32 MiB of memory and 250 ms. The server calls it two ways:

- → **manifest**: it prints its name, version, inputs and events as JSON. It must declare at least one input that is both secret and required, and check it, because the URL's id alone can be guessed.
- → **handle**: it reads `{registrationId, request, inputs, now}` on stdin and prints `{accept, reason, events}`. Each event has a **name** the manifest declares, and optionally a **dedupKey**, a **payload** (a string or any JSON value) and a **faq**.

The request carries the method, path, query, headers and raw body. The inputs are the registration's values, secrets included. The hook never sees the hook token in the URL: the server checks that before the hook runs.

## Step by Step: Write a Hook in Go

**1. Start a module** and add the SDK:

bash

```bash
mkdir deploys && cd deploys
go mod init example.com/deploys
go get github.com/agentrq/agentrq/wasm-hooks/sdk
```

**2. Write main.go.** This hook takes a secret token in an X-Token header and fires **deploy.failed** with the request body as its payload:

go

```go
package main

import "github.com/agentrq/agentrq/wasm-hooks/sdk"

var manifest = sdk.Manifest{
	Name:    "deploys",
	Version: "1.0.0",
	Inputs:  []sdk.Input{{Name: "token", Label: "Token", Type: "string", Secret: true, Required: true}},
	Events:  []sdk.Event{{Name: "deploy.failed", Description: "A deploy failed"}},
}

func main() {
	sdk.Main(manifest, func(in sdk.In) sdk.Result {
		if !sdk.Equal(in.String("token"), in.Request.Header("X-Token")) {
			return sdk.Reject("wrong token")
		}
		return sdk.Accept(sdk.Out{Name: "deploy.failed", Payload: string(in.Request.Body)})
	})
}
```

**3. Build it** for WebAssembly:

bash

```bash
GOOS=wasip1 GOARCH=wasm go build -o deploys.wasm .
```

**4. Upload it.** With user hooks on, open **Events → Hooks → Your hooks** and upload `deploys.wasm`. Otherwise the operator uploads it from the admin page, or from a script with the gzipped curl in [install a built-in hook](https://agentrq.com/guidelines/hooks/check-hook-deliveries-replay-rotate-and-reach-your-server#install-a-built-in-hook-on-a-self-hosted-server).

**5. Register it** like any hook: **Events → Hooks → New registration**, pick **deploys**, generate the token, route **deploy.failed** to an event whose trigger files the task, and copy the payload URL into the service.

## Rules for a Good Hook

- → **Compare secrets with sdk.Equal**, which takes the same time whatever the input, and never matches an empty secret.
- → **Check signatures with sdk.ValidHMACSHA256(secret, body, signature)** when the service signs the body with HMAC-SHA256 in hex, as GitHub does after its `sha256=` prefix.
- → **Return sdk.Reject for a request that is not genuine**, with a reason. It shows as **rejected** in the registration's deliveries.
- → **Return sdk.Accept with no events for a genuine one with nothing to do**, such as a ping or a branch you filter out. It shows as **ignored**.
- → **Set a dedupKey** from the service's delivery id or the request's Idempotency-Key, so a retry is recorded as **duplicate** and fires nothing.
- → **Keep the payload small and readable.** It becomes the task's `{{EVENT_PAYLOAD}}`, so plain text the agent can act on beats a raw dump. The server caps it at 64 KiB by default.
- → **Add a faq** to an event for questions the agent will have, such as where the logs are, each with a **Q** and an **A**.

## Inputs

Each input in the manifest becomes a field in the registration form.

| Field | What it does |
| --- | --- |
| Name | The key the hook reads with `in.String(name)` or `in.Strings(name)`. |
| Type | string, number, boolean or array. An array names its element type in Items. |
| Label | The field's name in the registration form. |
| Placeholder | An example value the form shows in the empty field, such as `main, release/*`. |
| Secret | Stored encrypted and never shown again. The form offers Generate and Copy. |
| Required | The registration can't be saved without it. |

## Upgrading a Hook

Uploading a new version of a hook keeps its registrations, unless it would break one. These upgrades are refused:

- → an event someone routes is gone,
- → an input becomes required,
- → an input changes type, or stops being secret.

An input the new version drops is no longer given to it, and is cleared the next time the registration is saved. To make a breaking change, publish it as a new hook with its own name, and move the registrations over.

## Complete Examples

The built-in hooks are written the same way, each with its tests:

- → [wasm-hooks/generic](https://github.com/agentrq/agentrq/blob/main/wasm-hooks/generic/main.go): a token in a header, the body as the payload, Idempotency-Key as the dedupKey.
- → [wasm-hooks/github](https://github.com/agentrq/agentrq/blob/main/wasm-hooks/github/main.go): an HMAC signature, seven events from five GitHub event types, branch globs.
- → [wasm-hooks/jira](https://github.com/agentrq/agentrq/blob/main/wasm-hooks/jira/main.go): two ways to authenticate, account-id filters and a plain-text payload.

## FAQ

### Can my hook call the service's API?

No. A hook has no network, files or environment, so everything it decides must come from the request and the registration's inputs. If the agent needs more, put what it needs to find it in the payload, and give the workspace access to the service's API or MCP server.

### Can I write a hook in Rust, TypeScript or another language?

Yes, if it compiles to WASI preview1. Read the command, manifest or handle, from the program's first argument, read the JSON on stdin for handle, and print the JSON answer on stdout. The SDK's sdk.go is a short reference for the exact shapes.

### How do I test a hook before uploading it?

Run it with a WASI runtime such as wasmtime: `wasmtime deploys.wasm manifest` prints the manifest, and `wasmtime deploys.wasm handle < request.json` prints the answer. In Go, keep the handle function named and call it from an ordinary Go test with a hand-made sdk.In, as the built-in hooks' tests do.

### Why must a hook check a secret?

The payload URL's id can be guessed, and the token in it may end up in a log. A secret the service shares with the hook is what proves a request is genuine, so the server refuses a manifest without a required secret input.
