Skip to content

CLI Commands

All commands read from contractual.yaml in the current directory.


All commands support these flags:

FlagAliasDescription
--help-hShow help for command
--versionShow CLI version
--yes-ySkip interactive prompts, use defaults
--interactiveForce interactive mode (even in CI)
--jsonOutput as JSON (implies --yes)
--quiet-qMinimal output
--verbose-vDetailed output
--config-cPath to contractual.yaml (default: auto-detect)

Scan the project for spec files and generate the initial configuration.

Terminal window
contractual init [options]
OptionAliasDescriptionDefault
--dir <path>Root directory to scan.
--initial-version-VInitial version for contracts0.0.0
--versioningVersioning mode: independent or fixedindependent
--force-fReinitialize even if config existsfalse
--format <fmt>Output format: text or jsontext

What it does:

  • Scans for OpenAPI and JSON Schema files
  • Creates contractual.yaml with detected contracts
  • Creates .contractual/ directory with initial snapshots
terminal
$ contractual init

Scanning for contract specs...

Detected specs
  openapi      api/openapi.yaml
  json-schema  schemas/user.schema.json

Created contractual.yaml
Created .contractual/
Wrote snapshots for 2 contract(s)

Validate specs against their format specification.

Terminal window
contractual lint [contracts...] [options]
OptionDescriptionDefault
--contract <name>Lint only named contract(s)All
--fixAuto-fix issues where possibleOff
--format <fmt>Output format: text, json, or stylishtext
terminal
$ contractual lint

Linting contracts...

payments-api  (openapi)
  [error]  oas3-api-servers  No servers defined  api/openapi.yaml:1
  user-schema  (json-schema)  No violations

1 contract(s) passed, 1 contract(s) have errors.

Show all changes between current specs and their last versioned snapshots, classified by severity.

Terminal window
contractual diff [contracts...] [options]
OptionAliasDescriptionDefault
--contract <name>Diff only named contract(s)All
--base-bCompare against specific versionLatest
--format <fmt>Output format: text, json, or markdowntext
--severity <level>Filter: all, breaking, non-breaking, patchall
--verboseShow JSON Pointer paths for each changeOff

Unlike breaking, which exits 1 if breaking changes exist, diff is informational—it always exits 0 and shows every change.

terminal
$ contractual diff

orders-api: 3 changes (2 breaking, 1 non-breaking) — suggested bump: major

BREAKING     Removed endpoint GET /orders/{id}/details
BREAKING     Changed type of field 'amount': string → number
non-breaking  Added optional field 'tracking_url'

order-schema: no changes

Compare specs against snapshots and exit 1 if breaking changes are found. This is the CI gate command.

Terminal window
contractual breaking [--contract <name>] [--format <fmt>] [--base <ref>]
OptionDescriptionDefault
--contract <name>Check only named contract(s)All
--format <fmt>Output format: text or jsontext
--base <ref>Snapshot tag or git ref to compare againstLatest
terminal
$ contractual breaking

Comparing contracts against last snapshot...

payments-api  (openapi)
  [breaking]      DELETE /v1/charges/{id}  Endpoint removed
  [non-breaking]  GET /v1/charges          Response field `metadata` added

user-schema  (json-schema)
  No changes detected.

1 breaking change(s) found.

Create a changeset file for detected changes.

Terminal window
contractual changeset [options]
OptionDescriptionDefault
--no-interactiveAuto-generate without promptsOff
--emptyCreate changeset with no spec changesOff
--messageChangeset summary (skip prompt)Interactive
terminal
$ contractual changeset

Detected changes in payments-api (openapi):
  [breaking]      DELETE /v1/charges/{id}  Endpoint removed

? Bump type for payments-api: (major)
? Summary: Remove deprecated endpoint

Wrote .contractual/changesets/fuzzy-lion-dances.md

Consume changesets and bump versions.

Terminal window
contractual version [options]
OptionDescriptionDefault
--dry-runPreview without writing filesOff
--no-changelogSkip CHANGELOG.md updateOff
--no-gitSkip git operationsOff
--preidPre-release identifier overrideFrom pre.json
terminal
$ contractual version

Reading changesets...
fuzzy-lion-dances.md   →  payments-api  major

Resolved bump types:
payments-api   1.4.2  →  2.0.0  (major)

Snapshotting specs...
  .contractual/snapshots/payments-api@2.0.0.yaml

Updated .contractual/versions.json
Updated CHANGELOG.md
Deleted 1 changeset file(s)

Done. Commit these changes to complete the release.

Show current versions and pending changesets.

Terminal window
contractual status [options]
OptionDescriptionDefault
--format <fmt>Output format: text or jsontext
--pendingShow only contracts with pending changesOff
terminal
$ contractual status

Contract Versions
─────────────────────────────────────────────────────
payments-api   v1.4.2  →  v2.0.0  (major pending)
user-schema    v0.9.1    up to date

Pending changesets (1):
fuzzy-lion-dances.md
  contracts: payments-api  bump: major

Run `contractual version` to apply these changesets.

Manage contracts in the project. See Contract Management for full documentation.

Terminal window
contractual contract add # Add a new contract
contractual contract list # List all contracts
contractual contract remove # Remove a contract

Manage pre-release versions. See Pre-release Versioning for full documentation.

Terminal window
contractual pre enter <tag> # Enter pre-release mode (alpha, beta, rc)
contractual pre exit # Exit pre-release mode
contractual pre status # Show pre-release state

CodeMeaningCommands
0SuccessAll
1Breaking changes or lint errors foundlint, breaking, status
2Configuration errorAll
3Tool execution errorlint, breaking
4User cancelled operationInteractive commands

See Exit Codes for detailed explanations.