gherkin-ai v3.2.2

Adopting gherkin-ai in an existing project

This guide is for teams that already have a code base, a CI pipeline and a release process, and want to add gherkin-ai without stopping delivery. It covers the order of adoption, what each step changes in the repository, and the gates to turn on along the way.

Upgrading a project that was generated with an earlier gherkin-ai version is a different task; see MIGRATION-3.2.md.

Choose how deep to go

gherkin-ai does not have to generate code to be useful. Pick the level that fits each service; different services in the same repository can sit at different levels.

Level You get You do not get Fits
1. Specifications and gates Linted .feature files, the semantic model, industry rules, delivery risk, the traceability graph, PR reports, MCP and the agent firewall Generated code Any stack, including stacks gherkin-ai does not generate
2. Contracts and agent prompts Level 1, plus OpenAPI / AsyncAPI, an ADR and agent prompts per feature, next to your code A runnable service A module you keep writing by hand, or with an agent
3. A generated service next to your code Level 2, plus a verified service: domain kernel, runtime kernel (PostgreSQL, outbox, inbox, sagas, tracing), HTTP layer, tests, Dockerfile, optional Terraform, Helm and CI — A new bounded context, or one you are extracting from a monolith

Most teams start with level 1 on one service, move the services they build next to level 3, and leave the rest at level 1.

0. No configuration: the governance commands only

Before any of the steps below, you can try level 1 on a repository as it is: no ghk init, no generated file.

# .github/workflows/specifications.yml: governance only, no gherkin-ai configuration in the repository
name: specifications
on: pull_request
jobs:
  gherkin-ai:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5
        with: { fetch-depth: 0 }
      - uses: actions/setup-node@v5
        with: { node-version: '24' }
      - run: npx -y gherkin-ai@3.2.2 lint --threshold 80
      - run: npx -y gherkin-ai@3.2.2 converge --openapi docs/openapi.json --threshold 80
      - run: npx -y gherkin-ai@3.2.2 risk --base origin/${{ github.base_ref }} --fail-on HIGH

tests/golden/brownfield.test.ts runs these commands on an Express and a Spring service in every CI run. When the team wants gherkin-ai's own contracts, architecture rules and industry profile, continue with step 1.

1. Install and pin

npm install --save-dev --save-exact gherkin-ai@3.2.2   # or a pinned global install on the build agents
npx ghk --version

2. Create the configuration

Commit what you have first: the commands below write files at the repository root.

ghk detect                   # detects the stack and writes gherkin-ai.config.json from it
ghk config show --sources    # check the result: which layer set each value

ghk detect reads the build files at the directory root: package.json, pom.xml / build.gradle(.kts) (including Quarkus, Micronaut and Ktor builds), go.mod, Cargo.toml, pyproject.toml / requirements.txt / manage.py, composer.json, Gemfile, mix.exs (Phoenix, and LiveView as its frontend), pubspec.yaml, and for .NET Program.cs, appsettings.json or a .csproj up to two directories down. It sets outputDir to ./generated-specs, so generated code never lands in your src/ or app/. For .NET it takes the database from the project's packages (PostgreSQL unless only SQL Server is referenced); the runtime kernel needs PostgreSQL. Edit the file for what cannot be detected:

{
  "$schema": "https://unpkg.com/gherkin-ai/schemas/config.schema.json",
  "projectName": "billing",
  "specDir": "./features",
  "outputDir": "./generated-specs",
  "architecture": "hexagonal",
  "stack": { "language": "java", "framework": "quarkus", "database": "postgres", "messaging": "rabbitmq" },
  "industry": { "id": "banking" }
}

3. Specify the behavior you already have

Start with one bounded context that changes often. Write features for what it does today (characterization), then for the change you are about to make.

ghk create                                  # guided, or write the .feature file by hand
ghk speckit import                          # if you already use GitHub Spec Kit (specs/NNN-*/spec.md)
ghk lint -f features/invoicing.feature
ghk lint --explain-ir -f features/invoicing.feature

4. Gate pull requests, then tighten

Add the gates in report-only form, read the results for a sprint, then make them blocking. The exit codes are stable across 3.x (ENTERPRISE.md §5).

