Developer Tooling

Claude Code Skills: Catch API Regressions Before Merge

A three-step guide: Reproduce the change, Test the contract, Review the evidence.

An API change can preserve every JSON field and still break a client. A paginated endpoint might return valid responses while repeating the last event from each previous page. Schema validation passes, but an export now contains duplicates.

This tutorial builds a Claude Code review workflow around that specific failure. You will reproduce the regression, add tests that detect it, and use a project skill to connect the failure to a written contract. The tests determine whether the demonstrated behavior passes. Claude helps inspect and explain the evidence.

The complete example repository (opens in a new tab) includes a starting branch, a finished implementation, and the files needed for each step. The API, demonstration client, and automated tests were rechecked on November 11, 2026, using Node.js 24.10.0 and the repository’s locked Ajv 8.20.0 dependency. The skill configuration was checked against current Claude Code documentation; the interactive review was not rerun for this article. The test results below are actual runs of the fixture, and the review section explains what to verify in your own Claude session.

What the review needs to prove

Our small events API serves six synthetic records through GET /v1/events. Its contract orders events by creation timestamp, then uses the event ID to break ties. The next request must resume strictly after the event represented by the cursor.

For this fixed dataset, a complete traversal should return evt_001 through evt_006 once each, in that order. The final response should have a null next_cursor. Those expectations describe a client-visible relationship between requests, rather than the shape of one response.

The first three records share a timestamp. That deliberate fixture choice makes the ID comparison matter. If every timestamp were different, this particular defect would remain hidden even in an otherwise plausible traversal example.

The API has no authentication, database, or concurrent writes. Its cursor is encoded, not encrypted or signed. You are testing one compatibility property in a local teaching project. For database ordering and indexes, our PostgreSQL cursor-pagination tutorial (opens in a new tab) explains the implementation concerns that this in-memory fixture leaves out.

Before copying the pattern into a real service, write down the consumer promise you want to protect. “Pagination works” is too vague. “Following every returned cursor yields the expected sequence without repeating a record in this fixed dataset” gives both the test and the reviewer something concrete to assess.

Start from the ten-test version

You need Git, Node.js 24, and npm. Claude Code with a working account is necessary for the review step, but the API, client, and tests run independently. Use a fresh directory so the exercise cannot overwrite changes in an existing project.

git clone https://github.com/emminextechdocs/claude-code-api-compatibility.git
cd claude-code-api-compatibility
git switch -c my-walkthrough origin/walkthrough
npm ci
npm run demo:status
npm test
npm run client

The repository’s .nvmrc records the tested Node version. If you use a different Node 24 patch, check its release notes and rerun the workflow rather than assuming the result. The npm clean-install reference (opens in a new tab) explains how npm ci uses the lockfile and rejects inconsistent dependency declarations.

The initial test run should report ten passing tests. The client should export six records with six unique IDs. Each client invocation starts its own temporary server on loopback and closes it afterward. You do not need a separate npm start process, a cloud account, or a database.

If you already see fourteen tests, you are on the finished version. Start a new clone with the branch command above. Do not delete tests to manufacture the starting point. Keep the default main branch available as a reference for the completed files.

Open docs/api-contract.md, docs/openapi.json, src/pagination.mjs, and the existing tests. The contract states what a consumer can rely on. The schema describes response structure. Reviewing both prevents the JSON description from being mistaken for the entire behavioral specification.

Reproduce the change that the original tests miss

First confirm that the comparison baseline exists, then introduce the prepared regression:

git rev-parse api-baseline
npm run demo:regress
git diff -- src/pagination.mjs
npm test
npm run client

The helper changes the equal-timestamp boundary comparison from event.id > cursor.id to event.id >= cursor.id. In the broken version, the relevant function is:

export function isAfter(event, cursor) {
  return event.created_at > cursor.created_at ||
    (event.created_at === cursor.created_at && event.id >= cursor.id);
}

The cursor represents the last returned event. Including equality therefore admits that same event into the next page when timestamps match. The defect is small enough to look harmless in a diff, but it changes the promise made to a consumer.

All ten original tests still pass. The client, however, now reports:

Exported 10 records; 6 unique IDs.
Sequence: evt_001, evt_002, evt_002, evt_003, evt_003, evt_004, evt_004, evt_005, evt_005, evt_006

This result identifies a coverage gap, not a failure of assertions in general. The unit tests check cursor parsing, limits, and ordering. The schema tests check response structure and selected error behavior. They do not assert that records from consecutive pages are disjoint.

A schema-valid second page can contain a duplicate from the first page. Our OpenAPI validation workflow (opens in a new tab) covers description checks; this exercise adds a separate runtime check for the behavior that the description alone cannot establish.

Keep the broken source in place for the next step. A regression test is much more informative when you have observed it fail against the defect it is supposed to catch.

