In the Commander format, a special rule applies whenever your commander would move to any zone other than the battlefield or the command zone itself: you may choose to place it in the command zone instead. This applies to being shuffled into a library, being put into a graveyard, being exiled, or being put into your hand. This is covered by CR 903.9.
Specifically, CR 903.9 states that if a commander would be put into its owner's hand, library, graveyard, or exile, that player may put it into the command zone instead. This is a replacement effect applied by the commander's owner, and it can be applied each time the commander changes zones in one of these ways.
It's important to note that this is a choice, not mandatory. You could let your commander be shuffled into your library if you wanted to (unusual, but legal). Also, if the commander goes to the command zone this way, it still counts as having changed zones, which means it will cost an additional 2 generic mana the next time you cast it from the command zone (the 'commander tax,' per CR 903.8).
Example: Your opponent casts Praetor's Counsel targeting your commander in the graveyard, which would shuffle it into your library. You may instead choose to redirect your commander to the command zone, keeping it accessible for future casting rather than lost in your deck.
This rule exists specifically to maintain the fundamental Commander experience of always having access to your commander throughout the game, preventing it from becoming permanently inaccessible inside a shuffled library.
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.