# .github/workflows/specifications.yml
name: Specifications
on: [pull_request]
jobs:
  gherkin-ai:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
        with:
          fetch-depth: 0                  # ghk risk compares with the base branch
      - uses: actions/setup-node@v7
        with:
          node-version: 24
      - name: Specification quality, convergence and delivery risk on the pull request
        run: npx --yes gherkin-ai@3.2.2 report --provider github --base origin/${{ github.base_ref }} --threshold 70 --fail-on CRITICAL
      - name: Upgrade check
        run: npx --yes gherkin-ai@3.2.2 upgrade --check

ghk report writes annotations on the changed .feature lines and a job summary, with no token and no extra permission (--provider gitlab writes a Code Quality report for merge requests).

Gate Start Target Exit code when it fails
lint --threshold the current average score, rounded down 80 4
converge --threshold (level 3 services) report only 80 7
risk --fail-on CRITICAL HIGH, after calibrating the weights with ghk risk --calibrate --write on your history 4
upgrade --check from the start — 4 while required changes are pending

ghk init --enterprise writes a complete gate workflow (.github/workflows/gherkin-ai-gate.yml) if the repository has none. deploy with ci.provider generates full CI/CD pipelines for generated services (DEPLOYMENT.md).

5. Turn on the industry profile

If the service belongs to a regulated or standardized industry, opt in to its profile (INDUSTRIES.md):

ghk industry show banking          # standards, vocabulary, rules and agent guidance
ghk industry apply banking         # sets industry.id, writes .ghe/industry-context.*
ghk lint --all

On an existing specification set, expect the new rules to fire. Fix the errors first: they mark features that cannot be built safely as written, such as two BIAN Service Domains in one feature (GHK102) or PHI access without consent (GHK402). Disable a rule only with a reason and a date to remove the exception:

{ "industry": { "id": "banking", "disabledRules": ["GHK104"] } }

The profile also adds human-approval paths to the agent firewall (for banking: **/payments/**, **/ledger/**, **/*settlement*).

6. Bring in the agents, inside a perimeter

ghk mcp install                               # version-pinned, read-only MCP server for Cursor, Claude Desktop and others
ghk skill                                     # rules file for Cursor, Windsurf or GitHub Copilot
ghk implement -f features/invoicing.feature   # prompt and context package for one feature
ghk firewall policy -f features/invoicing.feature

7. Generate code next to the existing code (levels 2 and 3)

Level 2: contracts and prompts in an existing module

ghk add -f features/invoicing.feature -t src/invoicing

ghk add writes the feature's OpenAPI and AsyncAPI documents, an ADR, the agent prompts (prompts/) and a language-native contract when the stack has one. TypeScript and JavaScript projects also get a TypeScript contract and __tests__/<feature>.stub.spec.ts with one it.todo per step, reported as pending, never as passing. --target is required outside NestJS. Like generate, add keeps a file you edited and writes the new version next to it as <file>.ghk-new, and ghk upgrade never deletes what add wrote.

Level 3: a generated service

ghk generate -f features/invoicing.feature --dry-run   # what would be created, updated or kept
ghk generate -f features/invoicing.feature

Verify against real infrastructure

ghk verify                  # the project's tests
ghk verify --docker         # in the stack's toolchain image: no network, read-only root, dependency caches
ghk verify --services       # also the runtime integration suite (IT1–IT7) against PostgreSQL 17 and the broker
ghk converge --threshold 80

8. Roles

Role Owns Commands
Product owner, business analyst The .feature files: scenarios, vocabulary, failure paths create, lint, speckit import
Developers Tags that name the model, implementation of pending steps, .ghk-new reviews lint --explain-ir, generate, implement, verify, graph
QA Scenario coverage, negative paths, the integration suite converge, verify --services, graph --trace
Platform team Pinned version, organization layer, CI gates, deployment targets config, report, upgrade --check, deploy
Security and compliance Industry profile, firewall approval paths, audit trail industry, firewall, audit export

9. Rollout checklist

Pilot (one service, two to four weeks):

Team:

Organization:

What to expect, and what not