Add opt-in local server for a companion mobile app#246
Open
mahdi-salmanzade wants to merge 1 commit into
Open
Conversation
Adds LocalServerService: an opt-in, read-only HTTP server exposing the current usage snapshot to trusted devices on the local network (e.g. a companion mobile app). Disabled by default; every request requires a Bearer token; the Claude session key never leaves the machine. - LocalServerService.swift: NWListener HTTP server, GET /v1/usage + /v1/ping, token auth, serves DataStore.loadUsage() as JSON; LAN address helper. - SharedDataStore: enabled/port/token persistence + token generation. - AppDelegate: start on launch if enabled, stop on terminate. - MobileAppView: real pairing screen (enable toggle + QR code + token) replacing the previous coming-soon placeholder.
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.
What
Adds an opt-in, read-only local HTTP server so a companion mobile app can display your current usage over the local network. This implements the "Mobile App" settings tab, replacing the previous coming-soon placeholder with a real pairing screen.
A matching open-source Expo app lives here: https://github.com/mahdi-salmanzade/claude-usage-mobile
How it works
The server simply serves the already-computed
DataStore.shared.loadUsage()snapshot as JSON. The phone never authenticates to Claude — the session key never leaves the Mac.Security model
Authorization: Bearer <token>; the token is generated locally and only shared via the pairing QR code. Regenerating it un-pairs existing devices.GET /v1/usage) plusGET /v1/ping; unknown paths → 404, bad/missing token → 401.Changes
LocalServerService.swift(new) —NWListener-based HTTP server; token auth; ISO-8601 JSON envelope aroundClaudeUsage; primary-LAN-address helper.SharedDataStore.swift— persistence for enabled/port and secure token generation.AppDelegate.swift— start on launch if enabled, stop on terminate.MobileAppView.swift— real pairing screen (enable toggle, QR code with{host,port,token}, copy/regenerate token, security note).Testing
curl: 401 on missing/bad token, 404 on unknown path, and a correctClaudeUsageJSON envelope on a valid request.Notes / follow-ups
MobileAppViewstrings are currently English literals — happy to wire them into the localization system if you'd like before merging.