Xanax (alprazolam) can help temporarily with the extreme anxiety from claustrophobia that you feel when you are in confined spaces. However, taking Xanax does not help you to reduce the anxiety long term, and does not help you to extinguish this learned and conditioned behavior.
The best way to help with claustrophobia is to engage with CBT (cognitive behavioral therapy). Anxiety Protocol is a self-help book for anxiety, which uses CBT, the best treatment for claustrophobia: