← All news
Product

7 CI/CD Review Routing Patterns for Lower LLM Spend

Discover 7 CI/CD code review routing patterns that cut LLM token spend by 40-80% while maintaining review quality. Includes model tiering, context compression, and more.

The Lineman team

7 CI/CD Review Routing Patterns for Lower LLM Spend

Quick guide: 7 CI/CD review routing patterns for engineering teams

  1. Lineman: The top choice for automatic tool-output compression that cuts token spend by 40%+ while maintaining review quality
  2. Code health-based triage: Routes tasks based on file complexity metrics before generation begins
  3. Diff size filtering: Skips trivial changes (whitespace, config bumps) to reduce unnecessary model calls
  4. Model tiering by task complexity: Assigns light, standard, or heavy models based on detected difficulty
  5. Semantic caching: Reuses prior review findings for similar code patterns
  6. Context compression pipelines: Summarizes bulky file reads and test logs before sending to the reviewer model
  7. Two-pass verification: Separates recall (catch everything) from precision (filter false positives) into distinct LLM calls

How we chose these CI/CD review routing patterns

Every pattern on this list addresses a specific cause of token waste in AI-assisted code review workflows. Your CI/CD pipeline likely sends full diffs, entire file contents, and verbose test logs to a frontier model on every PR—even when a cheaper model would produce the same result.

We evaluated each pattern against three criteria:

  • Measurable token reduction: Does it cut context window consumption by a quantifiable percentage?
  • Quality preservation: Does review accuracy stay within acceptable bounds after routing?
  • Workflow fit: Can your team implement it without overhauling existing CI/CD infrastructure?
  • Verification capability: Does your pipeline have a gate (test suite, linter, type checker) to catch routing failures?
  • Cost asymmetry exploitation: Does it capitalize on the price gap between frontier and smaller models?

The 7 CI/CD review routing patterns for lower LLM spend

1. Lineman: Automatic tool-output compression for code review

Lineman intercepts the data-heavy tool calls in your review workflow—file reads, build logs, test results—and hands your model a distilled version instead of the full output. The mechanics are simple: the bulky context never enters the main model's window, so it never gets billed.

On Lineman's benchmarks, this cuts 40%+ of tokens while holding output quality at 98.3% of baseline. Because Lineman operates at the tool-output layer, you keep prompting exactly as you do now. The integration installs in minutes inside Claude Code with no workflow changes required.

Lineman features

  • Language-agnostic compression: Works across Python, TypeScript, Go, and other languages without configuration changes
  • Real-time token savings statistics: See exactly how much context Lineman trims on each review task
  • Sub-2-second latency per delegated task: Fast enough to go unnoticed in your CI/CD timing budget
  • Maintains main model focus on reasoning: Offloads grunt work (log parsing, file summarization) to smaller models while your frontier model handles genuinely hard decisions
  • Transient processing: Code passes through without persistent storage, protecting your intellectual property

Lineman pros and cons

Pros:

  • Achieves average 53% token reduction with 98.3% baseline output quality retention on Lineman's benchmarks
  • No workflow changes—install and your existing prompts work as before
  • 14-day free trial with no card required to validate savings on your own codebase

Cons:

  • Requires API key connection for service delivery (takes minutes to set up)
  • Token savings vary by task type—data-heavy tasks see higher reductions than pure reasoning tasks
  • Currently optimized for Claude Code workflows; other agent frameworks may need additional setup

2. Code health-based triage: Route by file complexity

The Triage framework, described in recent academic research, uses code health metrics as a pre-generation routing signal. The core insight: clean, well-structured code can be reviewed correctly by cheaper models, while messy, complex code requires frontier-model reasoning capacity.

CodeHealth aggregates 25+ sub-factors (cyclomatic complexity, coupling, file size, duplication, naming) into a 1–10 composite score. Files scoring 9–10 route to your light-tier model; files scoring 1–4 go straight to the heavy tier. The mechanism is structural: clean code reduces the reasoning steps needed to trace dependencies and side effects.

