claude-loopback
CLAUDE.md2 starsChanged 2 months agoMITView on GitHub
A personal, localhost-only HTTP server that runs prompts through claude -p (Claude Code headless mode) and returns JSON or streams SSE. Only for the owner's local scripts. Never public, never multi-user, not a Messages API clone. Imports between .ts files use the .ts extension (rewritten to .js on build). Use only erasable TS syntax: no enums, namespaces or constructor parameter properties. - src/config.ts: Zod env schema → frozen Config. src/errors.ts: AppError, code → status. - src/logger.ts: pino with redaction; JSON…
- Reads credentials
In this repositoryOne other file it gives its agents.
- finish-milestoneSkill
The file
We split this CLAUDE.md into the rules it gives an agent
10 rules. About 0 are common, 5 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 9
Platforms: Windows, macOS and Linux: Keep OS-specific code behind a small seam (a process.platform === "win32" branch with its POSIX …
- Distinctive: line 64
No stack traces, paths or raw stderr in responses.
- Very specific: line 66
Check CLI flags against claude --help for the installed version, not memory.
- Distinctive: line 70
Write tests against the public interface (exported functions, HTTP routes, runner API).
- Very specific: line 71
Add stubs with real signatures that throw new Error("not implemented").
- Distinctive: line 75
Never weaken, loosen or delete an assertion to make code pass.
- Very specific: line 80
Commit only when pnpm run check passes.
- Distinctive: line 82
Don't commit unless a feature is complete or the user asks.
- Very specific: line 83
Never bypass hooks (--no-verify, -n).
- Distinctive: line 87
No body, no description, no trailers, no Co-Authored-By lines.
≈ “Common” is an estimate: at least 1 in 5 of the 29,248 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.
Files
claude-loopback
A personal, localhost-only HTTP server that runs prompts through claude -p (Claude Code
headless mode) and returns JSON or streams SSE. Only for the owner's local scripts. Never
public, never multi-user, not a Messages API clone.
Status & workflow
- Work in small, complete features. Stop for approval at the end of each one.
- Platforms: Windows, macOS and Linux. Keep OS-specific code behind a small seam (a
process.platform === "win32"branch with its POSIX sibling beside it).
Stack
Node 24 · TypeScript (strict) · Hono + @hono/node-server · Zod · Vitest · Biome · pnpm
Commands
pnpm run check: lint + typecheck + test (the gate; must pass before any commit)pnpm run lint/pnpm run format: Biome check / Biome check --writepnpm run typecheck:tsc --noEmit(also type-checks the.mjshook scripts)pnpm run test/pnpm run test:coverage: Vitest once / with the 85%/80% coverage gate (CI)pnpm run openapi: regeneratedocs/openapi.jsonafter any API change (a test checks drift)pnpm run e2e: manual smoke test against a running server and the REAL CLI. Spends usage, so ask before running it.pnpm run dev:node --watch src/index.ts(Node strips TS types natively; loads.env)pnpm run build/pnpm start: cleantscbuild todist// run the buildnode src/cli.ts <start|setup|token|config>: the npm command from source. Publishing (npm publish) runs check, then build, viaprepublishOnly/prepack; onlydist/,.env.exampleanddocs/openapi.jsonship (seefilesin package.json).pnpm run token: print a new randomLOOPBACK_TOKEN
Imports between .ts files use the .ts extension (rewritten to .js on build). Use only
erasable TS syntax: no enums, namespaces or constructor parameter properties.
Architecture
routes → service (queue, limits) → ClaudeBackend interface → process runner. CliBackend
now, ApiBackend (BYOK) later; routes never know which one is active. Config, logger, clock,
backend and spawner are injected so every layer is testable alone.
src/config.ts: Zod env schema → frozenConfig.src/errors.ts:AppError, code → status.src/logger.ts: pino with redaction; JSON or pretty (src/log-format.ts, pino-pretty).src/clock.ts: injectable time.src/app.ts:createApp(deps)(Hono).src/server.ts:startServer(all wiring, startup checks, graceful close).src/run.ts:runServer(signals, startup errors, banner fromsrc/banner.ts).- Entry points:
src/cli.tsis the npmclaude-loopbackcommand (settings in%APPDATA%\claude-loopback\config.env, or~/.config/claude-loopback/config.env);src/index.tsispnpm start/devfrom a clone (.env).src/setup.ts: setup checks for both;src/token-file.ts+src/file-acl.ts: token file written readable only by the current user. src/http/: middleware, schemas (Zod, also the OpenAPI source), routes, SSE, openapi.src/service/: prompt service (policy, attachments, run loop, drain), queue.src/backends/:types.ts+cli/(args, env, stream parser, classify, probe).src/process/: runner (buffered stdout, caps, timeout/abort), tree kill, temp dirs, instance lock (named pipe).
Dev tooling: .claude/hooks/ (format on edit, commit-message check, stop gate),
scripts/commit-format.mjs (commit rules, shared with .githooks/commit-msg).
Security invariants (never break these)
- Bind to 127.0.0.1 only. A bearer token (
LOOPBACK_TOKEN) is required, and the server refuses to start without one. - Spawn
claudewithshell: falsein a fresh temp dir per request, never the repo or the home dir. - Child env comes from an allowlist and never contains
ANTHROPIC_API_KEYorLOOPBACK_TOKEN. - Tools are default-deny. Requests may only narrow the server allowlist.
- No stack traces, paths or raw stderr in responses. No prompt/output contents in logs.
- Tests never call the real
claudeCLI. Use a fake spawner or a fake binary. - Check CLI flags against
claude --helpfor the installed version, not memory.
Test-first (always)
- Spec the behavior and edge cases, including failure paths.
- Write tests against the public interface (exported functions, HTTP routes, runner API).
- Add stubs with real signatures that
throw new Error("not implemented"). Run the tests and confirm each new test fails on an assertion or that error, not on an import/typo. A test that passes before the code exists tests nothing, so fix or delete it. - Implement until green.
- Never weaken, loosen or delete an assertion to make code pass. If a test was wrong, fix it and say so in the milestone summary.
Commit policy (strict)
- One commit per completed feature or milestone, not per file or small edit.
- Commit only when
pnpm run checkpasses. Never commit WIP or broken states. - Fold formatting fixes, typo fixes and small follow-ups into the feature's commit.
- Don't commit unless a feature is complete or the user asks.
- Never bypass hooks (
--no-verify,-n).
Commit format (strict, enforced by hooks)
- Single line only, imperative mood, lowercase start, max 60 characters, no trailing period.
- No body, no description, no trailers, no Co-Authored-By lines.
- Examples:
add sse streaming endpoint,fix child kill on disconnect
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
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.

