encore-pubsub — Claude Code skill: what it does, how to install
This skill guides asynchronous messaging in Encore.ts with Topic and Subscription, including fan-out events and background consumers.
npx skills add encoredev/skills --skill encore-pubsub -a claude-code
npx skills add encoredev/skills --skill pubsub -a claude-codeWhat encore-pubsub does
The skill covers event-based messaging between Encore.ts services. A producer sends data to a Topic, while each Subscription runs its own consumer. It also shows how to pass publishing access through a Publisher reference, so other code can send events without owning the topic declaration.
Topics and subscriptions belong at package scope, not inside functions. Use Attribute<T> with orderingAttribute when a field controls filtering or delivery order. The documented guarantees are at-least-once and exactly-once; with at-least-once, handlers must be idempotent because duplicate deliveries are possible. publish returns after queuing the message, so heavy synchronous work should stay out of the caller.
What it helps with
- publish events between services
- fan one event out to several handlers
- run background consumers for messages
- preserve event order by an attribute
- pass topic access through a
Publisherreference
Example prompts for the agent
- Create a
Topicfor anorder-createdevent and attach a subscription that sends the confirmation email. - Set up an idempotent background handler with
at-least-oncedelivery. - Use
Attribute<string>andorderingAttributeto keep events for the same cart in order.
How to install encore-pubsub
1Skills CLI (Vercel)
npx skills add encoredev/skills --skill encore-pubsub -a claude-codenpx skills add encoredev/skills --skill pubsub -a claude-code2Manually: put the files in place
~/.claude/skills/pubsub/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/pubsub/
1Skills CLI (Vercel)
npx skills add encoredev/skills --skill pubsub -a codex2Manually: put the files in place
.agents/skills/pubsub/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add encoredev/skills --skill pubsub -a cursor2Manually: put the files in place
.cursor/skills/pubsub/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install encoredev/skills pubsub2Manually: put the files in place
.github/skills/pubsub/SKILL.md1Skills CLI (Vercel)
npx skills add encoredev/skills --skill pubsub -a gemini-cli2Platform CLI
gemini skills install https://github.com/encoredev/skills --path encore/pubsubManually: put the files in place
.devin/skills/pubsub/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add encoredev/skills --skill pubsub -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about encore-pubsub
How do I install encore-pubsub in Claude Code?
Run npx skills add encoredev/skills --skill encore-pubsub -a claude-code, then run npx skills add encoredev/skills --skill pubsub -a claude-code. The installed skill is available at ~/.claude/skills/pubsub/SKILL.md.
What does encore-pubsub do?
It guides asynchronous event messaging in Encore.ts through Topic and Subscription. The skill covers background handlers, fan-out, ordering, and delivery guarantees.
Why do subscription handlers need to be idempotent?
at-least-once delivery can send the same message more than once. A handler must therefore tolerate duplicate events safely.
Source text
SKILL.md · Apache-2.0
---
name: encore-pubsub
description: Asynchronous messaging in Encore.ts via `Topic` and `Subscription` from `encore.dev/pubsub` — broadcast events, decouple producers from consumers, and run background handlers.
when_to_use: >-
User wants to publish/broadcast events, fan out a single event to many handlers, fire-and-forget messages between services, react to something asynchronously, set up a worker that consumes events, configure delivery guarantees (at-least-once, exactly-once), or use ordering attributes. Trigger phrases: "publish an event", "broadcast", "subscribe to", "topic", "Pub/Sub", "pubsub", "event bus", "order_created event", "send to anyone listening", "background event handler", "queue", "fan out".
---
# Encore Pub/Sub
## Instructions
Pub/Sub is for asynchronous messaging between services. Producers publish events to a `Topic`; consumers attach `Subscription`s to react. Resources must be declared at package level — never inside functions.
## Topics
```typescript
import { Topic } from "encore.dev/pubsub";
interface OrderCreatedEvent {
orderId: string;
userId: string;
total: number;
}
// Package level declaration
export const orderCreated = new Topic<OrderCreatedEvent>("order-created", {
deliveryGuarantee: "at-least-once",
});
```
### Publishing
```typescript
await orderCreated.publish({
orderId: "123",
userId: "user-456",
total: 99.99,
});
```
### Subscriptions
```typescript
import { Subscription } from "encore.dev/pubsub";
const _ = new Subscription(orderCreated, "send-confirmation-email", {
handler: async (event) => {
await sendEmail(event.userId, event.orderId);
},
});
```
### Message Attributes
Use `Attribute<T>` for fields that should be treated as message attributes (for filtering/ordering):
```typescript
import { Topic, Attribute } from "encore.dev/pubsub";
interface CartEvent {
cartId: Attribute<string>; // Used for ordering
userId: string;
action: "add" | "remove";
productId: string;
}
// Ordered topic: events with same cartId delivered in order
export const cartEvents = new Topic<CartEvent>("cart-events", {
deliveryGuarantee: "at-least-once",
orderingAttribute: "cartId",
});
```
### Topic References
Pass topic access to other code while maintaining static analysis:
```typescript
import { Publisher } from "encore.dev/pubsub";
const publisherRef = orderCreated.ref<Publisher>();
async function notifyOrder(ref: typeof publisherRef, orderId: string) {
await ref.publish({ orderId, userId: "123", total: 99.99 });
}
```
## Delivery Guarantees
- `at-least-once` (default): may deliver duplicates → handlers must be idempotent.
- `exactly-once`: stricter, capped throughput (AWS 300 msg/s/topic, GCP 3000+ msg/s/region). Does not deduplicate on the publish side.
## Guidelines
- Topics and subscriptions must be declared at package level.
- Subscription handlers must be idempotent (at-least-once delivery is the default).
- Use `Attribute<T>` for fields meant for filtering/ordering, not for arbitrary metadata.
- Don't do heavy synchronous work in `publish` callers — `publish` returns once the message is queued.
© encoredev · Apache-2.0 · encoredev/skills