Seamlessly switch Claude Code control between desktop and mobile devices
Happy’s device switching feature lets you transition control of your Claude Code sessions between your computer and mobile device with a single keypress. Start coding on your desktop, then take control from your phone, or switch back whenever you need.
Device switching is built into Happy’s core architecture. The CLI runs a control loop that alternates between local mode (desktop) and remote mode (mobile) based on input signals.
// Conceptual flow of local launcherexport async function claudeLocalLauncher(session: Session) { // Spawn Claude process with PTY const claudeProcess = spawn('claude', args, { cwd: session.path, env: session.claudeEnvVars, // PTY for interactive terminal }); // Watch for output and sync to server claudeProcess.on('data', (data) => { // Send output to server for mobile viewing session.client.sendUpdate(data); }); // Listen for mode switch request session.client.on('switch-mode', () => { // Clean shutdown of local process claudeProcess.kill(); return { type: 'switch' }; }); // Wait for completion or switch await claudeProcess.wait(); return { type: 'exit', code: 0 };}
// Conceptual flow of remote launcherexport async function claudeRemoteLauncher(session: Session) { // Use Claude SDK instead of spawning process const claudeSdk = new ClaudeSDK({ apiKey: process.env.ANTHROPIC_API_KEY, model: session.model, // ... other config }); // Process messages from mobile app for await (const message of session.queue) { const response = await claudeSdk.sendMessage(message); // Stream response back to mobile for await (const chunk of response) { session.client.sendUpdate(chunk); } } // Listen for mode switch (keyboard input) if (detectKeyPress()) { return 'switch'; } return 'exit';}
The session maintains a heartbeat to inform the server of current state:
// Keep-alive sent every 2 secondssetInterval(() => { session.client.keepAlive( thinking, // Is Claude currently processing? mode // 'local' or 'remote' );}, 2000);
This allows the mobile app to display real-time status: