llm-layer — Claude Code rule: what it does, how to install
llm-layer pins the conventions for model-provider code: the LLMProvider interface, config lookup, seat-based handling and usage tracking. Scoped to src/llm/**.
MIT ★ 1,319 updated 2026-09-24
.cursor/rules/llm-layer.mdcWhat llm-layer does
The rule holds the conventions for code under src/llm/**, the part of the project that talks to model providers. A provider implements LLMProvider from src/llm/types.ts with call(), stream() and an optional listModels(). Settings resolve through src/llm/config.ts: environment variables first, then ~/.caliber/config.json.
Seat-based providers (cursor and claude-cli) are marked by isSeatBased(), and validateModel() is not applied to them. Cursor is launched as agent --print --trust --workspace /tmp in src/llm/cursor-acp.ts. The rest of the map: getFastModel() for the fast model, src/llm/model-recovery.ts for recovery, src/llm/seat-based-errors.ts for errors, trackUsage() from src/llm/usage.ts.
The frontmatter sets globs: src/llm/**, so the rule only fires inside that folder. Edits elsewhere in the repo get no guidance from it.
What it helps with
- add a new provider without breaking existing ones
- trace whether a setting comes from env or
~/.caliber/config.json - tell a seat-based provider from a regular one
- hook usage tracking into a provider with
trackUsage() - recover a model after a provider error
Example prompts for the agent
- Add an
openrouterprovider undersrc/llm/that implementsLLMProviderwithcall()andstream() - Why does
validateModel()skip cursor? Readsrc/llm/types.ts - Wire
trackUsage()into the new provider
How to install llm-layer
Manually: put the files in place
.cursor/rules/llm-layer.mdcFrontmatter: description, globs, alwaysApply
Manually: put the files in place
.claude/rules/llm-layer.mdThe paths frontmatter field limits the files: move globs from the source into paths
AGENTS.md
Codex reads AGENTS.md: paste the rule text there
Manually: put the files in place
.github/instructions/llm-layer.instructions.mdThe applyTo field sets which files it applies to: move globs from the source into applyTo
Manually: put the files in place
.devin/rules/llm-layer.mdManually: put the files in place
.clinerules/llm-layer.mdStep by step, with commands for each platform: Cursor rules: .mdc files, four modes and what replaced .cursorrules
Questions about llm-layer
How do I install llm-layer in Claude Code?
Place the rule file at .claude/rules/llm-layer.md.
What does llm-layer do?
It sets the conventions for provider code in src/llm/**: the LLMProvider interface, where config comes from and how usage tracking is wired.
Do seat-based providers go through model validation?
validateModel() does not run against them. isSeatBased() in src/llm/types.ts marks them, and the rule names cursor and claude-cli as the seat-based ones.
Source text
llm-layer.mdc · MIT
--- description: LLM provider implementation patterns globs: src/llm/** --- - Providers implement `LLMProvider` from `src/llm/types.ts`: `call()`, `stream()`, optional `listModels()` - Config: env vars → `~/.caliber/config.json` via `src/llm/config.ts` - Seat-based: `isSeatBased()` in `src/llm/types.ts` (cursor, claude-cli) - Cursor: `agent --print --trust --workspace /tmp` in `src/llm/cursor-acp.ts` - Fast model: `getFastModel()` in `src/llm/config.ts` - Model recovery: `src/llm/model-recovery.ts` · Errors: `src/llm/seat-based-errors.ts` - Usage: `trackUsage()` from `src/llm/usage.ts` - `validateModel()` skips seat-based providers
© caliber-ai-org · MIT · caliber-ai-org/ai-setup