Putting Claude in a desktop app without exposing the API key
How innerpulse music runs the Anthropic SDK inside a desktop app while keeping the API key in the system keychain and out of the web page.
Many desktop apps today are web apps in a native window. That makes it easy to use the official Anthropic SDK, which is written for JavaScript, but it raises an awkward question: where does the API key go? Anything the page can read, a bug or a malicious script in the page can read too. innerpulse music, a songwriting app built with Tauri, answers that by never letting the page see the key at all.
Two halves with different jobs
Tauri apps have two parts. The interface is a web page, in this case a static Next.js build, running in the system webview. Behind it is a small Rust program with access to the operating system. The page can only reach the Rust side through commands the app explicitly defines.
The Anthropic SDK runs in the page as usual, but it is given a custom fetch function. Instead of going to the network, every request goes to one Rust command, which makes the real call to the API. The SDK does not know the difference, so streaming, tool use and retries all work as normal.
A narrow door in Rust
The Rust command is deliberately strict. It only forwards requests whose path starts with /v1/, and it rejects any path containing “..” or “@”, so a request cannot be steered to another endpoint or another host. It removes headers the page should not control, including any API key or authorization header, cookies, the host, origin and referer headers, and the browser’s own sec- headers. Then it adds the real key and sends the request to api.anthropic.com, and nowhere else.
Responses stream back to the page in pieces over a Tauri channel: first the status and headers, then each chunk of the body, then an end or error event. The SDK reassembles them into the same stream it would get from a normal network call, so text appears as the model writes it.
Keeping the key in the keychain
The key itself is stored in the operating system’s credential store: the Keychain on macOS, Credential Manager on Windows and the Secret Service on Linux. Those stores are designed for exactly this, and they keep the key out of the app’s config files and backups.
Some Linux desktops have no credential store running. In that case the app falls back to an encrypted file in its config folder, sealed with AES-256-GCM and a fresh random nonce, with the encryption key in a separate file readable only by the user. The app is honest about what that protects against: it stops the key showing up in a casual look through files or in a backup, but it does not stop someone who is already signed in as the same user. An environment variable works as a last resort for developers.
When the page asks about the key, it only ever gets a status and the last four characters, enough to tell which key is set. New keys are checked for the expected prefix before they are saved.
Closing the other doors
Hiding the key only helps if the page cannot reach the internet some other way. The webview’s Content Security Policy limits network connections to the app itself and Tauri’s own IPC channel. Even if something unexpected ran inside the page, it could not send data to an outside server directly.
Letting the model edit, carefully
The same caution applies to what Claude can change. The model does not rewrite the song file directly. It calls defined tools, such as one to update the song and one to write notes, and each change is applied to a copy, checked, and only then accepted. A malformed edit is rejected rather than saved. innerpulse desktop, a Windows AI client in the same portfolio, takes a similar line with tools: every tool call asks first.
A checklist for AI in desktop apps
- Keep the API key on the native side, never in the web page.
- Forward requests through one narrow command that allows only the API host and paths you expect.
- Strip credentials and browser headers from anything the page sends.
- Store keys in the operating system’s credential store, and be clear about what any fallback protects.
- Lock down the page’s network access with a Content Security Policy.
- Let the model act through tools that are checked before their results are kept.
The pattern fits any desktop app that calls a paid or sensitive API, not only AI ones.
