Native client API contract (binding for backend and Swift workstreams)
Additive extension of the Claude Remote / Codex Remote server (apps/server, base /api/v1). Nothing
existing changes for browsers: cookie sessions, CSRF and Origin rules stay exactly as they are.
Team ID 3YM54G49SN. Bundle ids: ai.spboucher.clauderemote (Claude instance), ai.spboucher.codexremote
(Codex instance); the same id is used by the macOS and the iOS app; Debug builds use the suffix .dev.
1. Apple App Site Association
GET /.well-known/apple-app-site-association — public, Content-Type: application/json, no redirect, 200:
{"webcredentials":{"apps":["3YM54G49SN.<bundle>","3YM54G49SN.<bundle>.dev"]},
"applinks":{"details":[{"appIDs":[same list],"components":[{"/":"/open/*"}]}]}}
App ids come from CR_APPLE_APP_IDS (comma list); default derived from the agent profile as above.
Must be deployed to production BEFORE any signed app is first launched (Apple's CDN caches misses).
2. Native sessions (bearer, device-bound)
A native session is a row of auth_sessions with client_kind = 'native' (browser rows: 'browser').
- Credential:
Authorization: Bearer crn_<43 base64url chars>; only the SHA-256 is stored. - A bearer token is accepted ONLY for
client_kind='native'rows; the cookie ONLY for'browser'rows. - Bearer requests need no CSRF token and no Origin (no ambient credential). If an
Originheader is present on a bearer request it must equal the public origin, else 403bad_origin. - Every native request carries
X-CR-Client: native/<macos|ios|ipados>/<appVersion>; native preauth POSTs require it plusContent-Type: application/json(403bad_clientotherwise). - WebSocket upgrades (
/sessions/:id/stream,/tasks/:id/log/stream,/events) accept the same bearer header. - Access token lifetime
CR_NATIVE_TOKEN_TTL_SEC(default 3600). An expired token answers 401token_expired(distinct from 401unauthenticated= session revoked/expired/unknown). Open WebSockets are tied to the session row, not the token: they survive a rotation and are closed with 4401 on revocation/expiry. - Session lifetime: absolute 30 d (as browsers); idle
CR_NATIVE_IDLE_SEC(default 14 d), justified by the device-bound key. Second factor pending: 15 min. - All existing routes (
/auth/status,/auth/logout,/auth/devices, projects, sessions, …) work unchanged with a bearer session at the same authorisation levels.
Shared object:
NativeSession = { id: uuid, token: string, tokenExpiresAt: iso, expiresAt: iso, secondFactor: boolean }
NativeDevice = { installId: uuid, name: string(1..80), platform: 'macos'|'ios'|'ipados',
model: string(≤80), appVersion: string(≤40),
publicKey: base64 (P-256 public key, X9.63 uncompressed 65 bytes) }
Endpoints (/api/v1/native/auth/…), same throttling and audit as the web equivalents
| Route | Auth | Body → Response |
|---|---|---|
POST login |
preauth | {username, password, totp?, device: NativeDevice} → `{next: 'done' |
POST totp |
restricted bearer | {code} → {next:'done', session} (token rotated) |
POST passkey/options |
restricted bearer, or none | with a bearer: request options with allowCredentials (second step). Without: {device: NativeDevice} not needed here → options for discoverable credentials plus challengeToken (opaque, 5 min, single use) : response `{options: PublicKeyCredentialRequestOptionsJSON, challengeToken: string |
POST passkey/verify |
restricted bearer, or none | {credential: AuthenticationResponseJSON, challengeToken?: string, device?: NativeDevice} → {next:'done', session}. Without a bearer, challengeToken and device are required and a new full native session is issued (passkey with user verification on its own — same rule as the web). |
POST refresh/challenge |
none (token may be expired) | {sessionId} → {challenge: base64url, expiresAt} (60 s, single use; 404-free: unknown session answers a decoy challenge) |
POST refresh |
none | {sessionId, signature} → {session}; signature = base64 DER ECDSA-P256-SHA256 over the UTF-8 bytes of cr-native-refresh:v1:<sessionId>:<challenge>, verified against the session's device public key. Rotates the token (old one dies at once). Only for full, live sessions; failure 401 unauthenticated and counted by the throttle. |
WebAuthn verification is unchanged: RP ID = host of CR_PUBLIC_ORIGIN, expected origin = CR_PUBLIC_ORIGIN
(Apple platform authenticators put https://<rpId> in clientDataJSON for associated apps), UV required.
Passkey registration from a native app uses the existing /auth/passkey/register/options|verify with a bearer.
Devices
GET /auth/devices gains entries kind: 'native' (label = device name) with additive optional fields
platform, model, appVersion, pushEnabled. DELETE /auth/devices/:id revokes it (WebSockets closed 4401,
push token dropped). Device.kind becomes 'passkey'|'session'|'native'.
3. Push
PUT /native/push(full bearer){apnsToken: hex, environment: 'sandbox'|'production', topic: string}→{ok:true, configured: boolean}(topicmust be one of the instance's app ids without the team prefix).DELETE /native/push.- Server sends through APNs HTTP/2 with a provider token (ES256) when
CR_APNS_KEY_FILE,CR_APNS_KEY_ID,CR_APNS_TEAM_IDare set; otherwise push is reportedconfigured:falseand nothing is sent. - Every
Notifier.notifyalso fans out to the user's native devices. Payload:{"aps":{"alert":{"title":<generic title>,"body":<body or omitted>},"sound":"default","thread-id":<kind>,"interruption-level":"time-sensitive" only for session.waiting},"cr":{"kind","link","notificationId"}}. Never terminal content;bodyonly when the user'snotifications.detail = 'titles'. A 410/BadDeviceToken/Unregisteredanswer deletes the token. UserSettings.notificationsgainspush: boolean(default true).
4. Summary (widgets, menu bar, Home)
GET /native/summary (full) →
{ serverTime: iso, agent: 'claude'|'codex', productName: string,
sessions: { live: number, waiting: number, running: number, detached: number, recoverable: number },
tasks: { running: number, queued: number, failed24h: number, succeeded24h: number },
cluster: { nodes: number, online: number, health: Health, collectedAt: iso|null } | null,
notificationsUnread: number }
5. Deep links
Notification link values are web paths (e.g. /terminal/?s=<id>, /tasks/?t=<id>); native apps map them
to their own navigation. Custom URL schemes: clauderemote:// and codexremote:// with the same path + query.