Code health-based triage features

  • Pre-computed metrics: Per-file scores are calculated once and updated incrementally after each passing task
  • Three-tier routing: Light (e.g., Haiku), Standard (e.g., Sonnet), Heavy (e.g., Opus) based on health thresholds
  • Verification gate integration: Failed reviews trigger automatic fallback to the heavy tier

Code health-based triage pros and cons

Pros:

  • Exploits measurable code quality differences to reduce model costs
  • Works with any model family—swap underlying models with tier recalibration only
  • Metric computation happens once per file, not per review

Cons:

  • Requires initial setup of code health scoring infrastructure
  • CodeHealth is a proprietary metric; open-source alternatives (cyclomatic complexity, Halstead metrics) may have weaker routing signal
  • Multi-file tasks route based on worst-health file, which can trigger unnecessary heavy-tier usage

3. Diff size filtering: Skip trivial changes

A diff triage model classifies incoming PRs before the main review begins. Whitespace-only changes, lockfile updates, and config bumps route to a bypass path that skips LLM review entirely or uses a minimal Haiku-tier pass.

According to production code review architectures, this filtering step alone removes 20–30% of unnecessary model calls. The triage model itself costs a fraction of a cent per classification.

Diff size filtering features

  • Pattern matching: Identifies generated files, lockfiles, and trivial diffs before any LLM invocation
  • Risk classification: Tags high-risk files (auth, payments, SQL) for escalation to deeper review
  • Configurable thresholds: Teams set their own definitions of "trivial" based on file patterns

Diff size filtering pros and cons

Pros:

  • Immediate cost savings with minimal implementation effort
  • Reduces latency on PRs that do not need full review
  • Works independently of your primary review model

Cons:

  • Requires maintenance of filter rules as codebase patterns evolve
  • Aggressive filtering may miss subtle issues in "trivial" changes
  • Classification errors can route sensitive changes to bypass paths

4. Model tiering by task complexity: Right model for the job

Not every review task requires Opus-tier reasoning. Production systems route requests based on detected complexity: simple lint-style checks go to Haiku, standard code review goes to Sonnet, and security-sensitive or multi-file refactors escalate to Opus.

The cost asymmetry is significant: Sonnet costs roughly a fifth of Opus per token. If 60% of your reviews can be handled by the standard tier, you cut that portion of spend by 80%.

Model tiering features

  • Complexity classification: A lightweight model scores each task's difficulty before routing
  • Escalation paths: Failed verifications trigger automatic retry on the next tier up
  • Per-tier prompt optimization: Simpler tasks use shorter system prompts, compounding savings

Model tiering pros and cons

Pros:

  • Matches model capability to task requirements
  • Preserves frontier-model quality for tasks that genuinely need it
  • Router overhead is negligible compared to main model inference

Cons:

  • Misclassification causes either wasted spend (over-routing) or failed reviews (under-routing)
  • Requires labeled data or heuristics to train/configure the router
  • Cross-tier coherence can degrade when tasks span multiple complexity levels

5. Semantic caching: Reuse prior review findings

Your codebase likely contains repeated patterns—similar functions, standard error handling, common API calls. Semantic caching embeds review findings and retrieves them when the model encounters similar code.

Instead of regenerating the same feedback for the hundredth instance of improper null checking, the system returns the cached finding. This reduces LLM calls by 40–60% for codebases with recurring patterns.

Semantic caching features

  • Embedding-based similarity: Matches code snippets against previously reviewed patterns
  • Configurable similarity thresholds: Teams control how close a match must be to trigger cache retrieval
  • Cache invalidation: Stale findings expire based on codebase evolution or rule changes

Semantic caching pros and cons

Pros:

  • Eliminates redundant LLM calls for common patterns
  • Improves review consistency across similar code
  • Latency drops to milliseconds for cache hits

