knitbrain CLAUDE.md

Project instructions for knitbrain, a TypeScript service that gives AI agents tools for session memory, learning, task classification, and self-checks. They describe the required session-start and verification steps.

In plain words
What is it for?
Use them when developing knitbrain, loading or continuing a session, verifying claims, running its checks, or testing changes against the installed build.
Why use it?
They reduce mistakes caused by stale knowledge or unfinished work and require the agent to classify or run a task before saving new learnings or handoffs.

Instructions file

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 instructions/pdgit12/knitbrain/claude-md
Clone the repo
git clone --depth 1 https://github.com/PDgit12/knitbrain
Per session 892 This file is loaded in full into every session.
When invoked 892 The same file — it is already loaded in full.
Security scan C 1 finding. 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.00892 $0.00892
Opus 5 $0.00446 $0.00446
Sonnet 5 $0.00178 $0.00178
Haiku 4.5 $0.00089 $0.00089

Measured 2d ago against content hash 4d9447244c54, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade C, and why

knitbrain CLAUDE.md scanned grade C with 1 finding 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 2d ago.

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.

Recursive force deletehighDestructive command

rm -rf with a variable or a broad path is one typo away from removing the wrong tree.

Always `rm -rf dist && npm run verify` before claiming green — stale dist masks build-order bugs. Local rebuild note: `build` re-chmods the three dist entrypoints (a globally symlinked install breaks otherwise).
CLAUDE.md · 66 lines

How it starts

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

knitbrain

TypeScript project (Node ≥18, ESM, vitest). This repo IS the knitbrain product — if a knitbrain MCP server is connected while developing here, note it runs the globally installed build, not your working tree; rebuild + reinstall (npm run build && npm install -g .) and reconnect to test local changes.


Session start

First action: call knitbrain_load_session — returns last handoff, top learnings, false positives. If it reports unfinished work, resume that first.

Adherence gate: close-the-loop writes (knitbrain_record_learning, knitbrain_skill_save, knitbrain_save_handoff) are blocked until knitbrain_classify_task/knitbrain_run ran this session (KNITBRAIN_STRICTNESS, default block).

Tool surface highlights (37 tools)

  • knitbrain_verify_claim — settle a codebase claim before LEARN. Caveat: the session MCP roots at the launch cwd — settle knit-brain facts by source + tests + built dist when the root is elsewhere.
  • knitbrain_self_check — keystone: audits all four invariants (anti-sycophancy, anti-stale, anti-drift, adherence) in one PASS/FAIL pass.
  • knitbrain_run_loop — one judge→iterate cycle per call; your verify_cmd is the hard gate.
  • knitbrain_search_code — retrieval layer: query → ranked function-level chunks + graph-related files, score-gated. Search BEFORE reading; knitbrain_read only the hits.
  • knitbrain_read / knitbrain_optimize / knitbrain_retrieve — compression loop; exact original always one retrieve away. Data-tool JSON responses are never skeletonized (machine contract).
  • Note: big tool responses may come back skeletonized with a trailing ⟨recall:hash⟩ — strip it before JSON-parsing a tool result.

Project Map

Entry points: dist/lib.js, dist/index.js, dist/proxy/index.js, dist/hooks/index.js, src/index.ts High-fanout (change carefully): src/ccr/store.ts, src/tokenizer.ts, src/engine/feedback.ts, src/engine/memory.ts, src/engine/knowledge.ts — check knitbrain_query_dependents before touching. Largest: src/mcp/tools.ts, scripts/production-audit.mjs, src/learn.ts

Read the full file on GitHub · 66 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. 2d ago First seen · 66 lines · 892 tokens per session scan C 4d9447244c54

Subscribe to this mod's changes

knitbrain CLAUDE.md is an instructions file published in the GitHub repository PDgit12/knitbrain (3 stars, last pushed 1mo ago), licensed MIT. It adds 892 tokens to every session, about $0.0045 per session on Opus 5. A static security scan graded it C with 1 finding (recursive force delete). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.