tool-scripts

A set of rules and a template for writing standalone command-line scripts for OpenClaw agents, software agents that can run tools. The scripts use built-in Node.js features and print results for the agent to read.

In plain words
What is it for?
Use it when creating Node.js tool scripts that accept command-line arguments, call web services, read configuration, and return text or JSON.
Why use it?
It provides a consistent way to build small scripts without adding third-party packages. It also clarifies how scripts receive options, load secrets, and report errors.

Cursor rule

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/mergisi/openclaw-rules/tool-scripts
Clone the repo
git clone --depth 1 https://github.com/mergisi/openclaw-rules
Per session 1,135 This file is loaded in full into every session.
When invoked 1,135 The same file — it is already loaded in full.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.01135 $0.01135
Opus 5 $0.00567 $0.00567
Sonnet 5 $0.00227 $0.00227
Haiku 4.5 $0.00113 $0.00113

Measured yesterday against content hash f1d0ce40d99f, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

tool-scripts scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

project-rules/tool-scripts.mdc · 136 lines

How it starts

The opening of the file, as written. The whole thing — 136 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Writing Tool Scripts

When creating tool scripts for OpenClaw agents, follow these patterns.

Rules

  1. Zero npm dependencies. Use only Node.js built-ins: https, fs, path, crypto.
  2. CommonJS format. Use .cjs extension and require().
  3. Self-contained. Each script must work standalone with node tools/script.cjs.
  4. Accept CLI arguments. Date ranges, flags, output format.
  5. Print to stdout. The agent captures stdout. Use console.log() for output, console.error() for errors.

Template

#!/usr/bin/env node
// Tool Name — Short description
// Usage: node tool-name.cjs [date] [--json]
// Requires: API_KEY in .env or secrets/
const https = require("https");
const path = require("path");
const fs = require("fs");

// Load config
const envPath = path.resolve(__dirname, "../secrets/.env");
if (fs.existsSync(envPath)) {
  fs.readFileSync(envPath, "utf-8").split("\n").forEach(line => {
    const [k, ...v] = line.split("=");
    if (k && !k.startsWith("#")) process.env[k.trim()] = v.join("=").trim();
  });
}

const API_KEY = process.env.API_KEY;
if (!API_KEY) { console.error("Set API_KEY in secrets/.env"); process.exit(1); }

// HTTP helper — works with any JSON API
function httpGet(url, headers = {}) {
  return new Promise((resolve, reject) => {
    const u = new URL(url);
    const req = https.request({
      hostname: u.hostname,
      path: u.pathname + u.search,
      method: "GET",
      headers: { "User-Agent": "OpenClaw-Agent/1.0", ...headers },
      timeout: 15000,
    }, res => {
      let body = "";
      res.on("data", d => body += d);
      res.on("end", () => {
        try { resolve(JSON.parse(body)); }
        catch { resolve(body); }
      });
    });
    req.on("error", reject);
    req.on("timeout", () => { req.destroy(); reject(new Error("timeout")); });
    req.end();
  });
}

function httpPost(url, headers, data) {
  return new Promise((resolve, reject) => {
    const body = typeof data === "string" ? data : JSON.stringify(data);
    const u = new URL(url);
    const req = https.request({
      hostname: u.hostname,
      path: u.pathname + u.search,
      method: "POST",
      headers: { "Content-Type": "application/json", "Content-Length": Buffer.byteLength(body), ...headers },
      timeout: 15000,
    }, res => {
      let b = "";
      res.on("data", d => b += d);
      res.on("end", () => {
        try { resolve(JSON.parse(b)); }
        catch { resolve(b); }
      });
    });
    req.on("error", reject);
    req.on("timeout", () => { req.destroy(); reject(new Error("timeout")); });
    req.write(body);
    req.end();
  });
}

// Date helpers
const yesterday = new Date(Date.now() - 86400000).toISOString().slice(0, 10);
const date = process.argv[2] || yesterday;
const jsonOutput = process.argv.includes("--json");

async function main() {
  // Your tool logic here
  const data = await httpGet(`https://api.example.com/data?date=${date}`);

  if (jsonOutput) {
    console.log(JSON.stringify(data, null, 2));
  } else {
    console.log(`Report for ${date}`);
    console.log("=".repeat(40));
    // Format and print results
  }
}

main().catch(e => { console.error("Fatal:", e.message); process.exit(1); });

Read the full file on GitHub · 136 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 136 lines · 1,135 tokens per session scan A f1d0ce40d99f

Subscribe to this mod's changes

tool-scripts is a cursor rule published in the GitHub repository mergisi/openclaw-rules (2 stars, last pushed 6mo ago), licensed MIT. It adds 1,135 tokens to every session, about $0.0057 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.