| name | contracts |
| description | Manage project contract registry. Subcommands: init (scan for shared types), list (show contracts), add (register new), sync (update producers/consumers). Used by /orchestrate for faster agent assignment. |
/contracts
Manage shared type contracts for multi-agent orchestration.
Subcommands
| Command | Purpose |
|---|
/contracts init | Scan project, find shared types, create registry |
/contracts list | Display contracts with producers/consumers |
/contracts add <name> | Add new contract to registry |
/contracts sync | Re-scan imports, update producer/consumer mappings |
/contracts init
Creates .claude/contracts.json by scanning project.
Steps
-
Scan type directories:
src/types/, src/dto/, src/contracts/, types/
-
Find shared types (imported by 2+ files):
Grep tool: pattern="import.*{.*TypeName.*}"
If importers >= 2 → shared contract
-
Trace producers/consumers:
- Producer: File that creates/returns the type
- Consumer: File that receives/uses the type
-
Generate registry:
{
"version": "1.0.0",
"updated": "2025-01-13",
"contracts": {
"UserDTO": {
"file": "src/types/user.ts",
"line": "3-15",
"producers": ["src/services/user.ts"],
"consumers": ["src/components/UserCard.tsx"]
}
}
}
-
Report: "Found X shared contracts in Y files"
/contracts list
Displays current registry in table format.
Output Format
Contracts Registry (.claude/contracts.json)
Updated: 2025-01-13
┌──────────────────┬────────────────────┬──────────────────┬──────────────────┐
│ Contract │ File │ Producers │ Consumers │
├──────────────────┼────────────────────┼──────────────────┼──────────────────┤
│ UserDTO │ src/types/user.ts │ services/user.ts │ UserCard.tsx │
│ CreateUserReq │ src/types/user.ts │ api/users.ts │ UserForm.tsx │
│ ProductDTO │ src/types/product │ services/product │ ProductList.tsx │
└──────────────────┴────────────────────┴──────────────────┴──────────────────┘
3 contracts registered
If No Registry
No registry found. Run /contracts init to create one.
/contracts add <name>
Add a new contract to registry manually.
Usage
/contracts add UserDTO
Steps
-
Prompt for file location:
Where is UserDTO defined? (e.g., src/types/user.ts)
-
Find line numbers:
Grep: pattern="interface UserDTO|type UserDTO"
-
Scan for imports:
Grep: pattern="import.*UserDTO"
-
Classify producers/consumers:
- If file has
return.*UserDTO or Promise<UserDTO> → producer
- Otherwise → consumer
-
Add to registry
-
Report: "Added UserDTO with 2 producers, 3 consumers"
/contracts sync
Re-scan imports and update producer/consumer mappings.
When to Use
- After adding new files that use existing contracts
- After refactoring imports
- Before running
/orchestrate
Steps
-
Read current registry
-
For each contract:
Grep: pattern="import.*{.*ContractName.*}"
-
Update producers/consumers
-
Report changes:
Sync complete:
- UserDTO: +1 consumer (NewComponent.tsx)
- ProductDTO: -1 producer (deleted OldService.ts)
- 2 contracts unchanged
Registry Schema
{
"version": "1.0.0",
"updated": "YYYY-MM-DD",
"contracts": {
"<ContractName>": {
"file": "path/to/definition.ts",
"line": "start-end",
"producers": ["path/to/producer1.ts", "path/to/producer2.ts"],
"consumers": ["path/to/consumer1.tsx", "path/to/consumer2.tsx"]
}
}
}
Integration with /orchestrate
When /orchestrate runs:
- Check for
.claude/contracts.json
- If exists: Skip Phase 1 (Discover), use registry
- Display: "Using registry: UserDTO, CreateUserReq"
- Assign agents based on producer/consumer files
- After completion: "Run /contracts sync to update registry"