Cons:

  • Requires embedding infrastructure (vector database, embedding model)
  • Cache misses on novel code patterns provide no benefit
  • Cached findings may become outdated as coding standards evolve

6. Context compression pipelines: Summarize before sending

File reads, build logs, and test results often contain thousands of tokens of noise. A preprocessing layer summarizes these outputs before they reach your review model—extracting the relevant signals while discarding the bulk.

Research shows this approach can reduce RAG payloads by 80–90%. The compression model (typically Haiku-tier) costs far less than sending raw context to your frontier model.

Context compression features

  • Hierarchical summarization: Documents compress in stages (chunk summaries → merged summary → final context)
  • Selective extraction: Only task-relevant signals pass through to the main model
  • Smaller-model preprocessing: Haiku or similar handles compression while Sonnet/Opus handles reasoning

Context compression pros and cons

Pros:

  • Dramatic token reduction on data-heavy tasks
  • Main model focuses on reasoning over relevant signals
  • Works alongside other routing patterns for compounding savings

Cons:

  • Compression is lossy—critical details may be discarded
  • Adds latency from the preprocessing step
  • Requires tuning to balance compression ratio against information loss

7. Two-pass verification: Separate recall from precision

A single-pass review often produces findings where 20–30% are false positives. Production teams have found that splitting review into two passes—first capture everything, then filter—improves precision without complex prompt engineering.

The first pass prioritizes recall: flag every potential issue. The second pass receives those findings and identifies which are genuine violations. This mirrors how human reviewers operate and reduces the false-positive rate that erodes developer trust in automated review.

Two-pass verification features

  • Recall-focused first pass: Configured to catch everything, accepting higher false-positive rates
  • Precision-focused second pass: Filters findings against false-positive examples and severity thresholds
  • Structured validation: Findings must cite exact file and line references to pass the filter

Two-pass verification pros and cons

Pros:

  • Higher precision without sacrificing recall
  • Simpler prompts than single-pass approaches attempting both goals
  • Filter pass can use a cheaper model than the initial review pass

Cons:

  • Two LLM calls instead of one increases baseline cost
  • Total latency increases by the duration of the second pass
  • Requires examples of false positives to train the filter effectively

Comparison table: CI/CD review routing patterns

PatternToken ReductionImplementation ComplexityVerification Gate Required
Lineman40–75%Low (minutes to install)No
Code health-based triage20–50%High (metrics infrastructure)Yes
Diff size filtering20–30%Low (pattern matching)No
Model tiering30–60%Medium (router logic)Yes
Semantic caching40–60%Medium (vector database)No
Context compression60–90%Medium (preprocessing pipeline)No
Two-pass verification0% (quality focus)Low (second LLM call)No

How do you measure token savings in CI/CD code review?

Run /context (or equivalent) before and after implementing a routing pattern. Compare token counts per PR across a sample of 50+ reviews. Track cost per successful review, not just cost per API call—failed reviews that trigger fallback inflate your true spend.

The metrics that matter: tokens per PR (before/after), cost per merged PR, cache hit rate (if using semantic caching), and tier distribution (what percentage routes to each model tier).

What causes token costs to compound in code review workflows?

Two mechanics drive cost compounding in code review. First, context compounding: models are stateless, so every turn re-sends the entire conversation as input. A multi-step review that reads files, analyzes diffs, and iterates on findings pays for accumulated context on every message.

Second, verbose tool output: file reads, build logs, and test results get injected into context as tool results. A single PR review that reads 20 files can easily hit 50,000+ tokens before the model writes its first comment.

Lineman addresses the second mechanic directly by compressing tool output before it enters context. Because the bulk never enters the window, it never compounds across turns.

Why Lineman is the top CI/CD review routing pattern for lower LLM spend

The patterns above require varying levels of infrastructure investment. Code health scoring needs metrics pipelines. Model tiering needs router logic and verification gates. Semantic caching needs embedding infrastructure and vector databases.

