02.2Case file/projects/zero-core/
sheet 02 of 06
ZERO CORE
The private hub behind my AI agent workflow
- role
- Solo
- context
- A private hub that keeps the rules my Claude Code sessions follow
- scope
- Rules, tests and a review agent around my own work
- result
- 95 problems raised in its first 41 reviews · 130 tests
Dependencies
- Cloudflare Workers
- D1
- Access
- TypeScript
- Claude API
- Claude Code hooks
Changelog
- the rules my Claude Code sessions follow live in one place and are handed to every session
- an independent review agent reads the change report when the work is done
- 130 automated tests, run before every deploy
The problem
I work with Claude Code every day. I want its sessions to follow the same rules every time, and I want to see what they did. A rule that lives only in my head, or in one file I forget to update, reaches only the sessions I remember to mention it to.
The design
Four parts, drawn in FIG 02.
- 1Claude Code session — where I work; when it learns something it proposes a rule change.
- 2Hook, on my PC — four jobs: inject the rules that apply at the start (within a size budget); stop a tool call that breaks a hard rule; sync usage; file a change report after each change.
- 3Cloudflare Worker, behind Access — the service the hook and the panel talk to.
- 4D1 — keeps the rules, proposals, reports, usage and to-dos.
- 5Review agent — reads the diff of every change report in a fresh context.
- 6Panel — eight regions, and Zero, a read-only assistant. I approve proposals here; an approved one becomes the next session's rules.
A hook on my PC. A Claude Code hook runs inside every session. At the start it injects the rules that apply, within a size budget so they never crowd out the work. During the session it stops a tool call that breaks a hard rule, such as committing a secret or adding a tracking script. It syncs usage, and after each change it files a change report.
A Worker and a database. A Cloudflare Worker with a D1 database, behind Cloudflare Access, keeps the rules, proposals, reports, usage and to-dos. The diff in every change report goes to a review agent that starts in a fresh context, so it has not seen the thinking that produced the change.
Back to me. When Claude learns something, it proposes a rule change. I approve it in the panel, and an approved proposal becomes part of the rules the next session is given. The panel has eight regions and a read-only assistant, Zero, that answers questions about the rules and cannot change them.



The code
Four short pieces quoted from its source, cut with // … where I left lines out. The file is named above each.
export async function preToolUse(input: HookInput, deps: Deps): Promise<HookOutput> { const cache = await deps.readCache(); if (!cache || !input.tool_name) return {}; const snap = cache.snapshot; const call = { tool: input.tool_name, input: input.tool_input ?? {} }; const verdict = evaluate(activeGuards(snap, input.cwd), call); // … const deny: { g: ActiveGuard; detail: string }[] = verdict.deny.map((g) => ({ g, detail: '' })); // … const at = now(); if (deny.length) { const first = deny[0]!; // … return { hookSpecificOutput: { hookEventName: 'PreToolUse', permissionDecision: 'deny', permissionDecisionReason: `Blocked by the owner's hard rule in ZERO CORE: ${describe(first.g)}.${first.detail} Do not try another way around it; tell the owner what you were about to do and ask.`, }, systemMessage: `ZERO CORE blocked ${input.tool_name}: ${first.g.rule.text}${first.detail}`, }; } // …}/** The answer with an ETag (a hash of its body): a request that already holds exactly this gets 304 and no body. Cache-Control stays no-store (index.ts), so nothing along the way keeps it; the panel itself remembers the tag. */export async function etagged(req: Request, data: unknown): Promise<Response> { const text = JSON.stringify(data); const sum = new Uint8Array(await crypto.subtle.digest('SHA-1', new TextEncoder().encode(text))); const tag = `"${[...sum].map((x) => x.toString(16).padStart(2, '0')).join('')}"`; const held = req.headers.get('If-None-Match'); if (held && held.split(',').some((t) => t.trim().replace(/^W\//, '') === tag)) return new Response(null, { status: 304, headers: { ETag: tag } }); return new Response(text, { headers: { 'Content-Type': 'application/json; charset=utf-8', ETag: tag } });}export type PetEvent = | { t: 'start'; id: number } | { t: 'tool'; name: string } | { t: 'text'; d: string } | { t: 'ping' } | { t: 'done'; reply: PetTalkReply | PetDeeperReply } | { t: 'error'; message: string };// …/** One event as a line. */export const encodeEvent = (ev: PetEvent): string => `${JSON.stringify(ev)}\n`;// …export function parseEvent(line: string): PetEvent | null { let v: unknown; try { v = JSON.parse(line); } catch { return null; } if (!v || typeof v !== 'object') return null; const o = v as Record<string, unknown>; switch (o.t) { case 'start': return typeof o.id === 'number' ? { t: 'start', id: o.id } : null; case 'tool': return typeof o.name === 'string' ? { t: 'tool', name: o.name } : null; case 'text': return typeof o.d === 'string' ? { t: 'text', d: o.d } : null; case 'ping': return { t: 'ping' }; case 'done': return o.reply && typeof o.reply === 'object' ? { t: 'done', reply: o.reply as PetTalkReply | PetDeeperReply } : null; case 'error': return { t: 'error', message: typeof o.message === 'string' ? o.message : 'something went wrong on the server' }; default: return null; }}/** The review: the diff zc sends is read by a fresh-context reviewer and dropped; the verdict is kept. zc may instead say why it sends none (`skip`). A report already reviewed is not reviewed again. */export async function reviewReport(env: Env, id: string, b: Body): Promise<{ verdict: Verdict; review: Review | null; note: string | null }> { const db = env.DB; const row = await db.prepare('SELECT * FROM reports WHERE id = ?').bind(id).first<Record<string, unknown>>(); if (!row) throw new HttpError(404, 'no such report'); const r = reportRow(row); if (r.verdict !== 'pending' && r.verdict !== 'skipped') return { verdict: r.verdict, review: r.review, note: r.review_note }; const skip = text(b, 'skip', 300); const diff = typeof b.diff === 'string' ? b.diff : ''; if (diff.length > DIFF_LIMIT + 4000) bad(`diff: at most ${DIFF_LIMIT} characters (zc cuts it down)`); let verdict: Verdict = 'skipped'; let review: Review | null = null; let note: string | null = skip; let model: string | null = null; let usage: { input_tokens: number; output_tokens: number } | null = null; if (!skip) { if (!diff.trim()) note = 'no changes to read'; else { const out = await reviewDiff(env, { title: r.title, points: r.points, files: r.files }, diff); if ('error' in out) note = `not reviewed: ${out.error}`; else { verdict = out.verdict; review = out.review; note = null; model = REVIEW_MODEL; usage = out.usage; } } } // … return { verdict, review, note };}What the review agent caught
Of the first 45 change reports filed, from 29 October to 2 November 2026, the review agent read 41 (4 were skipped) and raised 95 problems or concerns. I did not track how many of them I fixed, so I give no number for that. Three it found, and what I changed:
- The 30-second refresh pulled a scrolled block index back to the open block on every redraw. The open block is now brought into view only when it changes.
- Re-sending a session's usage without a title wiped the title already stored. A row sent again now keeps the stored title.
- After a failed save of a hard rule, Retry re-armed the confirmation instead of saving. A retried save now saves.
How it is tested
130 unit tests, run with node --test. On 3 Nov 2026, when I wrote this, npm test printed 130 passing and 0 failing. Each change report's diff is also sent to a review agent that reads it in a fresh context.
Numbers
- 122 KB → 0.3 KB for an unchanged 30-second poll, by answering with an ETag and a 304 instead of the whole response
- 130 tests, 8 panel regions