Agent skill

Counterfact Repl

by counterfact in counterfact/api-simulator

Interact with Counterfact mock API server programmatically. An agent skill from counterfact/api-simulator.

MITAuto-check passedBackend & APIs

Install Counterfact Repl

skills CLI
$ npx skills add counterfact/api-simulator --skill counterfact-repl -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install counterfact/api-simulator counterfact-repl --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/counterfact/api-simulator.git skills-src && mkdir -p .claude/skills && cp -r skills-src/skills/counterfact-repl .claude/skills/counterfact-repl && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
counterfact-repl
GitHub stars
170
Token cost
~3.2k tokens
SKILL.md length
906 words
Files
2
Skills in repo
12
Repo updated
First seen
Licence
MIT

At a glance

Interact with Counterfact mock API server programmatically. An agent skill from counterfact/api-simulator.

  • Works in 5 steps: Check for health endpoint (most reliable) → Look for package.json → Check for routes directory → …
  • The user mentions counterfact
  • SKILL.md covers Purpose, What is Counterfact?, When to Use This Skill and Detecting Counterfact, plus 5 more sections
  • Reaches api.production.com; needs COUNTERFACT_ADMIN_API_TOKEN

What it does

Counterfact Repl is an agent skill from counterfact/api-simulator. Interact with Counterfact mock API server programmatically. Inspect and modify context state, configure proxy settings, test endpoints, and control mock behavior. Use when the user mentions "counterfact", "mock server", "REPL", testing APIs, or working with OpenAPI mocks.

Its SKILL.md is about 3.2k tokens, which your agent loads only when the skill is triggered. The skill folder holds 1 other file (for example `examples.md`).

It sits in Backend & APIs, covering OpenAPI specifications. It works with OpenAPI, TypeScript and JavaScript. The repository describes itself as: Turn an OpenAPI spec into a local API in one command. Build and test your frontend with custom responses, shared state, and simulated failures, without waiting for the backend. The licence is MIT.

When your agent uses it

  • The user mentions counterfact
  • Working with OpenAPI mocks

Example prompts

  • “counterfact”
  • “mock server”
  • “/counterfact-repl”

Requirements

  • Node.js
  • A credential in COUNTERFACT_ADMIN_API_TOKEN

Workflow steps

5 steps, taken from the first numbered list in SKILL.md.

  1. Check for health endpoint (most reliable)
  2. Look for package.json
  3. Check for routes directory
  4. Check for OpenAPI spec
  5. Try alternate ports

What it can do on your machine

Read from SKILL.md and the folder at commit 0508aef. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are http, json, javascript and typescript).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    Hosts in commands or code, which the agent is likely to contact:

    • api.production.com

    Also links to:

    • counterfact.dev
    • github.com

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names these keys or tokens, usually read from environment variables:

    • COUNTERFACT_ADMIN_API_TOKEN

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Counterfact Repl loads about 3.2k tokens when it runs. Until then it costs about 72 tokens; SKILL.md has 906 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~72
When it runs · the whole SKILL.md, loaded when a task matches
~3.2k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from counterfact/api-simulator at commit 0508aef, republished under its MIT licence (© counterfact). 906 words, ~3,215 tokens.

