ContractSpec CLI
Command-line interface for creating, building, and validating contract specifications with AI-powered code generation.
Installation
bun add contractspec -DQuick Start
# Initialize project
bunx contractspec init
# Create a spec
contractspec create --type operation
# Generate code
contractspec build src/contracts/mySpec.ts
# Validate
contractspec validate src/contracts/mySpec.tsCommands
create
Interactive wizard to create contract specifications
contractspec create [--type operation] [--ai]build
Generate implementation code from contract specs using AI agents
contractspec build <spec-file> [--agent-mode claude-code]validate
Validate contract specifications and implementations
contractspec validate <spec-file> [--check-implementation]list
List all contract specifications in the project
contractspec list [--type operation] [--json]watch
Watch specs and auto-regenerate on changes
contractspec watch [--build] [--validate]sync
Sync contracts by building all discovered specs
contractspec sync [--dry-run]ci
Run all validation checks for CI/CD pipelines
contractspec ci [--format sarif] [--output results.sarif]deps
Analyze contract dependencies and relationships
contractspec deps [--circular] [--format dot]diff
Compare contract specifications and show differences
contractspec diff <spec1> <spec2> [--breaking]AI Agent Modes
The CLI supports multiple AI agent modes for different use cases:
simple
Direct LLM API calls, fast and straightforward. Best for rapid prototyping.
claude-code
Extended thinking with Claude. Best for production-quality code.
openai-codex
GPT-4o/o1 models. Excellent for algorithms and optimization.
cursor
Leverages Cursor agentic capabilities. Requires Cursor environment.
CI/CD Integration
Run all validation checks in CI/CD with machine-readable output:
- name: Validate Contracts
run: contractspec ci --format sarif --output results.sarif
- name: Upload SARIF
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: results.sarifConfiguration
Create a .contractsrc.json file in your project root:
{
"aiProvider": "claude",
"agentMode": "claude-code",
"outputDir": "./src",
"conventions": {
"operations": "interactions/commands|queries",
"events": "events"
}
}