Use Claude Code with your ChatGPT, Kimi, Cursor or Grok subscription via a local Anthropic-compatible proxy
Rust
add windows support
Raine Virta08f9e75b7217
diff --git a/.github/workflows/release.yml b/.github/workflows/release.ymlindex f095b9c..fd49d10 100644--- a/.github/workflows/release.yml+++ b/.github/workflows/release.yml@@ -19,12 +19,22 @@ jobs:include:- target: bun-darwin-arm64platform: darwin-arm64+ ext: ""- target: bun-darwin-x64platform: darwin-amd64+ ext: ""- target: bun-linux-x64platform: linux-amd64+ ext: ""- target: bun-linux-arm64platform: linux-arm64+ ext: ""+ - target: bun-windows-x64+ platform: windows-amd64+ ext: .exe+ - target: bun-windows-arm64+ platform: windows-arm64+ ext: .exesteps:- uses: actions/checkout@v5- uses: oven-sh/setup-bun@v2@@ -41,11 +51,11 @@ jobs:--compile \--target=${{ matrix.target }} \--define BUILD_VERSION="\"${VERSION#v}\"" \- --outfile dist/${BIN_NAME}+ --outfile dist/${BIN_NAME}${{ matrix.ext }}- name: Packagerun: |archive="${BIN_NAME}-${{ matrix.platform }}.tar.gz"- tar -C dist -czf "$archive" ${BIN_NAME}+ tar -C dist -czf "$archive" ${BIN_NAME}${{ matrix.ext }}shasum -a 256 "$archive" > "${BIN_NAME}-${{ matrix.platform }}.sha256"- uses: actions/upload-artifact@v5with:@@ -54,8 +64,20 @@ jobs:${{ env.BIN_NAME }}-${{ matrix.platform }}.tar.gz${{ env.BIN_NAME }}-${{ matrix.platform }}.sha256- release:+ smoke-windows:needs: build+ runs-on: windows-latest+ steps:+ - uses: actions/download-artifact@v5+ with:+ name: windows-amd64+ - shell: pwsh+ run: |+ tar -xzf claude-code-proxy-windows-amd64.tar.gz+ .\claude-code-proxy.exe --version++ release:+ needs: [build, smoke-windows]runs-on: ubuntu-latestpermissions:contents: writediff --git a/README.md b/README.mdindex 7f8ca02..9cb8c1e 100644--- a/README.md+++ b/README.md@@ -38,7 +38,10 @@ curl -fsSL https://raw.githubusercontent.com/raine/claude-code-proxy/main/script```**Manual:** download a prebuilt binary for your platform from the-[releases page](https://github.com/raine/claude-code-proxy/releases).+[releases page](https://github.com/raine/claude-code-proxy/releases). Windows+artifacts are published as `claude-code-proxy-windows-amd64.tar.gz` and+`claude-code-proxy-windows-arm64.tar.gz`; extract the `.exe` somewhere on your+`PATH`.### 2. Pick a provider and authenticate@@ -64,8 +67,10 @@ claude-code-proxy kimi auth login # device-code flow (prints URL + code)Sign in with your **kimi.com account**. The verification URL is displayed; openit in any browser, confirm the code, and the CLI polls until done.-On macOS credentials go to Keychain; on other platforms they are written to-`~/.config/claude-code-proxy/<provider>/auth.json` (mode 0600).+On macOS credentials go to Keychain. On Windows they are written under+`%APPDATA%\claude-code-proxy\<provider>\auth.json`; on Linux they are written+under `${XDG_CONFIG_HOME:-$HOME/.config}/claude-code-proxy/<provider>/auth.json`+(mode 0600 where supported).Verify:@@ -308,9 +313,9 @@ sequenceDiagram### `serve`-Starts the HTTP proxy and blocks. Binds to `127.0.0.1` only. Logs to-`$XDG_STATE_HOME/claude-code-proxy/proxy.log` (rotated at 20 MiB). Set-`CCP_LOG_STDERR=1` to mirror log lines to stderr while running.+Starts the HTTP proxy and blocks. Binds to `127.0.0.1` only. Logs to the+platform state directory (rotated at 20 MiB). Set `CCP_LOG_STDERR=1` to mirror+log lines to stderr while running.```shclaude-code-proxy serve@@ -406,9 +411,9 @@ Sign in with your **kimi.com account**. The access token has a ~15 minutelifetime; the proxy refreshes it 5 minutes before expiry with a single-flightguard and persists the rotated refresh token.-A persistent device ID is generated on first login at-`~/.config/claude-code-proxy/kimi/device_id` and reused forever — it's bound-into the issued JWT, so rotating it would invalidate your token.+A persistent device ID is generated on first login next to the Kimi auth file+and reused forever — it's bound into the issued JWT, so rotating it would+invalidate your token.#### `kimi auth status`@@ -446,9 +451,10 @@ Settings can come from either environment variables or a `config.json` file.Precedence per setting: **env var > config file > built-in default**. Theconfig file is optional — env-var-only setups continue to work unchanged.-The file lives at `~/.config/claude-code-proxy/config.json` on macOS (the same-directory the auth tokens use, deliberately not `~/Library`) and at-`${XDG_CONFIG_HOME:-$HOME/.config}/claude-code-proxy/config.json` elsewhere.+The file lives at `~/.config/claude-code-proxy/config.json` on macOS+(deliberately not `~/Library`), at `%APPDATA%\claude-code-proxy\config.json` on+Windows, and at+`${XDG_CONFIG_HOME:-$HOME/.config}/claude-code-proxy/config.json` on Linux.```json{@@ -477,7 +483,7 @@ directory the auth tokens use, deliberately not `~/Library`) and at| Variable | Config key | Default | Purpose || ------------------------ | ------------------- | ------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- || `PORT` | `port` | `18765` | Proxy listen port |-| `XDG_STATE_HOME` | — | `~/.local/state` | Base dir for `proxy.log` |+| `XDG_STATE_HOME` | — | `~/.local/state` | Linux/macOS base dir for `proxy.log` || `CCP_LOG_STDERR` | `log.stderr` | unset | Also mirror log lines to stderr || `CCP_LOG_VERBOSE` | `log.verbose` | unset | Log full request/response bodies + every SSE event || `CCP_ALIAS_PROVIDER` | `aliasProvider` | `codex` | Route Anthropic-style aliases (`haiku`, `sonnet`, `opus`, `claude-*`) through `codex` or `kimi` |@@ -499,23 +505,28 @@ affecting other keys.### Files-- `$XDG_STATE_HOME/claude-code-proxy/proxy.log` — JSON-lines log, rotated at 20- MiB. Secrets (`authorization`, `access`, `refresh`, `id_token`,+- `proxy.log` — JSON-lines log, rotated at 20 MiB. It lives at+ `%LOCALAPPDATA%\claude-code-proxy\proxy.log` on Windows (falling back to+ `%APPDATA%`), and at `$XDG_STATE_HOME/claude-code-proxy/proxy.log` on+ macOS/Linux. Secrets (`authorization`, `access`, `refresh`, `id_token`,`ChatGPT-Account-Id`, …) are redacted before write.-- `~/.config/claude-code-proxy/config.json` (macOS) or- `${XDG_CONFIG_HOME:-$HOME/.config}/claude-code-proxy/config.json` — optional- configuration file (see table above).-- `${XDG_CONFIG_HOME:-$HOME/.config}/claude-code-proxy/codex/auth.json` — codex- tokens (non-macOS; macOS uses Keychain under service- `claude-code-proxy.codex`). Pre-existing files at the legacy path- `~/.config/claude-code-proxy/codex/auth.json` are read as a fallback so- existing logins survive setting `XDG_CONFIG_HOME`.-- `${XDG_CONFIG_HOME:-$HOME/.config}/claude-code-proxy/kimi/auth.json` — kimi- tokens (non-macOS; macOS uses Keychain under service- `claude-code-proxy.kimi`). Same legacy-path fallback as above.-- `${XDG_CONFIG_HOME:-$HOME/.config}/claude-code-proxy/kimi/device_id` —- persistent UUID bound into the Kimi JWT at login. Reused for the lifetime- of the install.+- `config.json` — optional configuration file (see table above). It lives at+ `%APPDATA%\claude-code-proxy\config.json` on Windows,+ `~/.config/claude-code-proxy/config.json` on macOS, and+ `${XDG_CONFIG_HOME:-$HOME/.config}/claude-code-proxy/config.json` on Linux.+- Codex tokens — macOS uses Keychain under service `claude-code-proxy.codex`.+ Windows uses `%APPDATA%\claude-code-proxy\codex\auth.json`; Linux uses+ `${XDG_CONFIG_HOME:-$HOME/.config}/claude-code-proxy/codex/auth.json`.+ Pre-existing files at the legacy path+ `~/.config/claude-code-proxy/codex/auth.json` are read as a fallback.+- Kimi tokens — macOS uses Keychain under service `claude-code-proxy.kimi`.+ Windows uses `%APPDATA%\claude-code-proxy\kimi\auth.json`; Linux uses+ `${XDG_CONFIG_HOME:-$HOME/.config}/claude-code-proxy/kimi/auth.json`. Same+ legacy-path fallback as above.+- Kimi device ID — persistent UUID bound into the Kimi JWT at login. Windows+ uses `%APPDATA%\claude-code-proxy\kimi\device_id`; Linux uses+ `${XDG_CONFIG_HOME:-$HOME/.config}/claude-code-proxy/kimi/device_id`. Reused+ for the lifetime of the install.## Limitationsdiff --git a/src/cli.ts b/src/cli.tsindex a9887a8..e829324 100755--- a/src/cli.ts+++ b/src/cli.ts@@ -1,6 +1,6 @@#!/usr/bin/env bunimport { startServer } from "./server.ts"-import { createLogger, logDir } from "./log.ts"+import { createLogger, logFile } from "./log.ts"import { port as configPort, getConfig, aliasProvider as configAliasProvider } from "./config.ts"import { configDir } from "./paths.ts"import { existsSync } from "node:fs"@@ -31,7 +31,7 @@ async function main() {const port = configPort()startServer({ port })console.log(`Proxy listening on http://localhost:${port}`)- console.log(`Logs: ${logDir()}/proxy.log`)+ console.log(`Logs: ${logFile()}`)printConfigSummary()console.log()console.log("Providers are selected per-request by ANTHROPIC_MODEL:")diff --git a/src/log.ts b/src/log.tsindex 169ef20..07c0e9f 100644--- a/src/log.ts+++ b/src/log.ts@@ -1,7 +1,7 @@-import { mkdir, appendFile, stat, rename } from "node:fs/promises"+import { mkdir, stat, rename } from "node:fs/promises"import { createWriteStream, type WriteStream } from "node:fs"-import { join } from "node:path"-import { stateDir } from "./paths.ts"+import { dirname } from "node:path"+import { logFile } from "./paths.ts"import { logStderr, logVerbose } from "./config.ts"const MAX_LOG_BYTES = 20 * 1024 * 1024 // 20 MiB@@ -18,8 +18,10 @@ export const REDACT_KEYS = new Set(["x-api-key",])+export { logFile }+export function logDir(): string {- return stateDir()+ return dirname(logFile())}let stream: WriteStream | undefined@@ -27,9 +29,8 @@ let rotating: Promise<void> | undefinedasync function ensureStream(): Promise<WriteStream> {if (stream) return stream- const dir = stateDir()- await mkdir(dir, { recursive: true })- const file = join(dir, "proxy.log")+ const file = logFile()+ await mkdir(dirname(file), { recursive: true })stream = createWriteStream(file, { flags: "a", mode: 0o600 })return stream}@@ -38,11 +39,10 @@ async function maybeRotate(): Promise<void> {if (rotating) return rotatingrotating = (async () => {try {- const dir = stateDir()- const file = join(dir, "proxy.log")+ const file = logFile()const s = await stat(file).catch(() => undefined)if (!s || s.size < MAX_LOG_BYTES) return- const rotated = join(dir, `proxy.log.${Date.now()}`)+ const rotated = `${file}.${Date.now()}`await rename(file, rotated)if (stream) {stream.end()diff --git a/src/paths.test.ts b/src/paths.test.tsindex ca3c55a..4088bd4 100644--- a/src/paths.test.ts+++ b/src/paths.test.ts@@ -1,5 +1,12 @@import { describe, expect, it } from "bun:test"-import { resolveConfigDir, resolveStateDir } from "./paths.ts"+import {+ codexAuthFile,+ kimiAuthFile,+ kimiDeviceIdFile,+ legacyConfigDir,+ resolveConfigDir,+ resolveStateDir,+} from "./paths.ts"describe("resolveConfigDir", () => {it("uses ~/.config on darwin even when XDG_CONFIG_HOME is set", () => {@@ -19,6 +26,22 @@ describe("resolveConfigDir", () => {"/home/u/.config/claude-code-proxy",)})++ it("uses APPDATA on windows", () => {+ expect(+ resolveConfigDir({+ platform: "win32",+ env: { APPDATA: "C:\\Users\\u\\AppData\\Roaming" },+ home: "C:\\Users\\u",+ }),+ ).toBe("C:\\Users\\u\\AppData\\Roaming\\claude-code-proxy")+ })++ it("falls back to $HOME/AppData/Roaming on windows without APPDATA", () => {+ expect(resolveConfigDir({ platform: "win32", env: {}, home: "C:\\Users\\u" })).toBe(+ "C:\\Users\\u\\AppData\\Roaming\\claude-code-proxy",+ )+ })})describe("resolveStateDir", () => {@@ -39,4 +62,49 @@ describe("resolveStateDir", () => {resolveStateDir({ platform: "linux", env: { XDG_STATE_HOME: "/x" }, home: "/home/u" }),).toBe("/x/claude-code-proxy")})++ it("uses LOCALAPPDATA on windows", () => {+ expect(+ resolveStateDir({+ platform: "win32",+ env: { LOCALAPPDATA: "C:\\Users\\u\\AppData\\Local" },+ home: "C:\\Users\\u",+ }),+ ).toBe("C:\\Users\\u\\AppData\\Local\\claude-code-proxy")+ })++ it("falls back to APPDATA on windows without LOCALAPPDATA", () => {+ expect(+ resolveStateDir({+ platform: "win32",+ env: { APPDATA: "C:\\Users\\u\\AppData\\Roaming" },+ home: "C:\\Users\\u",+ }),+ ).toBe("C:\\Users\\u\\AppData\\Roaming\\claude-code-proxy")+ })+})++describe("provider paths", () => {+ it("resolves provider files under the windows config directory", () => {+ const deps = {+ platform: "win32" as const,+ env: { APPDATA: "C:\\Users\\u\\AppData\\Roaming" },+ home: "C:\\Users\\u",+ }+ expect(codexAuthFile(deps)).toBe(+ "C:\\Users\\u\\AppData\\Roaming\\claude-code-proxy\\codex\\auth.json",+ )+ expect(kimiAuthFile(deps)).toBe(+ "C:\\Users\\u\\AppData\\Roaming\\claude-code-proxy\\kimi\\auth.json",+ )+ expect(kimiDeviceIdFile(deps)).toBe(+ "C:\\Users\\u\\AppData\\Roaming\\claude-code-proxy\\kimi\\device_id",+ )+ })++ it("keeps the legacy config directory independent of platform", () => {+ expect(legacyConfigDir({ platform: "win32", env: {}, home: "C:\\Users\\u" })).toBe(+ "C:\\Users\\u\\.config\\claude-code-proxy",+ )+ })})diff --git a/src/paths.ts b/src/paths.tsindex 3d40164..78cf833 100644--- a/src/paths.ts+++ b/src/paths.ts@@ -1,5 +1,5 @@import { homedir } from "node:os"-import { join } from "node:path"+import { posix, win32 } from "node:path"export interface DirResolverEnv {platform: NodeJS.Platform@@ -11,22 +11,42 @@ function defaults(): DirResolverEnv {return { platform: process.platform, env: process.env, home: homedir() }}+function pathFor(platform: NodeJS.Platform) {+ return platform === "win32" ? win32 : posix+}++function windowsRoamingAppData(deps: DirResolverEnv): string {+ return deps.env.APPDATA || win32.join(deps.home, "AppData", "Roaming")+}++function windowsLocalAppData(deps: DirResolverEnv): string {+ return deps.env.LOCALAPPDATA || windowsRoamingAppData(deps)+}+// macOS deliberately uses ~/.config/<app> rather than honoring XDG_CONFIG_HOME// (which would redirect to ~/Library/Application Support). This matches where// auth tokens have always been stored on macOS.export function resolveConfigDir(deps: DirResolverEnv): string {+ const path = pathFor(deps.platform)+ if (deps.platform === "win32") {+ return path.join(windowsRoamingAppData(deps), "claude-code-proxy")+ }if (deps.platform === "darwin") {- return join(deps.home, ".config", "claude-code-proxy")+ return path.join(deps.home, ".config", "claude-code-proxy")}- const base = deps.env.XDG_CONFIG_HOME || join(deps.home, ".config")- return join(base, "claude-code-proxy")+ const base = deps.env.XDG_CONFIG_HOME || path.join(deps.home, ".config")+ return path.join(base, "claude-code-proxy")}-// XDG_STATE_HOME is honored on every platform (including macOS) — that's the+// XDG_STATE_HOME is honored on macOS and Unix platforms — that's the// pre-config.json behavior of log.ts and is documented in the README.export function resolveStateDir(deps: DirResolverEnv): string {- const base = deps.env.XDG_STATE_HOME || join(deps.home, ".local", "state")- return join(base, "claude-code-proxy")+ const path = pathFor(deps.platform)+ if (deps.platform === "win32") {+ return path.join(windowsLocalAppData(deps), "claude-code-proxy")+ }+ const base = deps.env.XDG_STATE_HOME || path.join(deps.home, ".local", "state")+ return path.join(base, "claude-code-proxy")}// Legacy (pre-config.json) auth/device-id path. Always ~/.config regardless@@ -34,7 +54,23 @@ export function resolveStateDir(deps: DirResolverEnv): string {// configDir() existed. Used as a read-only fallback so existing logins keep// working after upgrade.export function legacyConfigDir(deps: DirResolverEnv = defaults()): string {- return join(deps.home, ".config", "claude-code-proxy")+ return pathFor(deps.platform).join(deps.home, ".config", "claude-code-proxy")+}++export function codexAuthFile(deps: DirResolverEnv = defaults()): string {+ return pathFor(deps.platform).join(resolveConfigDir(deps), "codex", "auth.json")+}++export function kimiAuthFile(deps: DirResolverEnv = defaults()): string {+ return pathFor(deps.platform).join(resolveConfigDir(deps), "kimi", "auth.json")+}++export function kimiDeviceIdFile(deps: DirResolverEnv = defaults()): string {+ return pathFor(deps.platform).join(resolveConfigDir(deps), "kimi", "device_id")+}++export function logFile(deps: DirResolverEnv = defaults()): string {+ return pathFor(deps.platform).join(resolveStateDir(deps), "proxy.log")}export function configDir(): string {diff --git a/src/providers/codex/auth/token-store.ts b/src/providers/codex/auth/token-store.tsindex 542c7b4..c28b570 100644--- a/src/providers/codex/auth/token-store.ts+++ b/src/providers/codex/auth/token-store.ts@@ -1,7 +1,7 @@import { mkdir, readFile, writeFile, unlink, rename } from "node:fs/promises"import { dirname, join } from "node:path"import { keychainGet, keychainSet, keychainDelete } from "../../../keychain.ts"-import { configDir, legacyConfigDir } from "../../../paths.ts"+import { codexAuthFile, legacyConfigDir } from "../../../paths.ts"export interface StoredAuth {access: string@@ -11,7 +11,7 @@ export interface StoredAuth {}function file(): string {- return join(configDir(), "codex", "auth.json")+ return codexAuthFile()}function legacyFile(): string {return join(legacyConfigDir(), "codex", "auth.json")diff --git a/src/providers/kimi/auth/device-id.ts b/src/providers/kimi/auth/device-id.tsindex 570e9d9..5175042 100644--- a/src/providers/kimi/auth/device-id.ts+++ b/src/providers/kimi/auth/device-id.ts@@ -1,9 +1,9 @@import { mkdir, readFile, writeFile, chmod } from "node:fs/promises"import { dirname, join } from "node:path"-import { configDir, legacyConfigDir } from "../../../paths.ts"+import { kimiDeviceIdFile, legacyConfigDir } from "../../../paths.ts"function path(): string {- return join(configDir(), "kimi", "device_id")+ return kimiDeviceIdFile()}function legacyPath(): string {return join(legacyConfigDir(), "kimi", "device_id")diff --git a/src/providers/kimi/auth/token-store.ts b/src/providers/kimi/auth/token-store.tsindex 6bae7d3..032da16 100644--- a/src/providers/kimi/auth/token-store.ts+++ b/src/providers/kimi/auth/token-store.ts@@ -1,7 +1,7 @@import { mkdir, readFile, writeFile, unlink, rename } from "node:fs/promises"import { dirname, join } from "node:path"import { keychainGet, keychainSet, keychainDelete } from "../../../keychain.ts"-import { configDir, legacyConfigDir } from "../../../paths.ts"+import { kimiAuthFile, legacyConfigDir } from "../../../paths.ts"export interface StoredAuth {access: string@@ -12,7 +12,7 @@ export interface StoredAuth {}function file(): string {- return join(configDir(), "kimi", "auth.json")+ return kimiAuthFile()}function legacyFile(): string {return join(legacyConfigDir(), "kimi", "auth.json")