agentleFS
n1byn1ktn1byn1kt/apitap/CLAUDE.md

apitap

CLAUDE.md127 starsChanged 6 months agoApache-2.0View on GitHub

When asked to fetch data from a website, always check for existing skill files first: The replay path is the fast path. It calls APIs directly over HTTP — no browser, no Playwright, no Chrome. Don't open a browser if a skill file already exists. ApiTap intercepts web API traffic via browser, generates portable "skill files," and replays APIs without a browser. Two distinct runtime paths: Capture path (requires Playwright): Replay path (zero dependencies, stdlib node:http):

The file

We split this CLAUDE.md into the rules it gives an agent

5 rules. About 0 are common, 1 is distinctive, and 4 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 4

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    When asked to fetch data from a website, always check for existing skill files first:

    line 7
  2. Very specific:

    If it exists → use apitap replay <domain> <endpoint-id> (no browser needed)

    line 10
  3. Very specific:

    If no skill file → try apitap read <url> first (text extraction, no browser)

    line 11
  4. Very specific:

    Only use apitap capture or apitap browse as a last resort (requires browser)

    line 12
  5. Very specific:

    All imports use .js extension (NodeNext requirement): import { foo } from './bar.js'.

    line 82

≈ “Common” is an estimate: at least 1 in 5 of the 12,729 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
CLAUDE.md

CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

Using ApiTap as an MCP Tool

When asked to fetch data from a website, always check for existing skill files first:

  1. apitap show <domain> — check if a skill file already exists
  2. If it exists → use apitap replay <domain> <endpoint-id> (no browser needed)
  3. If no skill file → try apitap read <url> first (text extraction, no browser)
  4. Only use apitap capture or apitap browse as a last resort (requires browser)

The replay path is the fast path. It calls APIs directly over HTTP — no browser, no Playwright, no Chrome. Don't open a browser if a skill file already exists.

Commands

npm test                                          # Run all tests (~721, Node built-in runner + tsx)
node --import tsx --test test/path/to/test.ts     # Run a single test file
npm run typecheck                                 # Type check (tsc --noEmit)
npm run build                                     # Compile to dist/
npx tsx src/cli.ts <command> [args]               # Run CLI from source

Architecture

ApiTap intercepts web API traffic via browser, generates portable "skill files," and replays APIs without a browser. Two distinct runtime paths:

Capture path (requires Playwright):

Browser → CDP listener (monitor.ts) → filter.ts → SkillGenerator → skill.json on disk

Replay path (zero dependencies, stdlib node:http):

Skill file → replay/engine.ts → net/transport.ts pinnedFetch() → JSON response

Module Map

  • src/capture/ — Browser-side interception. monitor.ts is the Playwright CDP listener. session.ts wraps monitor into a stateful interactive session (used by MCP capture_start/capture_interact/capture_finish). filter.ts scores requests to separate API calls from noise. parameterize.ts converts /users/123 → /users/:id.
  • src/skill/ — Skill file lifecycle. generator.ts groups captured exchanges, deduplicates by method + parameterizedPath, extracts auth/pagination/body templates. store.ts reads/writes ~/.apitap/skills/<domain>.json. signing.ts provides HMAC-SHA256 integrity. ssrf.ts validates URLs against private IP ranges.
  • src/replay/ — engine.ts substitutes params, injects auth from encrypted storage, validates URLs via SSRF checks, and calls transport.fetch() (src/net/transport.ts). Auth comes from AuthManager, never from the skill file itself.
  • src/net/ — transport.ts: pinnedFetch(), a fetch-compatible client over node:http(s) whose DNS lookup rejects private addresses at connect time (closes DNS rebinding), never follows redirects, never pools sockets. fetchFollowing() adds fetch-style redirect following where every hop is re-checked and Authorization/Cookie are dropped on cross-origin hops. Every outbound HTTP call goes through here: replay, OAuth refresh, verifier, spec importers (GitHub/APIs.guru/SwaggerHub), and (via safeFetch) read/peek/discovery.
  • src/discovery/ — Browser-free API detection. frameworks.ts detects WordPress/Next.js/Shopify from HTML/headers. openapi.ts probes for specs. probes.ts checks common API paths. index.ts orchestrates all three in parallel.
  • src/read/ — Text-mode content extraction. Site-specific decoders (Reddit, YouTube, Wikipedia, HN, Twitter, Grokipedia, DeepWiki) in decoders/. Falls back to generic HTML extraction in extract.ts. peek.ts does HEAD-only triage.
  • src/auth/ — manager.ts stores/retrieves encrypted credentials (AES-256-GCM). refresh.ts handles browser-based token refresh. handoff.ts opens a visible browser for human login. oauth-refresh.ts handles OAuth refresh_token flows.
  • src/orchestration/ — browse.ts is the high-level "just get me the data" pipeline (cache → disk → discover → replay). cache.ts is an in-memory session cache for the MCP server.
  • src/cli.ts — Hand-rolled arg parser, all CLI commands. No framework (no yargs/commander).
  • src/mcp.ts — MCP server (12 tools) using @modelcontextprotocol/sdk. All responses from external APIs are wrapped with untrusted: true metadata.
  • src/plugin.ts — Lightweight non-MCP plugin interface (search + replay + batch tools).
  • src/serve.ts — Serves a single skill file as a dedicated MCP server where each endpoint becomes its own tool.