Lineman delivers the largest single-pattern token reduction—40%+ on benchmarks—with the lowest implementation barrier. Install in minutes, connect your API key, and your existing review prompts immediately benefit from compressed tool outputs.

The mechanics work in your favor: tool output accounts for over half a typical CI/CD review bill. Lineman intercepts that output at the source, hands your model a distilled version, and lets the main model focus on reasoning rather than parsing verbose logs.

For engineering teams running AI-assisted code review at scale, Lineman transforms the cost equation without requiring workflow changes, model swaps, or infrastructure overhauls. Get started with Lineman and see your projected token savings before committing.

FAQs about CI/CD review routing patterns for lower LLM spend

What is CI/CD code review routing?

CI/CD code review routing directs each pull request or code review task to the most cost-effective model tier based on task characteristics. Instead of sending every review to an expensive frontier model, routing patterns match model capability to task complexity.

How much can routing patterns reduce LLM costs?

Combined routing patterns can reduce LLM spend by 60–80% while maintaining review quality. Lineman alone achieves 40–75% reduction on data-heavy tasks by compressing tool outputs before they enter the model's context window.

Do I need to change my prompts to use these patterns?

Most patterns work without prompt changes. Lineman operates at the tool-output layer—you keep prompting exactly as you do now. Model tiering and semantic caching may benefit from prompt adjustments, but they are not required to see initial savings.

Which pattern should I implement first?

Start with Lineman for immediate token reduction with minimal setup. Add diff size filtering next for quick wins on trivial PRs. Model tiering and code health routing deliver larger savings but require more infrastructure investment.

Can I combine multiple routing patterns?

Yes. Patterns work together for compounding savings. A typical production stack uses diff filtering to skip trivial changes, model tiering for complexity-based routing, and Lineman for tool-output compression—each addressing a different source of token waste.

What verification is needed for model tiering?

Model tiering works best with a verification gate—test suite, linter, or type checker—that catches routing failures. When a lighter model's output fails verification, the task automatically retries on a heavier tier. Without verification, misrouted tasks may produce incorrect reviews.

How does Lineman compare to prompt compression techniques?

Prompt compression reduces the tokens in your system prompt and instructions. Lineman compresses tool outputs—file reads, logs, test results—which account for the majority of tokens in code review workflows. The two approaches address different token sources and can be combined.

Related

Product

How to Build an LLM Spend Audit by Department in 7 Steps (2026)

Quick Guide: How to Build an LLM Spend Audit by Department in 7 Steps Define your cost attribution dimensions — Decide whether you'll track by department, team, repository, or individual developer. Set up token telemetry collection — Install an SDK wrapper or proxy that captures every LLM API call with metadata. Configure department tagging — Map each request to a department using git context, API keys, or manual labels. Aggregate costs by time window — Build hourly, daily, and monthly rollups so you can spot trends and spikes. Add prompt compression middleware — Use Lineman to cut token costs by 40%+ while maintaining output quality. Create budget thresholds and alerts — Set per-department limits that notify you before overspending. Export to your FinOps dashboard — Push data to CloudWatch, Prometheus, or your existing observability stack. How to Build a Department-Level LLM Spend Audit 1. Define Your Cost Attribution Dimensions Start by mapping how your organization actually uses LLM APIs. Most engineering teams find that repository-level attribution gives the clearest picture of spend.

Product

How Source Code Context Reduction Cuts LLM Spend

If you manage AI coding tools at scale, you've noticed the bill grows faster than usage does. The root cause: LLM API cost optimization starts with understanding where your tokens actually go. Most of the cost comes from context compounding and verbose tool output, not reasoning.

Product

How to Cut Code Boilerplate Tokens in AI Coding in 7 Steps (2026)

Your AI coding assistant burns tokens on repetitive code boilerplate, file reads, and build logs before it even starts reasoning about your task. Lineman cuts that overhead by 40%+ while maintaining output quality. This guide walks you through seven steps to identify and reduce the redundant context that inflates your token bill.