Electrical Gremlin Stalling my car

My 2002 Jetta automatic 170k miles seems to have an electrical problem that the couple mechanics I have taken it to don’t seem to find. It left me stranded, It wouldn’t make a sound, all of this after starting 10 minutes before. The shop said that it was a dead cell battery, but I don’t believe them. They changed battery and it worked fine for a couple months, but now the weird electrical glitches started again. The main glitch is that once in a while, not often the car will stall when coming to a stop. Usually after being park overnight or for a couple of hours. I’ll just start it again and after a a minute or so a loud beep comes from the dashboard, but no light come on, and the cars keeps running fine. This happens once every 2 or 3 weeks. In the mean time the powered equipment in the car is always deprograming. the clock every time I start the car has a different time. The power lock and windows some times work some time doesn’t, Sometimes 1 window doesn’t work but the other do. And today I went to start the car and nothing again, pull the key out and the clock and odometer started flashing while a clicking sound came out of the steering column and from the back of the cabin(like the trunk maybe). Then I went to check the battery, just because, and decided to wiggle the cable hub that seats on top of the battery, and when I return to start the car everything looked ok and the car started right away. It’s been running fine for 2 days now. Any clues? What’s that cable hub on top of the battery for? like I said the mechanics can’t find anything.

Sounds like a problem with the battery cables.
Try this: with the engine off turn on the parking lights.
Watch them as you wiggle the battery cables.
If they flicker on and off you’ve found where the poor connection is.
Replace the offending cable. There can be hidden corrosion.