The rule is that you (nor your employer) can no longer contribute to an HSA if you enroll in Medicare (all Parts). You can use it for paying some of your part of Medicare expenses and even some OTC expenses - you can NOT pay for a Medigap policy out of it because that is optional private coverage (Gap or bridge insurance).
But that also means that you can't sign up for Social Security either because of the auto link between SS and Medicare (Part A- auto sign up)
If you are still working and have coverage and an HSA and want to continue to contribute - just don't sign up for Medicare (no Part) or Social Security until you make plans to leave your employment - 6 months before stop making contributions - to avoid tax consequences and avoid possible late sign-up premium penalties for Med. Part B.
The reason for the rule is because HSA contributions & usage are tax free and are connected to a HDHP - The actual rule is actually based more under the HDHP/HSA plan & the IRS but also involves Medicare because to contribute pre-tax dollars to an HSA you cannot have any health insurance other than an HDHP.
Medicare Interactive.org - Health Savings Accounts (HSAs) and Medicare
It's Always Something . . . . Roseanna Roseannadanna