/protean:commandfrom protean
Defines Protean commands as immutable DTOs representing intent to change aggregate state. Use when implementing CQRS patterns or defining actions like PlaceOrder, RegisterUser.
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.
A command carries one request to change one aggregate, and exactly one command handler processes it. This skill defines commands: fields, naming, and how to submit them.
A command is defined using the @domain.command(part_of="...") decorator:
from protean import Domain
from protean.fields import String, Identifier
domain = Domain()
@domain.aggregate
class Order:
customer_id: String(required=True)
@domain.command(part_of="Order")
class PlaceOrder:
order_id: Identifier(required=True)
customer_id: String(required=True)
product_id: String(required=True)
part_of parameter with the aggregate namePlaceOrder, not OrderPlaceddomain.process(): The domain dispatches to the appropriate handler| Field/Option | Purpose | Required |
|---|---|---|
part_of | Associate command with an aggregate | Yes (unless abstract) |
abstract | Mark as abstract base command | No |
__version__ | Schema version as positive integer (defaults to 1) | No |
from protean.fields import (
String, Integer, Float, Boolean,
DateTime, Date, Identifier,
List, Dict, ValueObject,
)
Commands cannot use HasOne, HasMany, or Reference fields.
from protean import Domain, handle
from protean.fields import DateTime, Decimal, Identifier, String
domain = Domain()
@domain.aggregate
class Order:
order_id: Identifier(identifier=True)
customer_id: String(required=True)
total_amount: Decimal(precision=19, scale=4)
@domain.command(part_of="Order")
class PlaceOrder:
order_id: Identifier(required=True)
customer_id: String(required=True)
total_amount: Decimal(precision=19, scale=4, required=True)
# Register the handler before init(); one registered after is not wired
@domain.command_handler(part_of="Order")
class OrderCommandHandler:
@handle(PlaceOrder)
def place_order(self, command: PlaceOrder):
order = Order(
order_id=command.order_id,
customer_id=command.customer_id,
total_amount=command.total_amount,
)
domain.repository_for(Order).add(order)
domain.init(traverse=False)
# Create and submit command
with domain.domain_context():
command = PlaceOrder(
order_id="ORD-001",
customer_id="CUST-123",
total_amount=99.99
)
domain.process(command)
Commands are submitted to the domain for processing:
with domain.domain_context():
# Default processing (based on domain config, default is async)
domain.process(command)
# Explicit synchronous processing
domain.process(command, asynchronous=False)
# Explicit asynchronous processing
domain.process(command, asynchronous=True)
Domain-wide configuration:
# In domain.toml
# command_processing = "sync" # or "async"
# In code
domain.config["command_processing"] = "sync"
# fragment
@domain.command(part_of="Order")
class PlaceOrder:
items = HasMany(OrderItem) # Wrong! Commands can't contain entities
Instead: Only fields and value objects
@domain.value_object
class Money:
amount: Decimal(precision=19, scale=4, required=True)
currency: String(max_length=3, default="USD")
@domain.command(part_of="Order")
class PlaceOrder:
order_id: Identifier(required=True)
customer_id: String(required=True)
items: List() # Serialize as list of dicts
total = ValueObject(Money) # Value objects are allowed
# fragment
command = PlaceOrder(order_id="ORD-001", customer_id="CUST-123")
command.customer_id = "CUST-456" # Raises IncorrectUsageError!
Instead: Create a new command instance with the values you need.
check reportscheck inspects your commands and reports these diagnostics:
COMMAND_NOT_IMPERATIVE: the command is named in a mood that is not imperative (OrderPlacement), so it reads like data or an event. Rename it to a verb-first imperative phrase (PlaceOrder). If the name already starts with a verb Protean does not know (AdjustStock), add the verb to [lint].command_verbs in domain.toml instead of renaming.UNUSED_COMMAND: the command has no registered handler, so nothing processes it. Add a command handler method for it, or remove the command if it is unused.aggregate: Commands are always part of aggregatescommand-handler: How commands are processedevent: Commands and events are complementary (commands = intent, events = result)value-object: Commands can contain value objectscheck and resolve what it reportsassets/command_inheritance.py (opens in a new tab)assets/command_simple.py (opens in a new tab)assets/command_validation.py (opens in a new tab)assets/command_with_value_object.py (opens in a new tab)assets/submitting_commands.py (opens in a new tab)references/anti-patterns.md (opens in a new tab)references/command-inheritance.md (opens in a new tab)references/command-processing.md (opens in a new tab)references/command-validation.md (opens in a new tab)references/with-value-objects.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
39 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".npx claudepluginhub proteanhq/protean --plugin proteanOther plugins' skills for the same job