bricks_get_class_usage

Phase 5BeginnerRead OnlyComplexity: 3/10
Check where a global class is used across the site

Overview

Returns usage statistics for a specific global class, showing which pages use it and how many elements reference it. This is essential for impact analysis before modifying or deleting a class.

Use this tool to understand how widely a class is used across the site. It helps decide whether a class is safe to delete, rename, or modify, and identifies which pages would be affected by changes.

Key Features

Per-Page Breakdown
Shows which specific pages use the class and how many elements on each page reference it.
Element Count
Returns the total number of elements across all pages that reference this class.
Impact Analysis
Enables informed decisions about class modifications — know exactly what will be affected before making changes.

When to Use

Before deleting a class — check if it is in use and on how many pages
Before renaming or significantly modifying a class — understand the impact
When auditing the design system to find unused classes that can be cleaned up
When consolidating duplicate classes — check which one is more widely used
Prerequisites
The class must exist. Use bricks_get_global_classes to find the class_id.

When NOT to Use

When you just need to list classes — use bricks_get_global_classes instead
When you want to check usage of all classes at once — call this per class individually

Parameters

1 Total Parameters1 Required
class_idstringREQUIRED
ID of the global class to check usage for. Get this from bricks_get_global_classes.

Code Examples

Check usage before modifying a class

Checks how many pages and elements use btn-primary before changing its background color. Shows the class is used on 5 pages with 18 elements.

JSON
// Check usage of btn-primary class before modifying it
bricks_get_class_usage({
  class_id: "d4e5f6"
})
Response
{
  "class_id": "d4e5f6",
  "class_name": "btn-primary",
  "total_pages": 5,
  "total_elements": 18,
  "pages": [
    { "page_id": 33, "title": "Home", "element_count": 4 },
    { "page_id": 45, "title": "About", "element_count": 2 },
    { "page_id": 56, "title": "Services", "element_count": 6 },
    { "page_id": 67, "title": "Contact", "element_count": 3 },
    { "page_id": 78, "title": "Pricing", "element_count": 3 }
  ]
}

Find unused classes for cleanup

Checks if an old class is still referenced anywhere. Returns 0 pages/elements, indicating it is safe to delete.

JSON
// Check if an old class is still in use (cleanup audit)
bricks_get_class_usage({
  class_id: "old123"
})
Response
{
  "class_id": "old123",
  "class_name": "old-button-style",
  "total_pages": 0,
  "total_elements": 0,
  "pages": []
}
// Safe to delete — not used anywhere

Common Mistakes

Skipping the usage check before deleting or significantly modifying a class.
Always call bricks_get_class_usage before bricks_delete_global_class or major bricks_update_global_class changes to understand the impact.
Wrong
// Deleting without checking impact
bricks_delete_global_class({ class_id: "abc123", force: true })
// Oops — 50 elements just lost their styling!
Correct
// Check impact first
bricks_get_class_usage({ class_id: "abc123" })
// Returns: 5 pages, 50 elements
// Decision: update the class instead of deleting
bricks_update_global_class({ class_id: "abc123", settings: { ... } })

Tips & Warnings

Tips & Warnings

Best practice: Call this tool before any destructive action on a class (delete, major rename, or significant style change). The per-page breakdown helps you understand the blast radius of your changes.

Design system audit: Periodically check usage of all classes to identify unused ones that can be cleaned up, keeping the design system lean and maintainable.

Tip: If a class has 0 usage and was created recently, it might be unused because elements have not been assigned to it yet. Check if it was part of Phase 2 setup before deleting.

Return Values

FieldTypeDescription
class_idstringThe ID of the class being checked.
class_namestringThe name of the class being checked.
total_pagesnumberTotal number of pages that use this class.
total_elementsnumberTotal number of elements across all pages that reference this class.
pagesarrayArray of page objects with page ID, title, and element count using this class.

Related Tools

Technical Details

Tool ID
bricks_get_class_usage
API Endpoint
/bricks-mcp/v1/design-system/classes/{class_id}/usage
HTTP Method
GET
Namespace
design-system
Source File
design-system/classes.ts
Version
1.0
Min Bricks Version
1.9
Requires Auth
Yes

Changelog

v1.0
Initial release with per-page breakdown, element counts, and total usage statistics.
20250101