Claude Skills Guide

Claude Code for Core Web Vitals Workflow Tutorial

Core Web Vitals have become essential metrics for web performance, directly impacting user experience and search engine rankings. Google’s Core Web Vitals—Largest Contentful Paint (LCP), First Input Delay (FID), and Cumulative Layout Shift (CLS)—measure loading performance, interactivity, and visual stability. This tutorial shows you how to leverage Claude Code to create efficient workflows for measuring, monitoring, and optimizing these critical metrics.

Understanding Core Web Vitals Metrics

Before diving into workflows, let’s quickly review what each metric measures:

Claude Code can help you audit these metrics, identify issues, and implement fixes systematically. Let’s explore practical workflows.

Setting Up Your Web Vitals Testing Environment

First, create a skill that helps you run Web Vitals audits. This skill will encapsulate the tools and prompts needed for consistent testing.

---
name: web-vitals
description: "Audit and analyze Core Web Vitals for web applications"
tools: [Bash, WebFetch, Read, Write]
---

The skill can use multiple tools to fetch pages, run Lighthouse audits, and analyze results. Before running audits, ensure you have the necessary tools installed:

npm install -g lighthouse

Workflow 1: Running Quick Web Vitals Audits

The most common workflow is running a quick audit on a URL to get baseline metrics. Create a simple bash command within your skill to run Lighthouse:

lighthouse <url> --only-categories=performance --output=json --output-path=<output-file>.json

After running the audit, you can ask Claude to analyze the results:

{
  "audits": {
    "lcp-lazy-loaded": { "score": 0, "details": {...} },
    "layout-shift-elements": { "score": 0, "details": {...} }
  }
}

When Claude returns the JSON audit results, ask it to extract and summarize the Core Web Vitals scores. This is particularly useful for comparing performance before and after optimizations.

Workflow 2: Batch Testing Multiple Pages

For larger sites, you need to test multiple pages systematically. Create a workflow that reads a list of URLs and runs audits on each:

# Read URLs from a file
cat urls.txt | while read url; do
  lighthouse "$url" --only-categories=performance --output=json --output-path="reports/$(basename "$url").json"
done

This batch approach lets you track performance across your entire site. Store the results in a dedicated folder and use Claude to compare them over time.

Workflow 3: Automated Regression Detection

Set up a GitHub Actions workflow that runs Web Vitals audits on every pull request:

name: Core Web Vitals
on: [pull_request]
jobs:
  lighthouse:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Run Lighthouse
        run: |
          npm install -g lighthouse
          lighthouse ${{ vars.SITE_URL }} --only-categories=performance --output=json --output-path=lighthouse.json
      - name: Check thresholds
        run: |
          node check-metrics.js

The check-metrics.js script parses the Lighthouse JSON and fails the build if any Core Web Vitals fall below thresholds. This prevents performance regressions from reaching production.

Workflow 4: Real User Monitoring Integration

For production applications, combine Claude Code with real user monitoring (RUM) data. Export Web Vitals from Google Chrome User Experience Report or your analytics provider:

# Fetch CrUX data (requires API key)
curl "https://chromeuxreport.googleapis.com/v1/records:queryRecord?key=$CRUX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"url": "https://example.com"}'

Use Claude to analyze the RUM data alongside lab data from Lighthouse. This gives you a complete picture—both simulated test results and real-world user experiences.

Common Optimization Patterns

Claude Code can help you implement proven optimization techniques. Here are patterns for each metric:

Optimizing LCP

LCP measures when the largest content element becomes visible. Common optimizations include:

  1. Optimize server response time: Use CDN, enable caching, optimize database queries
  2. Eliminate render-blocking resources: Inline critical CSS, defer non-critical JavaScript
  3. Optimize images: Use WebP/AVIF formats, implement lazy loading for below-fold images
  4. Preload key resources: Use <link rel="preload"> for LCP element images

Optimizing FID

FID measures the delay between first user interaction and browser response. Focus on:

  1. Reduce JavaScript execution time: Code-split, tree-shake, remove unused code
  2. Break up long tasks: Use requestIdleCallback or setTimeout to break large tasks
  3. Optimize third-party scripts: Defer non-critical third-party scripts

Optimizing CLS

CLS measures visual stability during page load. Prevent layout shifts by:

  1. Set explicit dimensions: Always specify width and height attributes for images and videos
  2. Reserve space for ads: Use min-height containers for dynamic ad placements
  3. Font loading optimization: Use font-display: swap and preload web fonts

Continuous Monitoring Strategy

For sustainable performance improvement, establish a monitoring strategy:

  1. Daily lab tests: Run Lighthouse on staging environments
  2. PR-level audits: Block merges that regress Core Web Vitals
  3. Production RUM: Track real user metrics continuously
  4. Alerting: Notify team when metrics exceed thresholds

Claude Code can automate much of this workflow, from running audits to generating reports and alerting stakeholders.

Conclusion

Claude Code transforms Core Web Vitals optimization from a manual, sporadic process into an automated, systematic workflow. By integrating Lighthouse audits into your development pipeline, setting up regression detection, and following proven optimization patterns, you can maintain excellent Core Web Vitals scores consistently.

Start with quick audits on your key pages, establish baseline metrics, then build up to continuous monitoring. Claude Code handles the heavy lifting—running tests, analyzing results, and guiding implementation—so you can focus on building great user experiences.

Remember: good Core Web Vitals scores not only improve user experience but also contribute to better search rankings. Make them a priority in your development workflow.