fix: respect Claude Max plan in remote sessions + legacy mobile compat#797
Open
DxTa wants to merge 4 commits intoslopus:mainfrom
Open
fix: respect Claude Max plan in remote sessions + legacy mobile compat#797DxTa wants to merge 4 commits intoslopus:mainfrom
DxTa wants to merge 4 commits intoslopus:mainfrom
Conversation
…#120) When the daemon spawns a session, it previously passed its full process.env to the child process. If the daemon's shell had ANTHROPIC_API_KEY set, Claude Code would use API key authentication instead of its native OAuth login (Max plan), causing unexpected billing. Now, auth-related env vars (ANTHROPIC_API_KEY, ANTHROPIC_AUTH_TOKEN, CLAUDE_CODE_OAUTH_TOKEN) are stripped from the inherited environment unless the selected profile explicitly sets them. This allows Claude Code to fall back to its native OAuth authentication for Max plan users. Includes comprehensive unit tests for env var stripping behavior.
Strip ANTHROPIC_API_KEY, ANTHROPIC_AUTH_TOKEN, and CLAUDE_CODE_OAUTH_TOKEN from inherited environment when spawning Claude in local mode, unless explicitly set by configuration. This prevents unintended authentication using credentials from the parent process, extending the security fix from the daemon path to local execution. Changes: - claudeLocal.ts: Add baseEnv filtering logic (lines 241-258) that strips auth vars unless explicitly provided in claudeEnvVars - claudeLocal.test.ts: Add 5 comprehensive test cases covering stripping behavior, explicit overrides, empty configs, and audit logging All 15 tests pass (10 existing + 5 new). Follows secure-by-default principle and matches implementation pattern from daemon fix (commit a5d18fc). Related to issue slopus#120: prevent credential inheritance in Claude spawning
… env stripping util Mobile clients on Play Store (v5, 2025-12-22) predate the session-protocol migration (commit 54d0031, 2026-02-13) and cannot parse the modern `role:'session'` wire format. This caused Claude assistant responses (e.g. 'pong') to be silently dropped. ## Mobile compatibility (happy-cli + happy-app) - CLI emits a legacy `output` mirror for every Claude assistant message: - `role: 'agent'`, `content.type: 'output'`, `legacyCompat: true` - UUID is preserved from original body or synthesised via randomUUID() if absent, since pre-migration parsers drop assistant output without a uuid. - Session-protocol agent envelopes also dual-send a legacy-wrapped copy (`role: 'agent'`, `content.type: 'session'`) alongside the modern envelope. - Mobile parser (`typesRaw.ts`) drops records tagged `legacyCompat: true` to prevent duplicate rendering on newer builds. - Removed dead `rawAgentContentInputSchema`/`RawAgentContentInput` type. - Collapsed duplicate codex and ACP `message|reasoning` branches. - Test coverage: 25/25 CLI tests, 62/62 mobile parser tests pass. ## Auth env stripping refactor (happy-cli) - Extracted `buildEnvWithStrippedAuthVars` and `deleteAuthVarsFromProcessEnv` into `src/utils/stripAuthEnvVars.ts` (with tests in `claudeRemote.test.ts`). - Replaced inline stripping loops in claudeLocal, claudeRemote, and daemon run with the shared utility, eliminating code duplication. - Changed `shx` devDependency to caret range.
…without body Synthetic error assistant messages from the Claude SDK may have body.message == null (isApiErrorMessage: true path). Only emit the legacy compat mirror when message is present to avoid sending malformed output records to older mobile clients.
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
Addresses #120 — users running sessions from browser/mobile were silently falling back to API key billing instead of honoring Claude Max plan.
Closes #120.
🤖 Generated with Claude Code