TypeScript · MIT · open source

Procedures as data. Call them from everywhere.

Write a typed procedure once. Your code, the mark CLI, HTTP, WebSocket and the MCP tools of Claude Code call the same registry. A program is plain JSON, so you can store it, send it, draw it and compose it.

npm install @procedures/client

Version 0.68.2 on npm.

A live program, run by the real client in your browser

{
  "$proc": ["client", "chain"],
  "input": {
    "steps": [
      {
        "$proc": ["client", "range"],
        "input": { "start": 1, "end": 6 },
        "$name": "numbers"
      },
      {
        "$proc": ["client", "map"],
        "input": {
          "items": {
            "$ref": "numbers"
          },
          "fn": {
            "$proc": [
              "client",
              "multiply"
            ],
            "input": {
              "a": {
                "$ref": "item"
              },
              "b": {
                "$ref": "item"
              }
            }
          }
        },
        "$name": "squares"
      },
      {
        "$proc": ["client", "sum"],
        "input": {
          "values": {
            "$ref": "squares.results"
          }
        },
        "$name": "total"
      },
      {
        "$proc": ["client", "template"],
        "input": {
          "template": "The sum of the squares is {{total}}",
          "values": {
            "total": {
              "$ref": "total"
            }
          }
        }
      }
    ]
  }
}
  1. client.chainsteps [{ "$proc": ["client", "range"], "input": { "st…→ { "results": [[1, 2, 3, 4, 5], { "results": [1,…
  2. client.rangestart 1, end 6→ [1, 2, 3, 4, 5]
  3. client.mapitems { "$ref": "numbers" }, fn { "$proc": ["client", "multiply"], "input": { "…→ { "results": [1, 4, 9, 16, 25] }
  4. client.multiplya 1, b 1→ 1
  5. client.multiplya 2, b 2→ 4
  6. client.multiplya 3, b 3→ 9
  7. client.multiplya 4, b 4→ 16
  8. client.multiplya 5, b 5→ 25
  9. client.sumvalues [1, 4, 9, 16, 25]→ 55
  10. client.templatetemplate "The sum of the squares is {{total}}", values { "total": 55 }→ "The sum of the squares is 55"
✓ 10 calls in 10.4 ms · The sum of the squares is 55Open it in the Composer →
67packages
694procedures
103tools for Claude
6,499tests
198,811lines of TypeScript

Measured when this site was built: the procedures of the registry, the it and test calls in the test files, and the source lines without the tests.

How it works

  1. Define a procedure

    A path, an input schema, an output schema and a handler. An import registers nothing: a host registers the module of the package.

    import { defineProcedure } from "@procedures/client";
    import * as z from "zod";
    
    export const add = defineProcedure({
      path: ["math", "add"],
      input: z.object({ a: z.number(), b: z.number() }),
      output: z.number(),
      handler: ({ a, b }) => a + b,
    });
  2. Call it from any host

    In process, from the CLI, over HTTP or WebSocket, or as a tool of Claude Code. One invocation path validates each call.

    await client.exec(["math", "add"], { a: 2, b: 3 }); // 5
    
    $ mark math add --a 2 --b 3
    
    $ curl -X POST http://127.0.0.1:3000/api/math/add \
        -H "content-type: application/json" \
        -H "authorization: Bearer $TOKEN" \
        -d '{"a":2,"b":3}'
  3. Compose programs as JSON

    A call can be the input of another call. chain, map, conditional and $ref make programs that you can store and send.

    {
      "$proc": ["math", "add"],
      "input": {
        "a": { "$proc": ["math", "add"], "input": { "a": 2, "b": 3 } },
        "b": 10
      }
    }

Write it once, call it from everywhere

client.exec(["math", "add"], { a: 2, b: 3 })

The registry runs in your process. No server.

Host 1 of 6. Each host uses the same registry.

What is in the box

Control flow as data

chain, parallel, conditional, tryCatch, map and reduce. A branch that is not selected does not run.

Tools as procedures

git, docker, pnpm, vitest, cue, the file system, MongoDB, SQLite and S3, each a package of typed procedures.

Middleware and streams

Retry, timeout, cache, circuit breaker and rate limit around each call. Streams with flow control on each transport.

Explore