Using Claude Code on a server A hands-on walkthrough by Flavio demonstrates running Anthropic's Claude Code directly on a remote Linux server — a disposable Sprites VM from Fly.io — to build a digital pet web app with a public URL, rather than running the coding agent on a local Mac and deploying afterward. The walkthrough covers creating the project folder, authenticating Claude Code via a subscription login that opened in the Mac's browser, and prompting the agent to build the app in Bun and TypeScript, with the pet gaining 10 hunger points per minute and moods shown by emoji. It also compares local, disposable Sprite VM and always-on VPS setups, noting that Sprites auto-pause when idle and need `sprite-env services` plus disk storage to keep state across restarts. Using Claude Code on a server By Flavio https://flaviocopes.com/about/ Tagged: AI https://flaviocopes.com/tags/ai/ Run Claude Code directly on a remote Linux server instead of your laptop. A hands-on walkthrough building a digital pet web app on a Sprites VM, with a public URL anyone can visit. I usually run coding agents on my Mac, then deploy the finished app to a server. In this walkthrough, we’ll flip that around and run Claude Code directly on a remote Linux machine to build a small digital pet. The pet gets hungrier over time, and anyone with its public URL can visit the page and feed it. We’ll check that two browsers see the same pet, make sure it survives a restart, and delete the test machine once we’re done. Because the app lives on a remote machine, visitors can keep feeding the pet while your laptop is asleep, as long as the remote app is running. Sprites can pause when idle, so we’ll also look at what happens when the process stops and how to keep the state intact. Why a server A server is just a computer waiting to answer requests. Putting the app on a remote host lets people reach it without relying on your laptop. Your local machine can run a web server too, though it comes with a few catches: - by default, it may only be reachable on localhost - a process tied to a terminal window can stop when you close that window - everything disappears the moment your laptop sleeps A remote host gives our pet its own URL. Once you make that URL public, anyone can visit whenever the app is available. Sprites manages idle time differently from an always-running VPS, so here is how the three setups compare: | Setup | Reachable from another device | When your laptop sleeps | Idle behavior | Process recovery | |---|---|---|---|---| | Local Mac | Only on localhost by default | Stops | Stays awake while Mac is awake | Manual restart if terminal closes | | Disposable Sprite VM | Built-in .sprites.app URL private by default, toggleable to public | Keeps running until idle | Auto-pauses when idle; HTTP requests wake it | Needs sprite-env services and disk storage | | Always-on VPS | Public IP or your own domain | Keeps running | Runs continuously | Needs a service manager like systemd | For this experiment, we’ll use Sprites https://fly.io/sprites/ as our server. You could follow along on any VPS, but a Sprite is disposable, boots in seconds, and ships with AI coding agents preinstalled. If you haven’t set up Sprites yet, install the CLI curl -fsSL https://sprites.dev/install.sh | sh , sign in with sprite login , and spin up a machine with sprite create test . The Sprites docs https://docs.sprites.dev/ have the full setup details. Claude Code comes preinstalled on a fresh Sprite. I’d still check claude --version and update it if needed, since the base image can change. Codex is installed too, so you can use that instead if you have an OpenAI subscription. Create the project folder Connect to your Sprite I named mine test and create a folder for the project: mkdir pet && cd pet Run Claude Code Now start Claude Code inside that folder: claude Pick a theme, then authenticate your account. I chose the subscription route here: During my session, the authorization page opened right in my Mac’s browser. Completing that sign-in authenticated Claude Code on the remote Sprite: In the screenshot below, I turned on “bypass permissions” mode. Only do that with disposable data and narrowly scoped access. Even inside a sandbox, an agent can still affect any external services you authorize, and turning on a public URL exposes whatever the app serves: Create the app Now you can write a prompt and build whatever you like. Here is the prompt I used: Create a digital pet web server using Bun and TypeScript. The pet should: - Have a name Pixel , hunger level 0-100 , and track when it was last fed - Get hungrier over time 10 hunger points per minute - Show different emoji moods based on hunger: happy <20 , okay <50 , hungry <80 , starving =80 - Have a simple dark-themed web UI showing the pet, hunger bar, and a feed button - GET / shows the pet, POST /feed feeds it and redirects back Save it as pet.ts, then run it and tell me how to access it. After a short wait, Claude Code finishes writing the code and starts the server: Here is the summary of what it built: Features: - Pixel starts happy with 0 hunger - Hunger increases by 10 points per minute automatically - Click "Feed Pixel" to reduce hunger by 30 points - The mood emoji and bar color change based on hunger level: - Green/happy at <20 - Yellow/okay at <50 - Orange/hungry at <80 - Red/starving at =80 Notice that it tells me the app is running at localhost:3000 . Here, localhost refers to the Sprite itself, not my laptop. Opening that address in my local browser would look for a server on my Mac instead, so we need the Sprite’s public-facing URL. Open it from the internet Back on your local computer, grab the Sprite’s URL: sprite info -s test If you open that URL in your browser right away, you’ll hit an error: One quick note on the screenshots: they show the older sprite url command. The current CLI uses sprite info and sprite config update , as shown in the code blocks above and below. Your browser request reaches Sprites, but access is private by default. Because this is an access error from Sprites itself, editing the pet’s code won’t fix it. Make this demo URL public: sprite config update -s test --url-auth public Reload the page, and Pixel shows up: If the page still doesn’t load for you, check that your server listens on port 8080 . That is the default port a Sprite URL forwards traffic to. Go ahead and feed Pixel: If you come back after a while, you’ll see Pixel getting hungry again: Testing across devices and sleep behavior Try opening the same URL on your phone while keeping it open on your computer. When you feed Pixel on one device and reload the other, both should show the updated hunger level because they talk to the same server process. Seeing a separate pet on each device would be a bug in this setup. You can even close your laptop lid and keep using the app on your phone. The active process on the Sprite keeps running on its own. What happens when nobody visits for a while? Sprites can pause when idle. A warm pause freezes running processes in place, while a cold wake boots back up without those processes. An incoming HTTP request will wake the Sprite, but a server you started manually in the terminal may need to be started again. To handle restarts automatically, we can use the built-in sprite-env services manager we’ll set that up in a moment . You also need to save the pet’s state to disk so it survives a restart. A regular VPS has the same requirement and still needs a service manager to recover after a crash or reboot. If you plan to keep this app running, test a restart on its own: feed Pixel, restart the process, and reload the page. If the hunger level resets back to zero, the app isn’t restoring its state from disk. A public URL alone does not give you persistence. Keep the same pet after a restart The original prompt leaves storage up to the agent, so it might only keep Pixel’s state in memory. Here is a complete version you can compare against what the agent wrote, saved as pet.ts inside /home/sprite/pet . Instead of relying on an in-memory timer, this version saves Pixel’s hunger and last update timestamp in SQLite and calculates elapsed time on every request. That also solves the sleeping Sprite problem, since an interval running in memory stops ticking while the machine is asleep: js import { Database } from 'bun:sqlite' const db = new Database 'pet.sqlite', { create: true } db.exec CREATE TABLE IF NOT EXISTS pet id INTEGER PRIMARY KEY CHECK id = 1 , hunger REAL NOT NULL, updated INTEGER NOT NULL db.query 'INSERT OR IGNORE INTO pet VALUES 1, 0, ? ' .run Date.now const read = db.query<{ hunger: number; updated: number }, 'SELECT hunger, updated FROM pet WHERE id = 1' const hungerNow = row: { hunger: number; updated: number } = Math.min 100, Math.max 0, row.hunger + Date.now - row.updated / 6000 const feed = db.transaction = { const hunger = Math.max 0, hungerNow read.get - 30 db.query 'UPDATE pet SET hunger = ?, updated = ? WHERE id = 1' .run hunger, Date.now } Bun.serve { hostname: '0.0.0.0', port: Number process.env.PORT ?? 8080 , fetch request { const url = new URL request.url if url.pathname === '/feed' && request.method === 'POST' { feed return new Response null, { status: 303, headers: { Location: '/' } } } if url.pathname == '/' return new Response 'Not found', { status: 404 } if request.method == 'GET' return new Response 'Method not allowed', { status: 405 } const hunger = Math.floor hungerNow read.get const mood = hunger < 20 ? 'happy' : hunger < 50 ? 'okay' : hunger < 80 ? 'hungry' : 'starving' const emoji = hunger < 20 ? '😄' : hunger < 50 ? '🙂' : hunger < 80 ? '😟' : '😫' return new Response < doctype html