Skip to content

fix: respect Claude Max plan in remote sessions + legacy mobile compat#797

Open
DxTa wants to merge 4 commits intoslopus:mainfrom
DxTa:fix/mobile-legacy-compat-and-auth-stripping
Open

fix: respect Claude Max plan in remote sessions + legacy mobile compat#797
DxTa wants to merge 4 commits intoslopus:mainfrom
DxTa:fix/mobile-legacy-compat-and-auth-stripping

Conversation

@DxTa
Copy link

@DxTa DxTa commented Mar 2, 2026

Summary

Addresses #120 — users running sessions from browser/mobile were silently falling back to API key billing instead of honoring Claude Max plan.

  • Strip inherited Anthropic auth env vars before launching remote Claude sessions so the Max plan is respected (not the ambient API key).
  • Add legacy output compatibility for older mobile clients.
  • Guard the output mirror against synthetic assistant messages that have no body to prevent crashes.

Closes #120.

🤖 Generated with Claude Code

DxTa added 4 commits February 28, 2026 18:01
…#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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Claude code max plan ignored - happy insists on using Claude with an API key

1 participant