Skip to main content
hooksSource-backedReview first Safety Privacy

CSS Unused Selector Detector - Hooks

Detects unused CSS selectors when stylesheets are modified to keep CSS lean using PurgeCSS, PostCSS, and content analysis. This hook runs on CSS/SCSS file write/edit operations and analyzes stylesheets to identify unused selectors, generate optimized output, and report before/after size metrics.

by JSONbored·added 2025-09-19·
HarnessClaude Code
Trigger:PostToolUse
Review first review before installing

Open the source and read safety notes before installing.

Citation facts

Source-backed facts for citing this resource, derived directly from the registry — also available as plain text for AI assistants.

Source URLs
https://purgecss.com/, https://github.com/JSONbored/awesome-claude/blob/main/content/hooks/css-unused-selector-detector.mdx
Safety notes
Runs automatically on its configured Claude Code hook event and executes shell logic that can read, modify, or delete files in your project (and may run builds, installs, or network calls); review the script and scope it to expected paths before enabling.
Privacy notes
Receives Claude Code hook input (session metadata, file paths, and tool output) and reads local project files; review what the script logs or forwards to external services and keep credentials out of its output.
Author
JSONbored
Claim status
unclaimed
Last verified
2025-09-19

Decision playbook

Review trust signals before you adopt

Signals are present but mixed. Use the checklist below to confirm the source and operational safety for your environment.

Compare context
Selected

0

Current score

78

Baseline

Delta

No baseline selected

No major trust-signal divergence detected in the current selection.

Source and provenance checks

Complete

Confirm ownership and provenance before trusting install instructions.

  • Source link availableRequired

    Open the canonical repository and verify ownership.

    Done
  • Source provenance statusRequired

    Marked as source-backed.

    Done
  • Metadata reviewed

    Registry metadata indicates a reviewed listing.

    Done

Safety and privacy checks

Complete

Validate risk disclosures before installation or API wiring.

  • Safety notes presentRequired

    Review the listed safety guidance before running commands.

    Done
  • Privacy notes presentRequired

    Review data handling notes before connecting accounts or secrets.

    Done
  • Trust level risk gateRequired

    Trust level does not block evaluation.

    Done

Package and install checks

Needs review

Check package metadata and artifact integrity signals.

  • Install payload available

    Install or copy payload is available for review.

    Done
  • Package verification flag

    No package verification flag provided.

    Pending
  • Checksum metadata

    No checksum provided for downloaded artifact.

    Pending

Compare-driven decision checks

Needs review

Use compare context to validate trade-offs before adoption.

  • Compare tray has multiple entries

    Add at least one more entry to compare trust differences.

    Pending
  • Baseline comparison available

    No baseline peer selected yet.

    Pending
  • Diverging trust signals identified

    No major trust-signal divergence found.

    Pending

Setup at a glance

CLI install

Copy-ready — paste the snippet to get started.

Install command

Provided

Config snippet

Provided

Copy snippet

Provided

Prerequisites

None

Platforms

1 listed

Difficulty

0/100

Adoption plan

Balanced adoption plan

Current risk score 16/100. Use staged verification before broader rollout.

Risk 16

Pre-adoption checks

Validate source and review signals before any execution.

  • Confirm source provenanceRequired

    Source URL/provenance metadata is present.

    Done
  • Confirm metadata review state

    Listing has review metadata.

    Done
  • Verify install payload

    Install/config payload exists and can be inspected.

    Done

Security checks

Confirm safety, privacy, and package integrity signals.

  • Review safety notesRequired

    Safety notes are present.

    Done
  • Review privacy notesRequired

    Privacy notes are present.

    Done
  • Verify package integrity metadata

    No package verification/checksum metadata.

    Pending

Rollout

Adopt in controlled steps based on the selected plan.

  • Run in isolated sandbox firstRequired

    Use a constrained sandbox and observe behavior across multiple tasks.

    Pending
  • Roll out graduallyRequired

    Roll out to a small cohort before wider usage.

    Pending
  • Set monitoring and fallback

    Define rollback path and monitor errors after adoption.

    Pending

Evidence readiness

Evidence readiness matrix · balanced

Required evidence gates are covered (5/6 signals complete).

Risk 15

Source provenance

Present

Source repository/provenance is listed.

Required in this preset

Metadata review

Present

Review metadata is present.

