I got Claude Code to also try to detect when the screen is being observed—it found a private macOS framework called SkyLight that has a function, `SLSIsScreenWatcherPresent`, that returns a boolean if any other process is observing the screen. It reckons that it's the same thing that Apple uses for the purple "screen is being observed" indicator. There’s a slight delay, but the masking triggers when I start screen recording (the very beginning of the recording needs trimming because of the delay).
You can also option-click the item to manually mask it.