@claude-auth-sdk/core 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +93 -2
  2. package/package.json +17 -4
package/README.md CHANGED
@@ -1,17 +1,108 @@
1
1
  # @claude-auth-sdk/core
2
2
 
3
+ [![npm version](https://img.shields.io/npm/v/%40claude-auth-sdk%2Fcore?label=%40claude-auth-sdk%2Fcore)](https://www.npmjs.com/package/@claude-auth-sdk/core)
4
+
3
5
  Core authentication SDK for Claude. Handles OAuth login, credential storage, and browser opening.
4
6
 
5
- See the [monorepo README](https://github.com/anthropics/claude-auth-sdk#readme) for full documentation.
7
+ See the [monorepo README](https://github.com/wickedev/claude-auth-sdk#readme) for the full docs and example app.
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ npm install @claude-auth-sdk/core
13
+ ```
6
14
 
7
15
  ## Quick start
8
16
 
9
17
  ```ts
10
18
  import { login } from '@claude-auth-sdk/core';
11
19
 
12
- const result = await login('claudeai');
20
+ await login('claudeai');
13
21
  ```
14
22
 
23
+ `login()` opens the browser for OAuth, waits for the callback, exchanges the authorization code for credentials, and stores them locally.
24
+
25
+ ## Authentication modes
26
+
27
+ ```ts
28
+ import { login } from '@claude-auth-sdk/core';
29
+
30
+ await login('claudeai');
31
+ await login('console');
32
+ ```
33
+
34
+ | Mode | Result |
35
+ | --- | --- |
36
+ | `claudeai` | Stores OAuth access and refresh tokens |
37
+ | `console` | Exchanges the OAuth session for an API key |
38
+
39
+ ## Options
40
+
41
+ ```ts
42
+ await login('claudeai', {
43
+ configDir: '/custom/path',
44
+ openBrowserFn: async (url) => {
45
+ // Custom browser launcher
46
+ },
47
+ fetchImpl: customFetch,
48
+ });
49
+ ```
50
+
51
+ - `configDir` changes the credential storage directory from the default `~/.claude`.
52
+ - `openBrowserFn` lets you inject your own browser-opening behavior.
53
+ - `fetchImpl` lets you provide a custom `fetch` implementation.
54
+
55
+ ## Error handling
56
+
57
+ ```ts
58
+ import { LoginError, login } from '@claude-auth-sdk/core';
59
+
60
+ try {
61
+ await login('claudeai');
62
+ } catch (error) {
63
+ if (error instanceof LoginError) {
64
+ console.error(error.code);
65
+ }
66
+ }
67
+ ```
68
+
69
+ Possible `LoginError.code` values:
70
+
71
+ - `cancelled`
72
+ - `timeout`
73
+ - `exchange_failed`
74
+ - `storage_failed`
75
+
76
+ ## Reading stored credentials
77
+
78
+ ```ts
79
+ import { createNodeDefaultStorageAdapter } from '@claude-auth-sdk/core';
80
+
81
+ const storage = createNodeDefaultStorageAdapter();
82
+ const envelope = await storage.read();
83
+
84
+ if (envelope?.terminal.mode === 'compat-oauth') {
85
+ console.log(envelope.terminal.credentials.accessToken);
86
+ }
87
+ ```
88
+
89
+ Credentials are stored in `~/.claude/` by default. On macOS, Keychain is used when available, with JSON files as a fallback.
90
+
91
+ ## API reference
92
+
93
+ | Export | Kind | Description |
94
+ | --- | --- | --- |
95
+ | `login(mode, options?)` | function | Starts the OAuth login flow |
96
+ | `LoginError` | class | Error type with a machine-readable `code` |
97
+ | `createNodeDefaultStorageAdapter(options?)` | function | Creates the default Node.js credential storage adapter |
98
+ | `openBrowser(url)` | function | Opens a URL in the default browser |
99
+ | `LoginMode` | type | `'claudeai' \| 'console'` |
100
+ | `LoginResult` | type | Successful login result |
101
+ | `LoginErrorCode` | type | Login error code union |
102
+ | `LoginInternalOptions` | type | Optional login configuration |
103
+ | `OAuthCredentialBundle` | type | OAuth credential payload |
104
+ | `StoredCredentialEnvelope` | type | Stored credential envelope |
105
+
15
106
  ## License
16
107
 
17
108
  MIT
package/package.json CHANGED
@@ -1,11 +1,15 @@
1
1
  {
2
2
  "name": "@claude-auth-sdk/core",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Core authentication SDK for Claude — OAuth login, credential storage, browser opener",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "sideEffects": false,
8
- "files": ["dist", "LICENSE", "README.md"],
8
+ "files": [
9
+ "dist",
10
+ "LICENSE",
11
+ "README.md"
12
+ ],
9
13
  "main": "./dist/index.js",
10
14
  "types": "./dist/index.d.ts",
11
15
  "exports": {
@@ -16,10 +20,16 @@
16
20
  },
17
21
  "repository": {
18
22
  "type": "git",
19
- "url": "https://github.com/anthropics/claude-auth-sdk.git",
23
+ "url": "https://github.com/wickedev/claude-auth-sdk.git",
20
24
  "directory": "packages/core"
21
25
  },
22
- "keywords": ["claude", "anthropic", "auth", "oauth", "sdk"],
26
+ "keywords": [
27
+ "claude",
28
+ "anthropic",
29
+ "auth",
30
+ "oauth",
31
+ "sdk"
32
+ ],
23
33
  "engines": {
24
34
  "node": ">=20"
25
35
  },
@@ -34,5 +44,8 @@
34
44
  "tsup": "^8.4.0",
35
45
  "typescript": "^5.8.3",
36
46
  "vitest": "^3.0.7"
47
+ },
48
+ "publishConfig": {
49
+ "access": "public"
37
50
  }
38
51
  }