Required in this preset

Safety notes

Present

Safety notes are present.

Required in this preset

Privacy notes

Present

Privacy notes are present.

Optional in this preset

Package integrity

Missing

Package integrity metadata is missing.

Optional in this preset

Install payload

Present

Install payload is available.

Required in this preset

Required evidence gates are covered for this preset.

Decision timeline

Decision timeline · balanced

5/6 steps complete with no blocking gaps for this preset.

Risk 14

triage

Confirm source provenanceRequired

Source/provenance metadata is available.

Done

triage

Check metadata review statusRequired

Review metadata is available.

Done

verify

Review safety notesRequired

Safety notes are available.

Done

verify

Review privacy notes

Privacy notes are available.

Done

verify

Validate package integrity metadata

Package integrity metadata is missing.

Pending

rollout

Verify install payload and commandsRequired

Install payload is available.

Done

No required blockers for this timeline preset.

Safety & privacy surface

Safety & privacy surface

1 safety and 1 privacy notes across 2 risk areas. Review closely: credentials & tokens, permissions & scopes.

2 areas
  • SafetyPermissions & scopesRuns automatically on its configured Claude Code hook event and executes shell logic that can read, modify, or delete files in your project (and may run builds, installs, or network calls); review the script and scope it to expected paths before enabling.
  • PrivacyCredentials & tokensReceives Claude Code hook input (session metadata, file paths, and tool output) and reads local project files; review what the script logs or forwards to external services and keep credentials out of its output.

Safety notes

  • Runs automatically on its configured Claude Code hook event and executes shell logic that can read, modify, or delete files in your project (and may run builds, installs, or network calls); review the script and scope it to expected paths before enabling.

Privacy notes

  • Receives Claude Code hook input (session metadata, file paths, and tool output) and reads local project files; review what the script logs or forwards to external services and keep credentials out of its output.

Schema details

Install type
cli
Reading time
1 min
Difficulty score
0
Troubleshooting
Yes
Breaking changes
No
Skill and platform metadata
Retrieval sources
https://purgecss.com/https://code.claude.com/docs/en/hooks
Runtime and command metadata
Trigger
PostToolUse
Script language
bash
Script body
#!/usr/bin/env bash

# Read the tool input from stdin
INPUT=$(cat)
TOOL_NAME=$(echo "$INPUT" | jq -r '.tool_name')
FILE_PATH=$(echo "$INPUT" | jq -r '.tool_input.file_path // .tool_input.path // ""')

if [ -z "$FILE_PATH" ]; then
  exit 0
fi

# Check if it's a CSS/SCSS file
if [[ "$FILE_PATH" == *.css ]] || [[ "$FILE_PATH" == *.scss ]] || [[ "$FILE_PATH" == *.sass ]]; then
  echo "🔍 Analyzing CSS file for unused selectors: $FILE_PATH" >&2
  
  # Check if file exists
  if [ ! -f "$FILE_PATH" ]; then
    echo "📁 CSS file does not exist yet, skipping analysis" >&2
    exit 0
  fi
  
  # Get original file size
  ORIGINAL_LINES=$(wc -l < "$FILE_PATH" 2>/dev/null || echo "0")
  ORIGINAL_SIZE=$(wc -c < "$FILE_PATH" 2>/dev/null || echo "0")
  
  echo "📊 Original CSS: $ORIGINAL_LINES lines, $ORIGINAL_SIZE bytes" >&2
  
  # Try PurgeCSS if available
  if command -v npx &> /dev/null && npx purgecss --version &> /dev/null; then
    echo "🧹 Running PurgeCSS analysis..." >&2
    
    # Create analysis directory
    mkdir -p css-analysis
    
    # Run PurgeCSS with multiple content patterns
    if npx purgecss --css "$FILE_PATH" \
      --content './src/**/*.{html,js,jsx,ts,tsx,vue,svelte}' \
      --content './**/*.{html,js,jsx,ts,tsx,vue,svelte}' \
      --output ./css-analysis/ 2>/dev/null; then
      
      # Analyze results
      PURGED_FILE="./css-analysis/$(basename "$FILE_PATH")"
      if [ -f "$PURGED_FILE" ]; then
        PURGED_LINES=$(wc -l < "$PURGED_FILE" 2>/dev/null || echo "0")
        PURGED_SIZE=$(wc -c < "$PURGED_FILE" 2>/dev/null || echo "0")
        
        SAVED_LINES=$((ORIGINAL_LINES - PURGED_LINES))
        SAVED_SIZE=$((ORIGINAL_SIZE - PURGED_SIZE))
        REDUCTION_PERCENT=$((SAVED_SIZE * 100 / ORIGINAL_SIZE))
        
        echo "📉 Optimized CSS: $PURGED_LINES lines, $PURGED_SIZE bytes" >&2
        echo "✅ Potential savings: $SAVED_LINES lines, $SAVED_SIZE bytes ($REDUCTION_PERCENT% reduction)" >&2
        echo "📁 Check css-analysis/$(basename "$FILE_PATH") for optimized version" >&2
      else
        echo "⚠️ PurgeCSS analysis completed but no output generated" >&2
      fi
    else
      echo "❌ PurgeCSS analysis failed - check content paths" >&2
    fi
  else
    echo "💡 Install PurgeCSS (npm install -g purgecss) for CSS optimization analysis" >&2
    
    # Basic analysis without PurgeCSS
    SELECTOR_COUNT=$(grep -o '[.#][a-zA-Z][-a-zA-Z0-9_]*' "$FILE_PATH" 2>/dev/null | sort -u | wc -l || echo "0")
    echo "📊 Found $SELECTOR_COUNT unique CSS selectors in file" >&2
  fi
  
  echo "✅ CSS analysis completed for $FILE_PATH" >&2
