# Use your own Claude subscription

Sign in to Claude Code with your own Claude subscription inside a miniVM, and what it implies.

The supported way to give a miniVM access to Claude is an API key: `ons auth add-key anthropic`
stores it with onshore.sh, and it is added to the miniVM's requests on their way out. The key
itself never enters the miniVM.

```bash
ons auth add-key anthropic
```

`ons` reads the key at a hidden prompt, from piped stdin, or with `--from-file <path>`. See
[Agent runs](https://onshore.sh/docs/guides/agent-runs#ai-accounts).

The managed onshore.sh service does not offer Claude.ai sign-in, and has no feature that reads, keeps or relays your
Claude subscription credentials. As we read
[Anthropic's terms for Claude Code](https://code.claude.com/docs/en/legal-and-compliance), a
platform may not do that for its users, but you may sign in to the unmodified Claude Code with
your own subscription where a platform hosts it. That is your own use of Claude Code, under your
account and your responsibility. This page explains how, and what it implies.

## Before you start

- **No Anthropic account bound to the miniVM.** When an Anthropic account is bound, onshore.sh's
  egress replaces the credential of every request to `api.anthropic.com`, so the bound account is
  used whatever you signed in with. If your organization has a default Anthropic account, create
  the miniVM without any AI account:

  ```bash
  ons create --agents --template agents --metadata msb.ai_account=none
  ```

  Nothing is bound, and `ons inspect <minivm-id>` shows
  `AI accounts: no AI account bound (msb.ai_account=none)`. `<minivm-id>` is the id `ons create`
  printed. For a run in one command, use `ons agent new --no-ai-account` instead. Do not pass
  egress credentials for `api.anthropic.com` either.
- **The miniVM can reach Anthropic.** Sign-in and model requests go straight from the miniVM to
  Anthropic over TLS, without onshore.sh's credential proxy in the middle. Claude Code needs
  these hosts in the template's egress allow list:

  - `api.anthropic.com` (model requests, account details)
  - `platform.claude.com` (token exchange and refresh)
  - `claude.ai` (sign-in)

  The `llm-apis` egress preset holds all three, and the `dev-agents` template, and the `agents`
  template built from it, use it. A template of your own must name the preset or list the three
  hosts. See [Egress](https://onshore.sh/docs/guides/egress).

## What it implies

- **Your credential sits on the miniVM's disk and in its memory** until the miniVM is killed. Any
  program running in the miniVM can read it and use it against Anthropic.
- **It is in the miniVM's pause snapshots.** Pausing saves the miniVM's memory and disk. A pause
  is kept by onshore.sh until the miniVM is killed or its paused retention ends. No onshore.sh feature looks inside it.
- **What you type and see in `ons shell` crosses onshore.sh's edge**, where TLS ends before the
  traffic goes to the miniVM's host (on a [Hybrid](https://onshore.sh/docs/guides/hybrid) pool, TLS ends on your own
  runner). It is not logged or stored, but it is not end-to-end encrypted to the miniVM. That is
  why this page never asks you to paste a long-lived token into a shell.
- **Never sign in inside a miniVM that runs code you do not trust** (third-party repositories,
  agent-generated scripts you have not read, untrusted dependencies).
- Sign in per miniVM, run `claude auth logout` in it when you are done, then kill the miniVM.

## Sign in inside the miniVM

1. **Open a shell**

   ```bash
   ons shell <minivm-id>
   ```

   `<minivm-id>` is the id of your miniVM (`ons ls` lists them).

2. **Sign in**

   ```bash
   claude auth login
   ```

   No browser opens in a miniVM: copy the sign-in URL, open it on your computer, and paste the
   code it shows back where Claude Code asks for it. That one-time code crosses the edge; the
   tokens it is exchanged for go from Anthropic straight to the miniVM and never cross the edge.

3. **Check**

   ```bash
   claude auth status
   ```

Agent runs started in this miniVM now use your subscription.

When you are done:

```bash
claude auth logout
```

Run it in the miniVM's shell, then kill the miniVM with `ons kill <minivm-id>`.

> **Warning:** Do not copy a long-lived token (`claude setup-token`, `CLAUDE_CODE_OAUTH_TOKEN`) into miniVMs:
> it would have to cross the edge, and every miniVM you copy it into holds it. Never pass any
> Claude credential with `--env`, metadata, `ons push` or in a template: those go through
> onshore.sh, and a template copies it into every miniVM built from it.

## What we cannot do

We cannot obtain, refresh, revoke or troubleshoot your Claude sign-in. If it expires, sign in
again inside the miniVM.

On the managed service, `ons auth add claude` (and `ons auth add chatgpt`) answers `403 SUBSCRIPTIONS_DISABLED`, and `ons auth add claude` points to this page.

Anthropic may change its terms at any time. API keys are the supported path.

Markdown version: https://onshore.sh/docs/guides/claude-code.md
