Beans, grounds and brewed
TSA has separate entries. Coffee beans and ground coffee are a yes for both bags. Liquid coffee is a yes in your carry-on only at 3.4 ounces or less. An empty thermos is fine.
Flying home from abroad
TSA’s answer covers screening at US airports. On the way home you go through the other airport’s screening first, and its rules are the ones that count there.
Coming home through US customs
USDA: “Travelers are permitted to bring unlimited quantities of roasted coffee in their luggage without restriction through any U.S. port of entry.” Ground coffee is roasted coffee, so that covers it.
Coffee is also on CBP’s list of foods that are generally admissible.
Declare it either way. USDA says declared food brings no penalty, even when it’s refused. What happens if you don’t.
TSA puts this on every entry: “The final decision rests with the TSA officer on whether an item is allowed through the checkpoint.”