else
  echo "File $FILE_PATH is not a CSS/SCSS file, skipping analysis" >&2
fi

exit 0
Full copyable content
{
  "hooks": {
    "postToolUse": {
      "script": "./.claude/hooks/css-unused-selector-detector.sh",
      "matchers": [
        "write",
        "edit"
      ]
    }
  }
}

About this resource

Features

  • Automatic unused CSS selector detection with PurgeCSS ^6.0.0+ for comprehensive content scanning across multiple file types and frameworks
  • Support for CSS, SCSS, SASS, and modern CSS frameworks (Tailwind CSS, Bootstrap, Material UI) with framework-specific optimization
  • Content analysis across HTML, JS, JSX, TS, TSX, Vue, and Svelte files using multiple content path patterns for accurate selector detection
  • Before/after comparison with line count reduction and byte size savings calculation showing percentage reduction metrics
  • Optimized CSS output generation with safelist support for critical framework classes preventing removal of essential styles
  • Integration with modern build workflows supporting Vite, Webpack, Rollup, and PostCSS pipelines for seamless optimization
  • Safelist configuration to protect dynamically-generated classes and framework utilities from being removed during purging
  • Detailed reporting with percentage reduction metrics, file size savings, and optimized output file generation for review

Use Cases

  • Automatic CSS optimization during stylesheet development providing real-time feedback on unused selectors as CSS is modified
  • Dead code elimination in large CSS codebases identifying and removing unused styles to reduce bundle size and improve performance
  • Performance optimization for web applications reducing CSS file size for faster page loads and improved Core Web Vitals
  • CSS bundle size reduction in production builds automatically removing unused styles before deployment to minimize asset size
  • Maintenance of clean, lean stylesheets keeping CSS files organized and free of dead code during long-term project maintenance
  • Framework migration assistance identifying unused framework classes when migrating between CSS frameworks or design systems

Installation

  1. Create hooks directory: mkdir -p .claude/hooks
  2. Create hook file: touch .claude/hooks/css-unused-selector-detector.sh
  3. Make executable: chmod +x .claude/hooks/css-unused-selector-detector.sh
  4. Add configuration from Hook Configuration section above to .claude/settings.json or ~/.claude/settings.json
  5. Alternative: Use the interactive /hooks command in Claude Code

Config paths

  • Local (not committed): .claude/settings.local.json
  • User settings (global): ~/.claude/settings.json
  • Project-wide (committed): .claude/settings.json

Requirements

  • Claude Code CLI installed
  • Project directory initialized
  • Bash shell available
  • jq installed (for JSON parsing from stdin)
  • Optional: PurgeCSS ^6.0.0 (npm install -g purgecss or npx purgecss) for unused CSS detection, PostCSS ^8.4.0+ for CSS processing
  • Node.js 18+ and npm/yarn/pnpm (for installing and running PurgeCSS and PostCSS, required for CSS optimization workflows)

Hook Configuration

{
  "hooks": {
    "postToolUse": {
      "script": "./.claude/hooks/css-unused-selector-detector.sh",
      "matchers": ["write", "edit"]
    }
  }
}

Hook Script

#!/usr/bin/env bash

# Read the tool input from stdin
INPUT=$(cat)
TOOL_NAME=$(echo "$INPUT" | jq -r '.tool_name')
FILE_PATH=$(echo "$INPUT" | jq -r '.tool_input.file_path // .tool_input.path // ""')

if [ -z "$FILE_PATH" ]; then
  exit 0
fi

# Check if it's a CSS/SCSS file
if [[ "$FILE_PATH" == *.css ]] || [[ "$FILE_PATH" == *.scss ]] || [[ "$FILE_PATH" == *.sass ]]; then
  echo "🔍 Analyzing CSS file for unused selectors: $FILE_PATH" >&2

  # Check if file exists
  if [ ! -f "$FILE_PATH" ]; then
    echo "📁 CSS file does not exist yet, skipping analysis" >&2
    exit 0
  fi

  # Get original file size
  ORIGINAL_LINES=$(wc -l < "$FILE_PATH" 2>/dev/null || echo "0")
  ORIGINAL_SIZE=$(wc -c < "$FILE_PATH" 2>/dev/null || echo "0")

  echo "📊 Original CSS: $ORIGINAL_LINES lines, $ORIGINAL_SIZE bytes" >&2

  # Try PurgeCSS if available
  if command -v npx &> /dev/null && npx purgecss --version &> /dev/null; then
    echo "🧹 Running PurgeCSS analysis..." >&2

    # Create analysis directory
    mkdir -p css-analysis

    # Run PurgeCSS with multiple content patterns
    if npx purgecss --css "$FILE_PATH" \
      --content './src/**/*.{html,js,jsx,ts,tsx,vue,svelte}' \
      --content './**/*.{html,js,jsx,ts,tsx,vue,svelte}' \
      --output ./css-analysis/ 2>/dev/null; then

      # Analyze results
      PURGED_FILE="./css-analysis/$(basename "$FILE_PATH")"
      if [ -f "$PURGED_FILE" ]; then
        PURGED_LINES=$(wc -l < "$PURGED_FILE" 2>/dev/null || echo "0")
        PURGED_SIZE=$(wc -c < "$PURGED_FILE" 2>/dev/null || echo "0")

        SAVED_LINES=$((ORIGINAL_LINES - PURGED_LINES))
        SAVED_SIZE=$((ORIGINAL_SIZE - PURGED_SIZE))
        REDUCTION_PERCENT=$((SAVED_SIZE * 100 / ORIGINAL_SIZE))

        echo "📉 Optimized CSS: $PURGED_LINES lines, $PURGED_SIZE bytes" >&2
        echo "✅ Potential savings: $SAVED_LINES lines, $SAVED_SIZE bytes ($REDUCTION_PERCENT% reduction)" >&2
        echo "📁 Check css-analysis/$(basename "$FILE_PATH") for optimized version" >&2
      else
        echo "⚠️ PurgeCSS analysis completed but no output generated" >&2
      fi
    else
      echo "❌ PurgeCSS analysis failed - check content paths" >&2
    fi
  else
    echo "💡 Install PurgeCSS (npm install -g purgecss) for CSS optimization analysis" >&2

    # Basic analysis without PurgeCSS
    SELECTOR_COUNT=$(grep -o '[.#][a-zA-Z][-a-zA-Z0-9_]*' "$FILE_PATH" 2>/dev/null | sort -u | wc -l || echo "0")
    echo "📊 Found $SELECTOR_COUNT unique CSS selectors in file" >&2
  fi

  echo "✅ CSS analysis completed for $FILE_PATH" >&2
else
  echo "File $FILE_PATH is not a CSS/SCSS file, skipping analysis" >&2
fi

exit 0

Examples

CSS Unused Selector Detector Hook Script

Complete hook script that detects unused CSS selectors when stylesheets are modified

