llm-patterns — Claude Code rule: what it does, how to install
The llm-patterns rule sets patterns for LLM providers in a project. Use it when provider interfaces, model settings, CLI errors, or streamed responses need consistent handling.
MIT ★ 1,319 updated 2026-09-24
.claude/rules/llm-patterns.mdWhat llm-patterns does
The rule targets src/llm/**. It defines the expected LLMProvider shape with call() and stream(), plus an optional listModels(). Configuration flows from environment variables through src/llm/config.ts into ~/.caliber/config.json.
It also covers seat-based providers: isSeatBased() lets cursor and claude-cli bypass validateModel(). Cursor runs through agent --print --trust --workspace /tmp. The fast-model helper is getFastModel(), while ANTHROPIC_SMALL_FAST_MODEL is scoped to anthropic, vertex, and claude-cli.
Recovery for a missing model lives in src/llm/model-recovery.ts and can use an interactive fallback. Usage goes through trackUsage(), CLI stderr is parsed by src/llm/seat-based-errors.ts, and JSON handling uses extractJson() with parseJsonResponse(). The Claude Code installation path is .claude/rules/llm-patterns.md.
What it helps with
- define a shared LLM provider contract
- keep model settings in the expected config flow
- skip model validation for seat-based providers
- recover when a selected model is missing
- parse CLI errors and JSON responses
Example prompts for the agent
- Review the provider code under
src/llm/**against this rule. - Add a provider with
call()andstream(), and decide whether it needslistModels(). - Handle a missing model, usage tracking, and JSON parsing using the project patterns.
How to install llm-patterns
Manually: put the files in place
.claude/rules/llm-patterns.mdThe paths frontmatter field limits the files
AGENTS.md
Codex reads AGENTS.md: paste the rule text there
Manually: put the files in place
.cursor/rules/llm-patterns.mdcFrontmatter: description, globs, alwaysApply
Manually: put the files in place
.github/instructions/llm-patterns.instructions.mdThe applyTo field sets which files it applies to
Manually: put the files in place
.devin/rules/llm-patterns.mdManually: put the files in place
.clinerules/llm-patterns.mdStep by step, with commands for each platform: AGENTS.md vs CLAUDE.md: what they are and which one to use
Questions about llm-patterns
How do I install llm-patterns in Claude Code?
Add the rule file at .claude/rules/llm-patterns.md. It applies to files under src/llm/**.
What does llm-patterns do?
It documents the project conventions for LLM providers, configuration, model selection, recovery after provider errors, usage tracking, and JSON parsing.
How are seat-based providers handled?
isSeatBased() identifies them. The cursor and claude-cli providers skip validateModel() under this rule.
Source text
llm-patterns.md · MIT
--- paths: - src/llm/** --- # LLM Provider Patterns - 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` and `claude-cli` skip `validateModel()` - Cursor: `agent --print --trust --workspace /tmp` in `src/llm/cursor-acp.ts` - Fast model: `getFastModel()` in `src/llm/config.ts` — `ANTHROPIC_SMALL_FAST_MODEL` scoped to anthropic/vertex/claude-cli - Model recovery: `src/llm/model-recovery.ts` handles not-found with interactive fallback - Usage: `trackUsage()` from `src/llm/usage.ts` - Errors: `src/llm/seat-based-errors.ts` parses stderr from CLI providers - JSON: `extractJson()`, `parseJsonResponse()` in `src/llm/utils.ts`
© caliber-ai-org · MIT · caliber-ai-org/ai-setup