Architecture
System shape, data flows, and conventions for contributors.
ashlr-plugin is a multi-host efficiency layer for coding agents. Claude Code and Codex install it as a plugin; Cursor, Goose and other MCP hosts register the same ashlr-mcp server. It wraps file, search, edit, and shell workflows with lower-token alternatives and keeps a local ledger of what each call saved.
Two value propositions
Token efficiency. ashlr__read, ashlr__grep, and ashlr__edit replace the built-in Read, Grep, and Edit tools. Large file reads are snip-compacted, AST-skeletoned, or LLM-summarized; grep calls can retrieve from a per-project genome index and fall back to ripgrep; edits send only diffs, not full file contents.
Observability. Every tool call is accounted in ~/.ashlr/stats.json (per-session + lifetime counters) and appended to ~/.ashlr/session-log.jsonl. Claude Code surfaces savings in the status line; Codex and other hosts read them through ashlr__savings and ashlr-plugin stats --json. The genome scribe loop extracts architectural knowledge from tool results into .ashlrcode/genome/, which feeds back into future grep routing.
MCP server map
The canonical MCP wiring is one router entry named ashlr:
| Host | Entry point |
|---|---|
| Claude Code | .claude-plugin/plugin.json runs scripts/bootstrap.mjs servers/_router.ts |
| Codex | .codex-plugin/plugin.json plus .mcp.json, which runs ashlr-mcp |
| Cursor, Goose, others | ashlr-mcp from the npm package |
The router exposes 54 MCP tools: file, search and edit tools, ashlr__bash and its background-job tools, SQL, HTTP, diff, logs, GitHub, tests, the genome tools, and the read-only or propose-only ashlr__fleet_* tools that let an agent inspect and steer an agent fleet. ashlr__pipe is experimental and registers only when ASHLR_PIPE_ENABLE=1. Run ashlr-plugin tools --json for the current registered list.
Lazy tool registration
The stdio router does not import handler code at startup:
servers/_tool-catalog.jsonholds each tool's name, description, input schema, and handlermodule. It is generated, not hand-edited.servers/_lazy-tools.tsregisters a placeholder for every catalog entry, soinitializeandtools/listanswer from the catalog alone.- The first
tools/callfor a tool dynamic-imports its handler module. The module callsregisterToolfromservers/_tool-base.ts, which replaces the placeholder, and the call is forwarded.
servers/_router-handlers.ts still eager-imports every handler module. The ashlr-plugin tools CLI, smoke tests, and scripts/gen-tool-catalog.ts use it; the generator reads the registered tools and writes the catalog.
Hooks
Claude Code hooks are declared in hooks/hooks.json for SessionStart, UserPromptSubmit, PreToolUse, PostToolUse, SubagentStop, Stop, and SessionEnd. Each command runs through scripts/hook-bootstrap.mjs; with --group, one launcher starts every hook for an event in parallel and merges their output. PreToolUse hooks redirect or nudge native tools toward the ashlr__* equivalents (see Permissions). Codex reads hooks/codex-hooks.json, and its MCP entry sets nudge mode. See Hooks for the full list.
Key shared modules
| File | Role |
|---|---|
servers/_tool-base.ts | Tool registry: registerTool, getTool, listTools |
servers/_lazy-tools.ts | Catalog-backed placeholders and first-call handler import |
servers/_stats.ts | Shared read/write for ~/.ashlr/stats.json, including recordSaving |
servers/_events.ts | Shared append for ~/.ashlr/session-log.jsonl (logEvent) |
servers/_summarize.ts | LLM summarizer, confidence badge, snip-compact |
servers/_genome-cache.ts | In-process genome retriever cache |
servers/_genome-live.ts | Genome refresh after edits |
servers/_http-helpers.ts | HTML extraction, JSON elision, private-host check |
Adding a new MCP tool
- Add the handler in a focused
servers/<name>-server-handlers.tsmodule and register it withregisterTool. - Call
recordSavingfromservers/_stats.tswhen the tool shortens output, andlogEventfromservers/_events.tsfor session log entries. - Import the module from
servers/_router-handlers.ts. - Run
bun run references:sync. It regeneratesservers/_tool-catalog.json, updates the tool count in the docs, README, andscripts/smoke-tools.ts, and refreshes the generated site tool pages. Leave a regeneratedsite/lib/docs.generated.jsonout of the commit. - Add a test in
__tests__/, then runbun run references:checkandbun run smoke:tools. With the committedsite/lib/docs.generated.json, which PRs leave out,references:checkreportssite/lib/docs.generated.json is stale; only other lines need a fix.
Without step 4 the router never lists the tool, because tools/list reads only the catalog.
See also
Full architecture doc: docs/architecture.md in the repo root.