Get category id for a custom category and display it in a class

I may be missing what you’re looking for but you never actually echo the cat_ID in the li and there’s no reason to assign $cat->cat_ID to $cat_id.

Additionally, I think you could just as well use something like this to get the category id (or ids) to display the current category(ies) of the current post. (using $category[0] will give you the first category)

    <ul>

        <?php 

           $category = get_the_category(); 
           foreach ( $terms as $term ) { ?>

              <li id="tools-<?php echo $category[0]->cat_ID; ?>"><?php echo $term->name; ?></li>

         <?php } ?>
     </ul>