#!/usr/bin/env bash
INPUT=$(cat)
TOOL_NAME=$(echo "$INPUT" | jq -r ".tool_name")
FILE_PATH=$(echo "$INPUT" | jq -r ".tool_input.file_path // .tool_input.path // \"\"")
if [ -z "$FILE_PATH" ]; then exit 0; fi
if [[ "$FILE_PATH" == *.css ]] || [[ "$FILE_PATH" == *.scss ]]; then
  ORIGINAL_LINES=$(wc -l < "$FILE_PATH" 2>/dev/null || echo "0")
  ORIGINAL_SIZE=$(wc -c < "$FILE_PATH" 2>/dev/null || echo "0")
  if command -v npx &> /dev/null && npx purgecss --version &> /dev/null; then
    mkdir -p css-analysis
    npx purgecss --css "$FILE_PATH" --content "./src/**/*.{html,js,jsx,ts,tsx}" --output ./css-analysis/ 2>/dev/null
    PURGED_FILE="./css-analysis/$(basename "$FILE_PATH")"
    if [ -f "$PURGED_FILE" ]; then
      PURGED_LINES=$(wc -l < "$PURGED_FILE" 2>/dev/null || echo "0")
      PURGED_SIZE=$(wc -c < "$PURGED_FILE" 2>/dev/null || echo "0")
      SAVED=$((ORIGINAL_SIZE - PURGED_SIZE))
      echo "✅ Potential savings: $SAVED bytes" >&2
    fi
  fi
fi
exit 0

Hook Configuration

Complete hook configuration for .claude/settings.json to enable CSS unused selector detection on file changes

{
  "hooks": {
    "postToolUse": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "./.claude/hooks/css-unused-selector-detector.sh",
            "matchers": ["write", "edit"]
          }
        ]
      }
    ]
  }
}

CSS Analysis with Safelist

Enhanced hook script using PurgeCSS with safelist patterns to protect framework classes

#!/usr/bin/env bash
INPUT=$(cat)
FILE_PATH=$(echo "$INPUT" | jq -r ".tool_input.file_path // .tool_input.path // \"\"")
if [ -z "$FILE_PATH" ] || [[ ! "$FILE_PATH" == *.{css,scss,sass} ]]; then exit 0; fi
if command -v npx &> /dev/null && npx purgecss --version &> /dev/null; then
  mkdir -p css-analysis
  npx purgecss --css "$FILE_PATH" \
    --content "./src/**/*.{html,js,jsx,ts,tsx,vue,svelte}" \
    --content "./app/**/*.{html,js,jsx,ts,tsx}" \
    --safelist [/^btn-/, /^nav-/, /^modal-/] \
    --output ./css-analysis/ 2>/dev/null
  echo "✅ CSS analysis with safelist completed" >&2
fi
exit 0

CSS Analysis with Percentage Reporting

Enhanced hook script with detailed percentage reduction reporting

#!/usr/bin/env bash
INPUT=$(cat)
FILE_PATH=$(echo "$INPUT" | jq -r ".tool_input.file_path // .tool_input.path // \"\"")
if [ -z "$FILE_PATH" ] || [[ ! "$FILE_PATH" == *.{css,scss} ]]; then exit 0; fi
ORIGINAL_SIZE=$(wc -c < "$FILE_PATH" 2>/dev/null || echo "0")
if command -v npx &> /dev/null && npx purgecss --version &> /dev/null; then
  mkdir -p css-analysis
  npx purgecss --css "$FILE_PATH" --content "./**/*.{html,js,jsx,ts,tsx}" --output ./css-analysis/ 2>/dev/null
  PURGED_FILE="./css-analysis/$(basename "$FILE_PATH")"
  if [ -f "$PURGED_FILE" ]; then
    PURGED_SIZE=$(wc -c < "$PURGED_FILE" 2>/dev/null || echo "0")
    SAVED=$((ORIGINAL_SIZE - PURGED_SIZE))
    PERCENT=$((SAVED * 100 / ORIGINAL_SIZE))
    echo "📊 Original: $ORIGINAL_SIZE bytes, Optimized: $PURGED_SIZE bytes" >&2
    echo "✅ Savings: $SAVED bytes ($PERCENT% reduction)" >&2
  fi
fi
exit 0

Basic Selector Count Analysis

Basic hook script that counts CSS selectors without requiring PurgeCSS

