agentleFS
TechStarkTechStark/opencv-js/CLAUDE.md

opencv-js

CLAUDE.md786 starsChanged 4 months agoApache-2.0View on GitHub

TypeScript NPM package wrapping the pre-built OpenCV.js (WASM) binary with type definitions. Supports Node.js and browser environments. NEVER cancel builds or tests. Always run the full sequence after any change: Always call .delete() on OpenCV objects — WASM memory does not GC: Current API (v4.11+): Legacy API (v4.10-): See doc/updating-opencv-version.md for the full checklist. Quick summary: 1. Build new dist/opencv.js via GitHub Actions (build-opencv-js.yml) 2. Replace dist/opencv.js with the artifact 3. Update version strings: package.json, README.md, CLAUDE.md, .github/copilot-instructions.md, build-opencv-js.yml 4.…

  • Installs packages

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

4 rules. About 0 are common, 1 is distinctive, and 3 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.

  • 3

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    NEVER cancel builds or tests.

    line 21
  2. Very specific:

    Always call .delete() on OpenCV objects — WASM memory does not GC:

    line 42
  3. Very specific:

    Update version strings: package.json, README.md, CLAUDE.md, .github/copilot-instructions.md, build-opencv-js.yml

    line 80
  4. Very specific:

    Run npm audit fix before committing

    line 101

≈ “Common” is an estimate: at least 1 in 5 of the 25,680 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

opencv-js — Claude Development Guide

Project Overview

TypeScript NPM package wrapping the pre-built OpenCV.js (WASM) binary with type definitions. Supports Node.js and browser environments.

  • Package: @techstark/opencv-js
  • Version: 5.0.0-release.1
  • OpenCV Version: 5.0.0 (WASM binary in dist/opencv.js)
  • Binary source: Built via GitHub Actions (build-opencv-js.yml) — official docs.opencv.org does not yet publish 5.x

Essential Commands

npm install        # ~15s — regenerates package-lock.json
npm run build      # ~2s  — TypeScript compile (tsc)
npm test           # ~8s  — Jest test suite (38 tests)
npm run format     # ~1s  — Prettier

NEVER cancel builds or tests. Always run the full sequence after any change:

npm install && npm run build && npm test

File Structure

dist/opencv.js          — pre-built WASM binary (~10MB), never edit
src/index.ts            — re-exports from types/
src/types/opencv/       — 100+ TypeScript definition files
test/                   — Jest tests (Mat, Tracker, rect, cvKeys, QRCode, etc.)
doc/cvKeys.json         — runtime API surface snapshot (buildInformation + keys)
.github/workflows/
  build-opencv-js.yml   — builds opencv.js from source via Emscripten
  npm-publish.yml       — publishes to NPM on release
  unit-test.yml         — CI tests on PR/push

Memory Management (Critical)

Always call .delete() on OpenCV objects — WASM memory does not GC:

const mat = new cv.Mat(3, 3, cv.CV_8UC1);
try {
  // use mat
} finally {
  mat.delete();
}

Import Patterns

Current API (v4.11+):

import cvReadyPromise from "@techstark/opencv-js";
const cv = await cvReadyPromise;

Legacy API (v4.10-):

import cv from "@techstark/opencv-js";
cv.onRuntimeInitialized = () => { /* use cv */ };

Browser webpack polyfills

resolve: { fallback: { fs: false, path: false, crypto: false } }

Updating the OpenCV Version

See doc/updating-opencv-version.md for the full checklist.

Quick summary:

  1. Build new dist/opencv.js via GitHub Actions (build-opencv-js.yml)
  2. Replace dist/opencv.js with the artifact
  3. Update version strings: package.json, README.md, CLAUDE.md, .github/copilot-instructions.md, build-opencv-js.yml
  4. Run npm install && npm run build && npm test
  5. Regenerate doc/cvKeys.json (run npm test — the cvKeys test validates the binary)

Build parameters for 5.0.0:

  • Emscripten: 4.0.20
  • CMake option: -DCMAKE_CXX_STANDARD=17 (required for Emscripten 4.0.20+)
  • Build flags: default (no custom flags needed)

Common Issues

ErrorCauseFix
cv.Mat is not a constructorOpenCV not initializeduse await cvReadyPromise
Memory leak / browser crashMissing .delete()add .delete() in finally
webpack fs not foundMissing polyfillsadd fallback config
Test failures on setupOpenCv()Async init not awaitedcheck test helper

Security

  • dist/opencv.js comes from our own CI build (OpenCV source + Emscripten) — verify origin before accepting external files
  • Run npm audit fix before committing

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.