Skip to content

Instantly share code, notes, and snippets.

@kyo-takano
Created July 29, 2026 05:28
Show Gist options
  • Select an option

  • Save kyo-takano/01d53b53bca2b76c1d594347674b65d7 to your computer and use it in GitHub Desktop.

Select an option

Save kyo-takano/01d53b53bca2b76c1d594347674b65d7 to your computer and use it in GitHub Desktop.
Xet-GC: Garbage Collector for Hugging Face Storage with Xet Backend

Xet-GC semi-automates the cleanup of Hugging Face repositories bloated by Xet.

image

With the "LFS Files" modal open in your settings, this script maps each row of the table to its corresponding "Possible filename," which is hidden within a tooltip mask. By parsing the DOM to extract this information, the script retains only the most recent version of each unique filename (assuming the first occurrence from top to bottom is the latest) and automatically selects all older duplicates.


  1. Open the Settings of your Hugging Face repository and navigate to Storage Usage > List Large Files.
  2. Open your browser's Developer Tools console, then copy and paste the code below. It will automatically check the boxes for all older, duplicate large files.
(function() {
    // Grab all the rows in the "LFS Files" table
    const rows = document.querySelectorAll('tr.text-smd');
    
    // Grab all tooltips, convert to an Array, and filter for the ones containing filenames
    const allTooltips = Array.from(document.querySelectorAll('.tooltip-mask .tooltip'));
    const fileTooltips = allTooltips.filter(tt => tt.textContent && tt.textContent.includes('Possible filename'));

    // Sanity check to ensure the DOM is fully loaded and structures match
    if (rows.length !== fileTooltips.length) {
        console.error(`Lengths do not match. Found ${rows.length} rows and ${fileTooltips.length} file tooltips. Ensure the page is fully loaded.`);
        return;
    }

    const seenFilenames = new Set();
    let checkedCount = 0;

    for (let i = 0; i < rows.length; i++) {
        const rawText = fileTooltips[i].textContent || "";
        const filename = rawText.replace('Possible filename:', '').trim();
        
        const checkbox = rows[i].querySelector('input[type="checkbox"]');

        if (!filename || !checkbox) continue;

        if (seenFilenames.has(filename)) {
            // If the filename is already in the Set, it is an older duplicate. Check the box.
            if (!checkbox.checked) {
                checkbox.click(); // Trigger native click to ensure framework events fire correctly
                checkedCount++;
            }
        } else {
            // First time seeing this filename (latest version), add it to the Set and skip checking.
            seenFilenames.add(filename);
        }
    }

    console.log(`Execution complete. Checked ${checkedCount} duplicate files. Ready for removal.`);
})();
  1. Finally, click "Remove selected", enter the repository ID, and confirm the deletion.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment