Pin a stable Plex client identity to stop New Device notifications (#190)#192
Merged
Brandon-Haney merged 1 commit intoJun 27, 2026
Conversation
Reuse the persisted plexcache_client_id as the X-Plex-Client-Identifier for all runtime Plex connections (CLI and web), tagged as the PlexCache-D product and device name at the app version. Without this, plexapi derives the identifier from the container MAC/hostname, so Plex registers PlexCache as a new device whenever that value changes (container recreation) or after the headless device is aged out, firing a New Device notification (issue StudioNirin#190). ensure_plex_client_identity() creates and persists the id once for installs configured by manual token rather than OAuth, leaving an existing or unparseable settings file untouched otherwise.
StudioNirin
approved these changes
Jun 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #190. Plex was firing "New Device" security notifications attributed to PlexCache, often in the middle of the night, because PlexCache connected with the plexapi default
X-Plex-Client-Identifier. That default is derived from the container's MAC/hostname (hex(uuid.getnode())), so Plex sees an unrecognized device whenever the container is recreated or after Plex ages the headless client out, and re-registers it.This pins a stable identity for every Plex connection by reusing the
plexcache_client_idthat's already persisted for the OAuth login. The device now also reports as thePlexCache-Dproduct/device name at the app version, instead of "PlexAPI" at the plexapi library version.What changed
core/plex_api.py—apply_plex_client_identity()sets the plexapi header globals and rebuildsBASE_HEADERSin place (so modules that imported it by name pick up the change).ensure_plex_client_identity()loads, or creates and persists, the id from settings and applies it. It leaves a missing (pre-setup) or unparseable settings file untouched rather than writing a stub.core/app.py— applies the identity right after config load, before any Plex connection, and keeps the in-memory config in sync so a later settings save can't drop the id.web/main.py— applies the identity in the web lifespan before the startup Plex prefetch.tests/test_plex_client_identity.py— covers header mutation, in-placeBASE_HEADERSupdate, reuse of an existing id, create-and-persist, and the missing/unparseable-file guards.Installs configured by OAuth already have
plexcache_client_id; installs configured by manual token get one minted and saved once on first run.How to test
68fdc57b2575) and thePlexAPIproduct.--verboseyou'll see a debug line:Plex client identity set: id=… product=PlexCache-D version=….PlexCache-Dat the PlexCache version.Confirmed working in the field by the reporter on #190 (no further notifications after switching to the build with this fix).