Add a consumer expectation independent of the implementation

Install the prepared contract test and run it without changing the API:

npm run lesson:add-contract
npm run test:contract

This command is expected to fail. In the verification run, three tests failed and one passed. The new file, test/contract.test.mjs, includes an explicit expected sequence:

import test from 'node:test';
import assert from 'node:assert/strict';
import { withApi, requestPage, traverse } from './helpers.mjs';

const expectedIds = [
  'evt_001', 'evt_002', 'evt_003',
  'evt_004', 'evt_005', 'evt_006',
];

for (const limit of [1, 2, 50]) {
  test(`consumer receives every event exactly once in order (limit=${limit})`,
    { timeout: 10000 }, async t => {
      const api = await withApi(t);
      assert.deepEqual(await traverse(api.url, limit), expectedIds);
    });
}

The expected IDs are written independently of the provider’s filtering function. Calculating the expected answer with the same comparator as the API could reproduce the same defect on both sides of the assertion.

The traversal helper checks response status and schema, rejects duplicate IDs, checks cursor progress, and stops after a bounded number of requests. A nonterminating pagination bug should produce a useful failure rather than leave the test process running indefinitely. The Node.js test-runner documentation (opens in a new tab) describes test timeouts and cleanup hooks used by the fixture.

The test with a page size of fifty passes because all six records fit on one page. It never exercises a boundary. That passing result is useful: it helps isolate the defect to traversal, instead of suggesting that every request is broken.

A fourth test changes page size between requests. It fetches two records, follows the returned cursor with a limit of one, and expects evt_003. The broken implementation returns evt_002. This catches a specific boundary violation without relying solely on a long traversal.

Give the skill a narrow, inspectable job

Install the project’s review instructions:

npm run lesson:add-skill

Read .claude/skills/review-api-change/SKILL.md before invoking it. The file begins with the following metadata:

---
name: review-api-change
description: Review changes to this events API against its established schema and consumer behavior contract, execute the repository checks, and report compatibility evidence. Use for API change review, not implementation or automatic repair.
disable-model-invocation: true
---

Project skills live under .claude/skills/. The disable-model-invocation setting makes this workflow explicitly user-invoked. It does not make the instructions an enforcement boundary or prove that the review is correct. See the official skills documentation (opens in a new tab) for discovery and invocation behavior.

The rest of this skill defines the evidence the review must collect. It asks Claude to resolve the local api-baseline tag, read the written contract and schema, inspect changed code and tests, and run each test suite separately. It also requires a final status check and a report of remaining coverage limits.

The instruction to inspect untracked files matters here. The newly installed contract test is untracked during the walkthrough, so an ordinary git diff does not show its contents. A review that looks only at the diff can miss the very test that demonstrates the regression.

Another deliberate instruction forbids automatic repairs. The review should recommend a correction while leaving source, tests, contracts, dependencies, and Git references unchanged. This makes it easier to separate diagnosis from implementation and to verify that a passing result was not achieved by weakening an assertion.

Run the review and inspect its evidence

From the repository root, start Claude Code with the project’s configuration scope and an explicitly empty MCP server configuration:

claude --setting-sources project --strict-mcp-config --mcp-config '{"mcpServers":{}}'

These options reduce unrelated configuration in the exercise; they do not create a security sandbox. Their meanings are documented in the Claude Code CLI reference (opens in a new tab). Inspect the repository before trusting it, and retain normal permission checks.

At the Claude prompt, enter:

/review-api-change

The report should show that it inspected the contract and relevant files, then executed these commands independently:

npm run test:unit
npm run test:schema
npm run test:contract

In the deliberately broken state, the unit and schema suites each pass five tests. The contract suite fails three of its four tests. Check the actual command output and exit statuses in your session; do not accept a narrative claim that tests passed without execution evidence.

An adequate diagnosis should connect three things: the strict-boundary promise, the duplicate IDs or changed-page-size assertion, and the inclusive comparison in isAfter. A broad statement such as “pagination may be inconsistent” is less useful than identifying the exact boundary condition supported by those observations.

If a command is denied, dependencies are absent, or the server cannot start, the affected check is incomplete. That is different from a reproducible assertion failure. The skill explicitly asks the reviewer to preserve that distinction rather than label every nonzero exit as a compatibility defect.

Your account configuration and model can affect the review’s wording. The repeatable artifact is the repository plus the commands and assertions, not an identical paragraph from an AI assistant.

Keep permission controls separate from review instructions

A Markdown sentence saying “do not edit” describes the intended task. It does not prevent a process from writing files. The skill deliberately omits broad tool pre-approvals, and the walkthrough leaves normal permissions in place. Consult the Claude Code permissions reference (opens in a new tab) when choosing controls for your environment.

