The Commander format adds a replacement effect (sometimes called the 'command zone replacement') that applies whenever your commander would move to any zone from anywhere. Specifically, if your commander would be exiled, you may choose to redirect it to the command zone instead. This is found in the Commander rules (formally rule 903.9a in the Comprehensive Rules for the Commander format).
This replacement effect is optional — you may choose to let the exile happen normally (for example, if you want the card to be exiled for some strategic reason). But in most cases, players choose the command zone to keep their commander accessible for future recast.
Critically, this applies regardless of how the exile happens. Whether it is a spell like Swords to Plowshares, an ability like Path to Exile, or any other effect, you always have the option to redirect to the command zone. The commander simply returns to the command zone and can be recast by paying its commander tax (an additional {2} for each previous time it was cast from the command zone).
Concrete example: Your opponent casts Path to Exile targeting your commander, Atraxa. When Atraxa would be exiled, you apply the command zone replacement effect and put Atraxa into the command zone instead. You do not search for a basic land (since Atraxa never actually entered exile), and you may recast Atraxa later by paying her mana cost plus {2} commander tax.
Note that the replacement effect can only be applied once per zone change (CR 614.5), so if multiple replacement effects compete, you choose the order — but you can always choose the command zone replacement last to ensure your commander ends up there.
Unofficial fan resource — not affiliated with or endorsed by Wizards of the Coast. Answers are AI-generated estimates grounded in the Comprehensive Rules and are not a substitute for an official judge. Verify anything match-critical.