How often per session or how often per spell deployment are you countering spellcaster PCs via any of the below:
1) Preemptively using unestablished backstory or unilateral access to the offscreen (NPC x has Antimagic wards on their lair/redoubt, Divination and Teleportation exclusion zones mandated by territorial governing bodies, spellcasting is outlawed or aggressively stigmatized, NPC x has a mage with an anti-spellcaster loadout, NPC x IS a mage with an anti-spellcaster loadout, NPC x has Magic Resistance, etc, etc).
Interesting question!
There's multiple things here, so that makes reducing to a "per session" estimate impossible. However, most of what you've listed falls within my personal
Fair Play is Foreshadowing paradigm. By requiring myself – in the majority of these situations – to foreshadow these sorts of hard magical counters, it makes the challenge something the players can engage with and thinking strategically about. While I know I can do a better job with Magic Resistance (a trait common in 5e monsters and a whole other conversation), a few examples spring to mind...
(1) World-building is Foreshadowing
I was just asking for advice about how to run a scene where the PCs witness a NPC ruler get poisoned, and one person suggested that the ruler's throne room has a permanent
antimagic field in effect as a defensive measure which then works against them when healers try to cast
lesser restoration to heal the poisoning. That's a great example of world-building serving as foreshadowing which then becomes a hard magical counter.
(2) Foreshadowing for Multiple Functions
When I ran Tomb of Annihilation – in which Acererak has a huge magical dungeon in the jungle – I dropped multiple clues about diamond mines specifically being over-mined, extremely rare, and dwarves lamenting the long enslavement their fathers and mothers endured in the diamond mines. This helped foreshadow that Acererak had teleportation & divination countering enchantments on the dungeon... something my players were able to piece together. The scarcity of diamonds, and hence diamond dust (this was 5e where diamond dust is a material component for resurrection & greater restoration spells), also served to emphasize the deadliness of the night hag adversaries in the adventure – their maximum HP reducing Nightmare Haunting was usually curable with
greater restoration, but with the scarcity of diamonds that made the decision to expend some to cast the spell a challenging choice.
(3) Limiting Through Engaging
I've been writing up a flame mage dungeon built on an old oracular sacred site, for high-level play. There's essentially ambient magic from all the training of apprentice flame mages mingling with residual magic of these elemental flame oracles. This effect is also tied to a
forbiddance effect preventing an asuras NPC critical to the quest from entering the dungeon. This manifests as a "Counterspell Meter." Each time
counterspell is cast in the dungeon within a 24 hour period, the caster rolls a d6. If the result is equal to or less than the number of times
counterspell has been cast, then there is a fiery eruption at the midpoint between the countered spell and the caster of
counterspell, and a
living glitterfire manifests (a form of living spell) hostile to all creatures. Design-wise, this was as much to limit player abuse of
counterspell, as it was to curtail multiple enemy mages stopping all PC spellcasting through sheer weight of
counterspells. But it also engages the players in the story of this dungeon, because it can directly affect them depending on their chocies. Or at least, that's my intent! Will see how it runs in play!
2) Reactively (and secretly) changing loadouts or defenses to counter a spellcaster PC after you've discovered they've got an obstacle/encounter trivializing or obviating spell gambit they're about to deploy.
I haven't done this. I'm more of a "play it where it lies" mindset, and don't think it's worth it to neuter the players' enjoyment of these sorts of loopholes. As play progresses in the long-run, I believe part of the DM's role is to present bigger and better challenges to the players, and this requires stepping up to superior play – in other words, there will be a chance down the road to challenge whatever winning strategy they've landed on today.
But I do understand why a DM might overreact, especially with certain spells...
Leomund's tiny hut comes to mind because that spell in 5e has seen a dramatic power-up since even its powered-up appearance in 4e. The concept of the spell isn't flawed, but its execution in 5e is really bad.
I think the "this is play as intended" argument should always be open to questioning. Maybe what's intended isn't what's written. Maybe what's intended isn't right for your group.
3) Aggressively using the endless resources at your disposal to actively harangue spellcaster PCs in ways that you don't harangue martial PCs (eg creatures that can steal spells or spellcasters that steal spells but none that steal armor/swords, Rakshashas and the like but limited Rust Monsters, spellbook and component pouch stealing Imps/Pixies).
Nah, I'm an equal opportunity rat bastard DM. I did have a night hag focus her Nightmare Haunting on the wizard PC for a couple sessions, but that was because the wizard and the paladin killed her younger sister. Whereas her older sister was married to the paladin, and declared his soul off limits for herself (long story).
4) Fudge a Saving Throw Roll or a To-Hit Roll against the Spellcaster.
I used to fudge dice when I was younger, but I guess I grew out of it. Since then I've had a lot more bad guys get wiped out in a single round by my players. But you know what? It's also made me level up my strategic & tactical thinking when it comes to D&D, and I've also gotten a lot better at knowing how to tweak monster design – when it makes sense for that monster/NPC – to account for common tactics (e.g. stun-locking comes to mind).
Is it 1 x per session? Is it 2 x per session?
Is it 1/4 spellcaster deployments (that would otherwise trivialize or outright obviate an encounter)? Is it 2/4? Is it 3/4?
Which of the above 4 countermeasures do you use, why, and how much?
#1 (Preemptively using unestablished backstory or unilateral access to the offscreen) is my poison of choice. For me, it's much more of a dungeon-building or campaign-building decision, rather than a "per session" decision.