#!/usr/bin/env bash
INPUT=$(cat)
FILE_PATH=$(echo "$INPUT" | jq -r ".tool_input.file_path // .tool_input.path // \"\"")
if [ -z "$FILE_PATH" ] || [[ ! "$FILE_PATH" == *.{css,scss} ]]; then exit 0; fi
SELECTOR_COUNT=$(grep -oE "[.#][a-zA-Z][-a-zA-Z0-9_]*" "$FILE_PATH" 2>/dev/null | sort -u | wc -l || echo "0")
echo "📊 Found $SELECTOR_COUNT unique CSS selectors" >&2
if [ "$SELECTOR_COUNT" -gt 100 ]; then
  echo "⚠️ High selector count - consider splitting into smaller files" >&2
fi
exit 0

Troubleshooting

PurgeCSS not detecting any unused selectors in CSS

Verify content paths match your project structure: update --content patterns to include all HTML/JSX/TSX files. Check PurgeCSS config safelist if critical selectors are protected. Ensure content files are accessible: test with ls command. Verify file extensions match: use --content pattern with correct glob syntax.

PostToolUse hook only runs for write, not edit operations

Add both matchers to hook config: matchers array should include write and edit. Verify tool_name extraction from stdin matches expected values. Test with echo command to debug tool input parsing. Check hook configuration in .claude/settings.json.

css-analysis directory not created or files missing

Check write permissions in project root directory. Ensure mkdir -p succeeds without errors. Verify PurgeCSS output path is writable. Check disk space if directory creation fails silently. Test directory creation manually: mkdir -p css-analysis && echo OK.

PurgeCSS removes critical CSS framework classes

Add safelist patterns to PurgeCSS config for framework classes using --safelist flag. Use safelist syntax with regex patterns for framework prefixes. Consider extracting framework CSS to separate file excluded from purging. Use safelist patterns like /^btn-/, /^nav-/ for framework class prefixes.

No output generated message despite PurgeCSS success

Check PURGED_FILE path construction matches PurgeCSS output format. Verify basename command extracts correct filename. Ensure output directory exists before PurgeCSS runs. Check PurgeCSS output format and verify --output flag creates files correctly.

CSS analysis is too slow for large stylesheets

Add timeout wrapper to limit execution time. Limit analysis scope to files under specific size threshold. Use faster content scanning by limiting --content patterns to specific directories. Skip analysis for generated files: exclude node_modules, dist, build directories.

PurgeCSS not finding content files in subdirectories

Use recursive glob patterns with ** syntax for subdirectory scanning. Check file permissions to ensure content files are readable. Verify glob pattern syntax matches your file structure. Use absolute paths if relative paths fail. Check PurgeCSS version and upgrade to latest for improved file discovery.

Percentage calculation shows incorrect reduction values

Verify file size calculation uses wc -c for byte count, not wc -l for lines. Check for division by zero errors before percentage calculation. Use proper integer math for percentage calculation. Test with known values to verify calculation logic.

Source citations

Add this badge to your README

Show that CSS Unused Selector Detector - Hooks is listed on HeyClaude. Paste this Markdown into your README — it renders the badge and links back to this page.

