/protean:message-enrichmentfrom protean
Attaches cross-cutting metadata (tenant IDs, request/correlation context, actor info, audit data) to Protean commands and events via command enrichers, event enrichers, and aggregate enrichers. Useful for injecting context into messages without polluting payloads.
Ships in protean. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Enrichers attach cross-cutting context to messages. A command enricher runs as a
command is processed; an event enricher runs as an aggregate raises an event. Each
returns a dict that is merged into the message's metadata.extensions, so the data
travels with the message (through serialization and the event store) without bloating
the payload.
An aggregate enricher is the third kind. It does not touch messages. It runs just
before an aggregate is saved and sets fields on the aggregate itself, such as
updated_by or created_by.
from protean import Domain, g
domain = Domain()
# Command enricher: receives the command, returns a dict
@domain.command_enricher
def add_request_context(command):
return {"request_id": getattr(g, "request_id", None)}
# Event enricher: receives the event AND the aggregate, returns a dict
@domain.event_enricher
def add_tenant_context(event, aggregate):
return {"tenant_id": getattr(g, "tenant_id", None)}
# Aggregate enricher: receives the aggregate, sets fields on it, returns nothing
@domain.aggregate_enricher
def stamp_updated_by(aggregate):
if hasattr(aggregate, "updated_by"):
aggregate.updated_by = g.get("current_user")
def fn(command) -> dict. Event enricher: def fn(event, aggregate) -> dict (it also gets the aggregate, so it can read aggregate state). Aggregate enricher: def fn(aggregate) -> None@domain.command_enricher / @domain.event_enricher / @domain.aggregate_enricher. For reusable functions, use domain.register_command_enricher(fn) / domain.register_event_enricher(fn) / domain.register_aggregate_enricher(fn)None): The returned dict is merged into metadata.extensions. Returning None or {} is a no-op. An aggregate enricher sets fields on the aggregate instead, and its return value is ignoredpart_of an aggregate; they run for every command (or every event) in the domaing) and returns data. It must not change the message, load aggregates, or perform I/O. An aggregate enricher sets fields on the aggregate it receives, and it also must not load aggregates or perform I/Ogetattr(g, "key", None)aggregate.raise_(), before the event is appended (and they also run for fact events); aggregate enrichers run whenever an aggregate is saved, on both create and update, including through update() and QuerySet.update(). They never run on the records the framework saves for itself, such as outbox rows. An enricher skips any aggregate that does not declare the field it stampsupdated_at, updated_by and created_by. Do not enforce rules or raise events in them; that belongs in the aggregate's methods. They do not run for event-sourced aggregates, or for a save that passes apply_hooks=False# fragment
command._metadata.extensions # after command enrichment
event._metadata.extensions # after event enrichment
# Downstream, handlers/projectors read it via:
# g.message_in_context.metadata.extensions
# An aggregate enricher writes to the aggregate's own fields
from protean import Domain, g
domain = Domain()
@domain.command_enricher
def command_audit(command):
return {
"request_id": getattr(g, "request_id", None),
"actor_id": getattr(g, "actor_id", None),
}
@domain.event_enricher
def event_audit(event, aggregate):
return {
"tenant_id": getattr(g, "tenant_id", None),
"aggregate_type": type(aggregate).__name__,
}
@domain.aggregate
class Order:
customer_id: String(required=True)
created_by: String()
updated_by: String()
@domain.aggregate_enricher
def stamp_audit(aggregate):
if not hasattr(aggregate, "updated_by"): # an aggregate without audit fields
return
user = g.get("current_user")
aggregate.updated_by = user
if aggregate.created_by is None: # set once, on create
aggregate.created_by = user
domain.init(traverse=False)
# Put the acting user on the context so the aggregate enricher can read it
with domain.domain_context(current_user="alice"):
order = Order(customer_id="c-1")
domain.repository_for(Order).add(order)
assert order.created_by == "alice"
Extensions are for cross-cutting metadata (tenant, request, actor), not domain payload. Domain data belongs in the command/event fields.
# fragment
domain.register_event_enricher(some_dict) # Wrong! Not callable
Registering anything that is not callable raises IncorrectUsageError with code
USAGE_ENRICHER_NOT_CALLABLE.
command / command-handler: Commands that enrichers annotateevent / event-handler: Events that enrichers annotateaggregate: Event enrichers receive the aggregate raising the eventcheck and resolve what it reportsWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub proteanhq/protean --plugin protean39 skills in this plugin
/add-commandAdd a complete command flow to an existing aggregate. It creates a command class, a FastAPI API endpoint, and a command handler with repository logic. This is the primary workflow for adding write operations to a Protean domain. Use when the user wants to "add a command", "add an action", "add an operation", "expose a write endpoint", "create a command flow", "wire up a POST endpoint", "add a new operation to an aggregate", or describes an action like "I want users to be able to [verb] a [thing]" (e.g., "place an order", "register a user", "cancel a reservation"). This workflow composes the command, command-handler, and api-endpoint element skills./add-domain-service-flowBuild a domain service flow in Protean for business logic that spans two or more aggregates. Domain services are stateless, encapsulate cross-aggregate business rules, and run pre/post invariants for validation. They are used when business logic doesn't naturally belong to a single aggregate. Wire them into command handlers or application services for persistence. Use when the user asks to "add a domain service", "implement cross-aggregate logic", "coordinate multiple aggregates", "add a business operation spanning aggregates", "validate across aggregates", or when they describe scenarios like "placing an order checks inventory and reserves stock", "transferring funds between accounts", "scheduling involves both resource and calendar"./add-eventAdd a complete event flow to an existing aggregate. It creates a domain event, adds or updates an aggregate method that raises the event via self.raise_(), and wires an event handler that processes the event and performs specified side effects (such as syncing state across aggregates, sending notifications, or triggering downstream processes). This is the primary workflow for adding reactive, event-driven behavior to a Protean domain. Use when the user wants to "add an event", "add a domain event", "add a reaction to a state change", "add a side effect", "create an event flow", "wire an event handler", "add event-driven behavior", "react to a state change", "sync aggregates on event", or describes something that happened or should happen (like "when an order is placed, reduce inventory", "after payment is confirmed, send a notification", "when a user registers, create a welcome email", "notify the warehouse when an order ships"). This workflow composes the event, aggregate, and event-handler element skills./add-fieldAdd fields to Protean domain elements (aggregates, entities, value objects). Guides you through selecting the right field type, configuring validations, and placing fields correctly. Use when the user asks to "add a field", "add an attribute", "add a property", "I need to store [data]", "add a new field to [aggregate/entity]", or describes data that needs to be tracked. Covers simple fields, association fields (HasOne, HasMany, ValueObject), field validation, custom validators, and choosing between field types for different use cases./add-read-modelBuild a complete read model in Protean, a projection populated by a projector that reacts to domain events. Covers single-aggregate projections (flattened view of one aggregate), cross-aggregate projections (combining data from multiple aggregates), and choosing between database-backed and cache-backed storage. Use when the user asks to "add a read model", "create a projection with projector", "build a query view", "add a CQRS read side", "create a denormalized view", "build a reporting view", "add a dashboard query model", or when they need to combine data from multiple aggregates into one queryable structure./add-saga-flowBuild a complete saga in Protean using a process manager that coordinates a multi-step flow across several aggregates. The saga reacts to domain events, issues commands to drive each aggregate forward, tracks its own state, and closes on a terminal handler with a compensating path for failures. Use when the user asks to "add a saga", "coordinate a multi-step process", "orchestrate a workflow across aggregates", "manage order fulfillment", "add a process manager flow", "compensate on failure", "roll back a distributed transaction", or when they describe a flow like "reserve stock, take payment, then ship, and undo the reservation if payment fails".Other plugins' skills for the same job