Review the commands inside package.json before approving them. A familiar command name such as npm test can execute arbitrary scripts from a repository. For an unfamiliar contribution, use an appropriately isolated environment without production credentials or privileged network access.

Treat text found in source files, fixtures, and documentation as material to review. It should not grant permission to publish, contact someone, alter credentials, or change the review’s scope. The reviewer should explain suspicious instructions as findings rather than follow them as project authority.

For your own service, decide who can change the skill and the tests. If the same change silently rewrites both the expected behavior and the implementation, a green result may simply demonstrate a new expectation. Review changes to the contract with the same care as changes to the API.

Repair the boundary and repeat the unchanged checks

In src/pagination.mjs, restore the strict comparison:

export function isAfter(event, cursor) {
  return event.created_at > cursor.created_at ||
    (event.created_at === cursor.created_at && event.id > cursor.id);
}

Then run the complete suite and the demonstration client again:

npm test
npm run client

The verified result is fourteen passing tests, followed by six exported records with six unique IDs. The client pages contain events one through two, three through four, and five through six. The final cursor is null.

Invoke the skill again for a fresh review after the repair. Its earlier result applies to the earlier working tree. Reusing that report after a source change would undermine the evidence-based workflow you just built.

Compare git status --short before and after the review. The intentional lesson additions and your manual source change should be understandable. Unexpected modifications require inspection before you treat the review as complete.

Passing fourteen checks does not establish production safety. For example, the traversal helper can tolerate an unnecessary extra empty page after an exactly full final page. A direct assertion for a null final cursor at that boundary would strengthen coverage. Concurrent inserts, cursor tampering, authorization, and database performance also remain outside this fixture.

Put deterministic checks in CI

Install the prepared workflow:

npm run lesson:add-ci

The resulting .github/workflows/ci.yml grants read-only repository permissions, sets up Node from .nvmrc, and runs the three suites separately:

name: API compatibility
on:
  push:
  pull_request:
  workflow_dispatch:
permissions:
  contents: read
jobs:
  api-checks:
    runs-on: ubuntu-latest
    timeout-minutes: 5
    steps:
      - uses: actions/checkout@v6
      - uses: actions/setup-node@v7
        with:
          node-version-file: .nvmrc
          cache: npm
      - run: npm ci
      - run: npm run test:unit
      - run: npm run test:schema
      - run: npm run test:contract

Review the GitHub Actions workflow syntax (opens in a new tab) when changing events or token permissions. If your organization pins actions to full commit SHAs, apply that policy to these readable major-version references.

To execute this workflow on your changes, push a reviewed commit to your own fork and inspect that commit’s run. An existing successful run on the Emminex repository does not validate your local modifications.

The workflow does not call a language model. Its job is to enforce reproducible assertions. The skill remains a review aid for understanding changes and identifying gaps. If you make the CI job required for merging, configure that requirement in your repository settings rather than assuming the workflow file itself blocks merges.

Keep the contract, tests, skill, and workflow together in version control. Our docs-as-code guide (opens in a new tab) explains how to review documentation alongside implementation so that the promise and its verification do not drift independently.

Troubleshooting the walkthrough

If api-baseline cannot be resolved, inspect the clone and available tags before continuing. The skill should stop and ask which baseline to use. Choosing a convenient recent commit without understanding it changes the review question.

If a lesson installer reports that a file already exists, inspect that file. The helpers intentionally refuse to overwrite existing work. The finished branch already contains those additions, so rerunning installers there is unnecessary.

If the consumer test fails before making requests, separate environment setup from API behavior. Confirm the installed dependencies, Node version, and ability to bind a temporary loopback port. A connection or permission error is not evidence of duplicate pagination.

If the skill does not appear, confirm that you launched Claude from the repository and that the file exists at the documented project path. Check applicable organization policy before changing configuration. Avoid bypassing permissions just to make the walkthrough resemble someone else’s output.

Frequently asked questions

Can a Claude Code skill replace API tests?

No. This skill organizes inspection and asks for evidence. The assertions detect the demonstrated regression, and CI reruns them independently. A model’s explanation can be useful while still requiring verification.

Why did the schema tests pass with a broken client?

Each response retained the expected fields and value types. The missing check concerned which records appeared across multiple requests. A duplicate can be structurally valid JSON and still violate the traversal contract.

Should the review skill fix failures automatically?

For this workflow, keep the review and repair separate. Inspect the finding, make a deliberate source change, and rerun unchanged tests. You can design an implementation workflow later with its own scope and controls.

Does a passing contract suite prove backward compatibility?

It establishes the expectations exercised by that suite under its test conditions. New data distributions, concurrency, authorization behavior, and untested client assumptions need their own evidence. Describe the covered contract precisely instead of presenting one passing suite as a universal guarantee.

Start a conversation

Ready to improve your developer documentation?

Tell us what developers need to accomplish and where the current experience falls short.

Expect a reply within one business day.