Listed on HeyClaude
[![Listed on HeyClaude](https://heyclau.de/badge/hooks/css-unused-selector-detector.svg)](https://heyclau.de/entry/hooks/css-unused-selector-detector)

How it compares

CSS Unused Selector Detector - Hooks side by side with 3 alternatives on trust, install, platform support, and disclosed safety notes — all from reviewed registry metadata.

Next steps differ across entries — use the actions in the table below to copy install commands and source links per resource.

Field

Detects unused CSS selectors when stylesheets are modified to keep CSS lean using PurgeCSS, PostCSS, and content analysis. This hook runs on CSS/SCSS file write/edit operations and analyzes stylesheets to identify unused selectors, generate optimized output, and report before/after size metrics.

Open dossier

A PostToolUse hook that reminds you to enable native query logging for PostgreSQL, Prisma, Sequelize, and TypeORM, and flags possible N+1 patterns when you edit SQL or data-access files.

Open dossier

A Claude Code SessionEnd hook that scans a project for dead code and writes a report to .claude/reports. It runs available tools per language: ESLint and Knip for JS/TS, autoflake or pylint for Python, Knip for unused npm dependencies, ripgrep for unreferenced src files, and jq to flag zero-coverage files.

Open dossier

Alerts when files exceed size thresholds that could impact performance. This PostToolUse hook provides comprehensive file size monitoring when files are created or modified, automatically detecting files that exceed recommended size thresholds for different file types and providing optimization suggestions.

Open dossier
Next stepsDiffers
Trust
Review statusReviewedMaintainer reviewedReviewedMaintainer reviewedReviewedMaintainer reviewedReviewedMaintainer reviewed
Package trustPackage not verifiedPackage not verifiedPackage not verifiedPackage not verified
Source provenanceSource-backedSource-backedSource-backedSource-backed
Submitter
Install riskReview firstReview firstReview firstReview first
Notes Safety Privacy Safety Privacy Safety Privacy Safety Privacy
Brand
Categoryhookshookshookshooks
Sourcesource-backedsource-backedsource-backedsource-backed
AuthorJSONboredJSONboredJSONboredJSONbored
Added2025-09-192025-10-192025-10-192025-09-19
Platforms
Claude Code
Claude Code
Claude Code
Claude Code
Source repo
Safety notesRuns automatically on its configured Claude Code hook event and executes shell logic that can read, modify, or delete files in your project (and may run builds, installs, or network calls); review the script and scope it to expected paths before enabling.Runs automatically after bash, write, or edit activity and inspects files that look like query, model, repository, DAO, or SQL files. Creates .claude/logs/query-performance.log and appends database command or file-analysis events. Uses grep-based heuristics for query warnings and should not be treated as proof of a performance defect.Registered as a SessionEnd hook, so it runs automatically every time a Claude Code session ends. Invokes external tools via npx (ts-prune, Knip, eslint) and locally installed binaries (autoflake, pylint, vulture, jq, rg), which can trigger package downloads and execute project tooling. Defaults to DRY_RUN=true and only writes a report; setting DRY_RUN=false is intended to enable destructive cleanup, so review the report before changing it. Creates directories under .claude/backups and .claude/reports in the working tree.Runs automatically on its configured Claude Code hook event and executes shell logic that can read, modify, or delete files in your project (and may run builds, installs, or network calls); review the script and scope it to expected paths before enabling.
Privacy notesReceives Claude Code hook input (session metadata, file paths, and tool output) and reads local project files; review what the script logs or forwards to external services and keep credentials out of its output.Reads query-related source files and may print file paths, query patterns, and database command strings to local hook output. Stores analyzed file paths and database command text in .claude/logs/query-performance.log. Database command text may include connection names, database names, or other operational details if typed directly into the command.Writes a dead-code report containing file paths, export names, and dependency names from the project to .claude/reports/dead-code-report.txt and echoes it to stderr. Running tools via npx may fetch packages from the npm registry over the network.Receives Claude Code hook input (session metadata, file paths, and tool output) and reads local project files; review what the script logs or forwards to external services and keep credentials out of its output.
Prerequisites— none listed— none listed— none listed— none listed
Install
mkdir -p .claude/hooks && touch .claude/hooks/css-unused-selector-detector.sh && chmod +x .claude/hooks/css-unused-selector-detector.sh
mkdir -p .claude/hooks && touch .claude/hooks/dead-code-eliminator.sh && chmod +x .claude/hooks/dead-code-eliminator.sh
mkdir -p .claude/hooks && touch .claude/hooks/file-size-warning-monitor.sh && chmod +x .claude/hooks/file-size-warning-monitor.sh
Config
{
  "hooks": {
    "postToolUse": {
      "script": "./.claude/hooks/css-unused-selector-detector.sh",
      "matchers": [
        "write",
        "edit"
      ]
    }
  }
}
{
  "hooks": {
    "postToolUse": {
      "script": "./.claude/hooks/database-query-performance-logger.sh",
      "matchers": [
        "bash",
        "write",
        "edit"
      ]
    }
  }
}
{
  "hooks": {
    "sessionEnd": {
      "script": "./.claude/hooks/dead-code-eliminator.sh"
    }
  }
}
{
  "hooks": {
    "postToolUse": {
      "script": "./.claude/hooks/file-size-warning-monitor.sh",
      "matchers": [
        "write",
        "edit"
      ]
    }
  }
}
Citations
ClaimUnclaimedUnclaimedUnclaimedUnclaimed
Open 4 picks in the interactive comparison tool

Related guides

Signals

Loading live community signals…

More like this, weekly

A short, calm digest of reviewed Claude resources. Unsubscribe any time.