Download SKILL.mdSave it as .claude/skills/counterfact-repl/SKILL.md (or your agent's skills folder). This skill also uses 1 other file; get the full folder from GitHub.
name
counterfact-repl
description
Interact with Counterfact mock API server programmatically. Inspect and modify context state, configure proxy settings, test endpoints, and control mock behavior. Use when the user mentions "counterfact", "mock server", "REPL", testing APIs, or working with OpenAPI mocks.
applyTo
**/*.{yaml,yml,json}, **/routes/**/*.{ts,js}, **/*context.{ts,js}

Counterfact REPL Skill

Purpose

This skill enables AI agents to interact with a running Counterfact mock server through its Admin API. Counterfact provides programmable API mocks based on OpenAPI specifications, with a REPL for runtime manipulation. This skill exposes those capabilities programmatically via HTTP endpoints.

What is Counterfact?

Counterfact is a contract-driven mock API server that:

  • Generates mock endpoints from OpenAPI specifications
  • Provides a JavaScript REPL for runtime state manipulation
  • Allows programmable behavior (not just static responses)
  • Supports context objects for storing mock state
  • Enables proxy mode to route requests to real APIs selectively

The REPL lets developers manipulate mock state in real-time using JavaScript. This skill exposes the same capabilities via HTTP API.

When to Use This Skill

Invoke this skill when the user:

  • Mentions "counterfact", "mock server", "REPL", or "OpenAPI"
  • Wants to test or develop against a mock API
  • Needs to inspect or modify mock server state
  • Wants to configure proxy vs. mock routing
  • Needs to simulate API failures or edge cases
  • Says things like:
    • "Add data to the mock"
    • "Change the mock state"
    • "Make the API return an error"
    • "Proxy this endpoint to the real server"
    • "What data is in the mock store?"
    • "Simulate a service failure"

Detecting Counterfact

To determine if Counterfact is running, check in this order:

  1. Check for health endpoint (most reliable):

    http
    GET http://localhost:3100/_counterfact/api/health

    If successful, Counterfact is running on port 3100.

  2. Look for package.json:

    • Check if counterfact is in dependencies or devDependencies
    • Read scripts to find the port (e.g., --port 3000)
  3. Check for routes directory:

    • Look for routes/ or api/routes/ directory
    • TypeScript/JavaScript files matching OpenAPI paths
  4. Check for OpenAPI spec:

    • Files matching *.yaml, openapi.yaml, swagger.yaml
    • Look for openapi: or swagger: in content
  5. Try alternate ports:

    • Port 3100 (default)
    • Port 3000 (common alternative)
    • Check environment variables or config files

Admin API Endpoints

All Admin API endpoints are prefixed with /_counterfact/api/

Health Check

Request:

http
GET /_counterfact/api/health

Response:

json
{
  "status": "ok",
  "port": 3100,
  "uptime": 123.45,
  "basePath": "/path/to/routes",
  "prefix": ""
}

Use when: Checking if server is running, getting server info.


List All Contexts

Request:

http
GET /_counterfact/api/contexts

Response:

json
{
  "success": true,
  "data": {
    "paths": ["/", "/pets", "/users"],
    "contexts": {
      "/": { "rootProperty": "value" },
      "/pets": { "pets": [...] },
      "/users": { "users": [...] }
    }
  }
}

Use when: Discovering what contexts exist, getting overview of all state.


Get Specific Context

Request:

http
GET /_counterfact/api/contexts/{path}

Example:

http
GET /_counterfact/api/contexts/pets

Response:

json
{
  "success": true,
  "data": {
    "path": "/pets",
    "context": {
      "pets": [
        { "id": 1, "name": "Fido" },
        { "id": 2, "name": "Whiskers" }
      ]
    }
  }
}

Use when: Inspecting state for a specific API path.


Update Context

Request:

http
POST /_counterfact/api/contexts/{path}
Content-Type: application/json

{
  "property": "newValue",
  "arrayProperty": [...]
}

Example:

http
POST /_counterfact/api/contexts/pets
Content-Type: application/json

{
  "pets": [
    { "id": 1, "name": "Fido" },
    { "id": 2, "name": "Whiskers" },
    { "id": 3, "name": "Rex" }
  ]
}

Response:

json
{
  "success": true,
  "message": "Context updated for path: /pets",
  "data": {
    "path": "/pets",
    "context": { "pets": [...] }
  }
}

Use when: Adding data, modifying state, simulating conditions.

Important: The update uses smart diffing - only changed properties are updated, preserving methods and other properties.


Get Full Configuration

Request:

http
GET /_counterfact/api/config

Response:

json
{
  "success": true,
  "data": {
    "alwaysFakeOptionals": false,
    "basePath": "/path/to/routes",
    "buildCache": false,
    "generate": { "routes": true, "types": true },
    "openApiPath": "/path/to/openapi.yaml",
    "port": 3100,
    "proxyUrl": "",
    "prefix": "",
    "startRepl": true,
    "startServer": true,
    "watch": { "routes": true, "types": true },
    "proxyPaths": []
  }
}

Use when: Getting full server configuration.


Get Proxy Configuration

Request:

http
GET /_counterfact/api/config/proxy

Response:

json
{
  "success": true,
  "data": {
    "proxyUrl": "https://api.example.com",
    "proxyPaths": [
      ["/api/users", true],
      ["/api/posts", false]
    ]
  }
}

Use when: Checking what paths are proxied vs. mocked.


Update Proxy Configuration

Request:

http
PATCH /_counterfact/api/config/proxy
Content-Type: application/json

{
  "proxyUrl": "https://api.example.com",
  "proxyPaths": [
    ["/api/users", true],
    ["/api/posts", false]
  ]
}

Response:

json
{
  "success": true,
  "message": "Proxy configuration updated",
  "data": {
    "proxyUrl": "https://api.example.com",
    "proxyPaths": [
      ["/api/users", true],
      ["/api/posts", false]
    ]
  }
}

Use when: Switching between mock and real API, testing integration.

Notes:

  • proxyUrl is the base URL to proxy to
  • proxyPaths is an array of [path, enabled] tuples
  • Path of "" or "/" enables proxy globally
  • Setting path true routes to real API, false uses mock

List All Routes

Request:

http
GET /_counterfact/api/routes

Response:

json
{
  "success": true,
  "data": {
    "routes": [
      {
        "path": "/pets",
        "methods": {
          "GET": true,
          "POST": true
        }
      },
      {
        "path": "/pets/{id}",
        "methods": {
          "GET": true,
          "PUT": true,
          "DELETE": true
        }
      }
    ]
  }
}

Use when: Discovering available endpoints, understanding API structure.


Common Usage Patterns

Pattern 1: Inspect Current State

User request: "What pets are in the store?"

Agent workflow:

1. GET /_counterfact/api/health
   → Confirm server running

2. GET /_counterfact/api/contexts/pets
   → Retrieve pets array

3. Present formatted list to user

Example response:

Currently in the pet store:
- ID 1: Fido
- ID 2: Whiskers

Pattern 2: Add Test Data

User request: "Add a new pet named Rex with ID 3"

Agent workflow:

1. GET /_counterfact/api/contexts/pets
   → Get current pets

2. Append new pet to array

3. POST /_counterfact/api/contexts/pets
   Body: { "pets": [...existingPets, newPet] }
   → Update context

4. Verify by GETting /pets endpoint
   → Confirm change visible in API

Pattern 3: Simulate Failure

User request: "Make the user service unavailable"

Agent workflow:

1. POST /_counterfact/api/contexts/users
   Body: { "serviceAvailable": false }
   → Set failure flag

2. Explain that route handlers should check this flag

3. Optionally: Test GET /users to verify error

Note: The route handler must be coded to check context.serviceAvailable. The skill sets the flag, but behavior depends on route implementation.


Show full SKILL.md (365 more words)Show less
Pattern 4: Switch to Proxy Mode

User request: "Route /orders to the real API"

Agent workflow:

1. GET /_counterfact/api/config/proxy
   → Check current proxy settings

2. PATCH /_counterfact/api/config/proxy
   Body: {
     "proxyUrl": "https://api.production.com",
     "proxyPaths": [["/orders", true]]
   }
   → Enable proxy for /orders

3. Confirm that /orders now hits real server

Pattern 5: Batch Data Setup

User request: "Set up test data: 3 users and 5 products"

Agent workflow:

1. Create users array with test data

2. POST /_counterfact/api/contexts/users
   Body: { "users": [...testUsers] }

3. Create products array with test data

4. POST /_counterfact/api/contexts/products
   Body: { "products": [...testProducts] }

5. Confirm setup complete

Error Handling

Server Not Running

If health check fails:

❌ Error: Counterfact server not running
Suggestion: Start the server with: npx counterfact openapi.yaml
Context Not Found

If context doesn't exist:

GET /_counterfact/api/contexts/nonexistent
→ Returns: { "path": "/nonexistent", "context": {...} }

Note: Contexts are hierarchical. If /api/users doesn't exist, it returns parent context.

Invalid JSON

If request body is malformed:

← 400 Bad Request
{ "success": false, "error": "Request body must be a valid JSON object" }
Server Error

If internal error occurs:

← 500 Internal Server Error
{
  "success": false,
  "error": "Error message",
  "stack": "..." // Only in development
}

Advanced Techniques

Hierarchical Contexts

Contexts are hierarchical. If you have:

/               → root context
/api            → api context
/api/users      → users context

Then GET /_counterfact/api/contexts/api/users/123 returns the /api/users context (closest parent).

Smart Diffing

Context updates use smart diffing:

javascript
// Old context: { users: [...], count: 5 }

POST { users: [...newUsers] }
// Result: { users: [...newUsers], count: 5 }
//         count is preserved
Testing Proxied Requests

After setting proxy:

1. PATCH /_counterfact/api/config/proxy
   Body: { "proxyPaths": [["/users", true]] }

2. Make request to http://localhost:3100/users
   → This now proxies to real server

3. Check response headers for proxy evidence

Limitations

  1. In-memory state: Changes reset on server restart
  2. No TypeScript validation: Context can accept any JSON object
  3. No authentication: Admin API is unauthenticated (local development tool)
  4. No versioning: API is v1, may evolve
  5. Context discovery: Must know or discover paths, no automatic schema

Security Considerations

⚠️ Warning: The Admin API provides full control over mock server state.

Recommendations:

  • Only run Counterfact in development/testing environments
  • Do not expose the Admin API to untrusted networks
  • Configure a bearer token when exposing the Admin API beyond local development
  • Be cautious with context updates from untrusted sources

Current access controls:

  • By default, the Admin API only listens on the loopback interface (localhost)
  • You can require a bearer token for all Admin API requests:
    • CLI flag: --admin-api-token <TOKEN_VALUE>
    • Environment variable: COUNTERFACT_ADMIN_API_TOKEN=<TOKEN_VALUE>
  • When a token is configured, clients must send:
    • HTTP header: Authorization: Bearer <TOKEN_VALUE>

Integration with OpenAPI

The skill works best when paired with OpenAPI understanding:

  1. Read the OpenAPI spec to understand available paths
  2. Map OpenAPI paths to context paths
  3. Use OpenAPI schemas to validate context updates
  4. Generate realistic test data based on OpenAPI examples

Example:

1. Read openapi.yaml
2. Find path /pets with schema: { id: number, name: string }
3. Generate test data: { id: 1, name: "Fido" }
4. POST /_counterfact/api/contexts/pets with test data

Troubleshooting

Issue: Health check returns 404

Solution: Server may not have Admin API. Update to latest Counterfact version.


Issue: Context update doesn't affect API responses

Solution: Check route handler implementation. It must read from $.context.

Example route handler:

typescript
export const GET: HTTP_GET = ($) => {
  return $.response[200].json($.context.pets);
};

Issue: Proxy not working

Solution:

  • Verify proxyUrl is set: GET /_counterfact/api/config/proxy
  • Check path is enabled: proxyPaths array
  • Ensure path matches exactly (case-sensitive)

See Also

© counterfact, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 1 other file in skills/counterfact-repl of counterfact/api-simulator.

  • SKILL.md
  • examples.md

Open the folder on GitHubat commit 0508aef

Compare with similar skills

Counterfact Repl next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Counterfact Repl compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Counterfact Repl this skillcounterfact/api-simulator170—~3.2kAutomated safety check: PassMIT
API Breaking Change Detectorgithub/awesome-copilot40k—~1.7kAutomated safety check: PassMIT
OpenAPI to MCP Servermcp-use/mcp-use11k—~5.2kAutomated safety check: PassApache-2.0
Api2clialexknowshtml/api2cli455—~2.9kAutomated safety check: PassMIT
Projectsamchon/nestia2.2k—~3kAutomated safety check: PassMIT
API ContractChenyCHENYU/Robot_Admin1k—~1.9kAutomated safety check: PassMIT

Similar skills

  • API Breaking Change Detector

    github/awesome-copilot

    Official

    Cross-references C Web API controllers/DTOs against their TypeScript/JavaScript consumers (React, Angular, Vue, Svelte, Node.js, or hand-written/auto-generated HTTP clients like Fetch, Axios, NSwag)…

    40k GitHub stars~1.7k tokensUpdated today
    Backend & APIsAuto-check passed
  • OpenAPI to MCP Server

    mcp-use/mcp-use

    Turns an OpenAPI or Swagger spec into an MCP server with the mcp-use TypeScript SDK, mapping each operation to a tool, wiring auth, testing and deploying.

    11k GitHub stars~5.2k tokensUpdated today
    Backend & APIsAuto-check passed
  • Api2cli

    alexknowshtml/api2cli

    Generate a working CLI from any API, then wrap it in a Claude Code skill.

    455 GitHub stars~2.9k tokensUpdated 7 mo ago
    Backend & APIsAuto-check passed
  • Project

    samchon/nestia

    Defines the nestia product contract, workspace layout, package boundaries, the Go plugin composition model, and canonical commands.

    2.2k GitHub stars~3k tokensUpdated 2 days ago
    Backend & APIsAuto-check passed
  • API Contract

    ChenyCHENYU/Robot_Admin

    A skill your agent uses when: generating TypeScript API layer (type definitions + request functions) from page-spec JSON or Swagger/OpenAPI docs.

    1k GitHub stars~1.9k tokensUpdated today
    Backend & APIsAuto-check passed
  • Typescript

    scalar/scalar

    Write clear, predictable TypeScript and Vue TypeScript code with strong typing, maintainability, and consistent documentation conventions.

    16k GitHub stars~1.1k tokensUpdated today
    Backend & APIsAuto-check passed

More from counterfact/api-simulator

All 12 skills in this repo
  • Counterfact PR Creation

    counterfact/api-simulator

    Create Counterfact pull requests with the required agent-authored acceptance and repository-learning notes; do not use to review another PR.

    170 GitHub stars~918 tokensUpdated today
    Auto-check passed
  • Build Simulation

    counterfact/api-simulator

    Build a fully simulated API from an OpenAPI spec using Counterfact.

    170 GitHub stars~2.9k tokensUpdated today
    Auto-check passed
  • Counterfact Maintenance

    counterfact/api-simulator

    Keep contributor changes aligned with repository test patterns, diagnostics, black-box test boundaries, release/versioning workflow, documentation requirements, and compatibility.

    170 GitHub stars~3.1k tokensUpdated today
    Auto-check passed
  • Counterfact Repo Basics

    counterfact/api-simulator

    Provide Counterfact repository orientation, high-level architecture, and the canonical command reference for install/build/test/lint workflows.

    170 GitHub stars~868 tokensUpdated today
    Auto-check passed
  • Route

    counterfact/api-simulator

    Edit Counterfact route files to add endpoint behavior while keeping handlers thin and delegating business logic to context classes.

    170 GitHub stars~341 tokensUpdated today
    Auto-check passed
  • Scenario

    counterfact/api-simulator

    Create and update Counterfact scenario modules that seed or mutate context state through reusable scenario functions.

    170 GitHub stars~356 tokensUpdated today
    Auto-check passed

Categories

Questions about Counterfact Repl

What does Counterfact Repl do?

Interact with Counterfact mock API server programmatically. An agent skill from counterfact/api-simulator. Counterfact Repl is an agent skill from counterfact/api-simulator. Interact with Counterfact mock API server programmatically.

When should I use Counterfact Repl?

Counterfact Repl fits situations like: the user mentions counterfact; working with OpenAPI mocks.

How do I install Counterfact Repl in Claude Code?

Run `npx skills add counterfact/api-simulator --skill counterfact-repl -a claude-code`. Or copy the skill folder (skills/counterfact-repl in counterfact/api-simulator) into .claude/skills/counterfact-repl in your project. Claude Code loads it when a task matches its description.

How do I install Counterfact Repl in Codex?

Run `npx skills add counterfact/api-simulator --skill counterfact-repl -a codex`. Or copy the skill folder (skills/counterfact-repl in counterfact/api-simulator) into .agents/skills/counterfact-repl in your project. Codex loads it when a task matches its description.

Can I use Counterfact Repl in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add counterfact/api-simulator --skill counterfact-repl -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/counterfact-repl, .gemini/skills/counterfact-repl, .github/skills/counterfact-repl and .opencode/skills/counterfact-repl in your project.

What does Counterfact Repl need to run?

Going by SKILL.md and its folder, Counterfact Repl needs credentials named COUNTERFACT_ADMIN_API_TOKEN. Our summary lists: Node.js; A credential in COUNTERFACT_ADMIN_API_TOKEN.

Does Counterfact Repl access the network?

SKILL.md names 3 domains. In commands or code: api.production.com; the agent is likely to contact it when it follows the instructions. As links in the text: counterfact.dev and github.com. This is read from the text; nothing was executed.

Is Counterfact Repl safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Counterfact Repl use?

Counterfact Repl is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Counterfact Repl use?

About 3.2k tokens (SKILL.md is roughly 13k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Counterfact Repl?

Skills that share tags, products or a category with Counterfact Repl: API Breaking Change Detector (github/awesome-copilot, 40k stars), OpenAPI to MCP Server (mcp-use/mcp-use, 11k stars), Api2cli (alexknowshtml/api2cli, 455 stars) and Project (samchon/nestia, 2.2k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Counterfact Repl?

counterfact (a GitHub organization) maintains it in counterfact/api-simulator, which has 170 GitHub stars. The repository holds 12 skills in this directory. The repository was last updated on October 9, 2026.

Source: counterfact/api-simulator on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.