Key Design Decisions

  • CLI is the API: agents use the same commands humans do. --json on every command for machine output. That covers failures too — every error exit goes through failCli() in src/cli.ts, which prints {success: false, error, usage?, hint?} to stdout under --json while keeping the human line on stderr. Keep error short enough to surface alone — long guidance goes in hint, which reaches both channels. Add new error exits via failCli, never a bare console.error + process.exit. apitap serve is the one exception: its stdout is the MCP transport, so it passes stream: 'stderr' and the human line is suppressed to keep that stream parseable.
  • Skill files are the central artifact: JSON at ~/.apitap/skills/<domain>.json with version, endpoints, auth config, provenance, and HMAC signature.
  • Auth is never in skill files: credentials live in separate encrypted storage. Skill files only contain [stored] placeholders.
  • SSRF defense is multi-layered: validated at import, at replay, per redirect hop, and — the enforcement point — inside the connection's own DNS lookup (validatingLookup), so the checked address is the connected address. Private IPs, cloud metadata, localhost all blocked. Never add a new outbound call that pre-checks DNS and then calls global fetch(hostname): that re-resolves and reopens rebinding. Use transport.fetch / safeFetch.
  • Generator deduplication: keyed on method + parameterizedPath. For POST bodies, duplicate bodies stored in exchangeBodies map for cross-request diffing during toSkillFile().
  • ESM-only: "type": "module" with .js extensions in imports (even for .ts source files, required by NodeNext resolution).

Security Model

  • Signing threat model: Skill file HMAC-SHA256 signatures protect against external attackers and file corruption, not same-user processes. Any process running as the same user can derive the signing key from /etc/machine-id + ~/.apitap/install-salt. This follows the standard Unix security model where same-user processes share a trust boundary.
  • APITAP_MACHINE_ID env var: Testing-only override for the machine ID used in key derivation. Never set in production.
  • Auth encryption: Credentials in ~/.apitap/auth.enc use AES-256-GCM with per-install random salt and 100K PBKDF2-SHA512 iterations. Fresh random IV per encryption. File permissions 0o600, directory 0o700.

Testing Conventions

  • Tests mirror src/ structure under test/ (e.g., src/capture/filter.ts → test/capture/filter.test.ts).
  • Uses Node's built-in node:test with describe/it/assert. No Jest, no Mocha.
  • E2E tests in test/e2e/ spin up local HTTP servers for capture→replay round-trips.
  • Security tests in test/security/ cover SSRF, path traversal, header injection, DNS rebinding, redirect attacks.
  • Outbound HTTP goes through transport.fetch — stub that (transport.fetch = stub), not globalThis.fetch, which reaches none of the replay, OAuth, verifier or importer paths.
  • MCP tests in test/mcp/ test the MCP server tools end-to-end.

TypeScript

  • Strict mode. Target ES2022, module NodeNext.
  • All imports use .js extension (NodeNext requirement): import { foo } from './bar.js'.
  • Core types in src/types.ts: CapturedExchange, SkillFile, SkillEndpoint, StoredAuth, Replayability, DiscoveryResult.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.