@anthropic-ai/claude-code 2.1.112 → 2.1.113

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.
package/bin/claude.exe ADDED
@@ -0,0 +1,11 @@
1
+ echo "Error: claude native binary not installed." >&2
2
+ echo "" >&2
3
+ echo "Either postinstall did not run (--ignore-scripts, some pnpm configs)" >&2
4
+ echo "or the platform-native optional dependency was not downloaded" >&2
5
+ echo "(--omit=optional)." >&2
6
+ echo "" >&2
7
+ echo "Run the postinstall manually (adjust path for local vs global install):" >&2
8
+ echo " node node_modules/@anthropic-ai/claude-code/install.cjs" >&2
9
+ echo "" >&2
10
+ echo "Or reinstall without --ignore-scripts / --omit=optional." >&2
11
+ exit 1
@@ -0,0 +1,126 @@
1
+ #!/usr/bin/env node
2
+ // Fallback launcher for the claude wrapper package (name in ./package.json).
3
+ //
4
+ // Normally the postinstall script copies the native binary over bin/claude.exe,
5
+ // so this file is never invoked. It exists for environments where postinstall
6
+ // doesn't run (--ignore-scripts) — users can run `node cli-wrapper.cjs` directly
7
+ // and pay the Node-process overhead as the price.
8
+
9
+ const { spawnSync } = require('child_process')
10
+ const { arch, constants } = require('os')
11
+ const path = require('path')
12
+
13
+ // Replaced at build time via sed. Keep the literals below as markers.
14
+ // Platform detection + PLATFORMS map is duplicated in install.cjs — keep in sync.
15
+ const PACKAGE_PREFIX = '@anthropic-ai/claude-code'
16
+ const BINARY_NAME = 'claude'
17
+ const WRAPPER_NAME = require('./package.json').name
18
+
19
+ const PLATFORMS = {
20
+ 'darwin-arm64': { pkg: PACKAGE_PREFIX + '-darwin-arm64', bin: BINARY_NAME },
21
+ 'darwin-x64': { pkg: PACKAGE_PREFIX + '-darwin-x64', bin: BINARY_NAME },
22
+ 'linux-x64': { pkg: PACKAGE_PREFIX + '-linux-x64', bin: BINARY_NAME },
23
+ 'linux-arm64': { pkg: PACKAGE_PREFIX + '-linux-arm64', bin: BINARY_NAME },
24
+ 'linux-x64-musl': {
25
+ pkg: PACKAGE_PREFIX + '-linux-x64-musl',
26
+ bin: BINARY_NAME,
27
+ },
28
+ 'linux-arm64-musl': {
29
+ pkg: PACKAGE_PREFIX + '-linux-arm64-musl',
30
+ bin: BINARY_NAME,
31
+ },
32
+ 'win32-x64': {
33
+ pkg: PACKAGE_PREFIX + '-win32-x64',
34
+ bin: BINARY_NAME + '.exe',
35
+ },
36
+ 'win32-arm64': {
37
+ pkg: PACKAGE_PREFIX + '-win32-arm64',
38
+ bin: BINARY_NAME + '.exe',
39
+ },
40
+ }
41
+
42
+ function detectMusl() {
43
+ if (process.platform !== 'linux') {
44
+ return false
45
+ }
46
+ const report =
47
+ typeof process.report?.getReport === 'function'
48
+ ? process.report.getReport()
49
+ : null
50
+ return report != null && report.header?.glibcVersionRuntime === undefined
51
+ }
52
+
53
+ function getPlatformKey() {
54
+ const platform = process.platform
55
+ let cpu = arch()
56
+ if (platform === 'linux') {
57
+ return 'linux-' + cpu + (detectMusl() ? '-musl' : '')
58
+ }
59
+ // Rosetta 2: an x64 Node on Apple Silicon reports arch()==='x64'. Prefer the
60
+ // native arm64 binary — the x64 build needs AVX, which Rosetta doesn't emulate.
61
+ if (platform === 'darwin' && cpu === 'x64') {
62
+ const r = spawnSync('sysctl', ['-n', 'sysctl.proc_translated'], {
63
+ encoding: 'utf8',
64
+ })
65
+ if (r.stdout?.trim() === '1') {
66
+ cpu = 'arm64'
67
+ }
68
+ }
69
+ return platform + '-' + cpu
70
+ }
71
+
72
+ function getBinaryPath() {
73
+ const platformKey = getPlatformKey()
74
+ const info = PLATFORMS[platformKey]
75
+ if (!info) {
76
+ console.error(
77
+ `[${WRAPPER_NAME}] Unsupported platform: ${process.platform} ${arch()}. Supported: ${Object.keys(PLATFORMS).join(', ')}`,
78
+ )
79
+ process.exit(1)
80
+ }
81
+ try {
82
+ const pkgDir = path.dirname(require.resolve(info.pkg + '/package.json'))
83
+ return path.join(pkgDir, info.bin)
84
+ } catch {
85
+ console.error(
86
+ `[${WRAPPER_NAME}] Could not find native binary package "${info.pkg}".`,
87
+ )
88
+ if (platformKey === 'darwin-arm64' && arch() === 'x64') {
89
+ console.error(
90
+ ' You are running x64 Node under Rosetta 2 on Apple Silicon. npm only',
91
+ )
92
+ console.error(
93
+ ' installed the darwin-x64 binary, which requires AVX (not emulated by',
94
+ )
95
+ console.error(' Rosetta). Install arm64 Node and reinstall.')
96
+ } else {
97
+ console.error(' Try reinstalling with: npm install')
98
+ }
99
+ process.exit(1)
100
+ }
101
+ }
102
+
103
+ function main() {
104
+ const binaryPath = getBinaryPath()
105
+ const result = spawnSync(binaryPath, process.argv.slice(2), {
106
+ stdio: 'inherit',
107
+ env: { ...process.env, CLAUDE_CODE_INSTALLED_VIA_NPM_WRAPPER: '1' },
108
+ })
109
+ if (result.error) {
110
+ console.error(
111
+ `[${WRAPPER_NAME}] Failed to execute native binary at ` + binaryPath,
112
+ )
113
+ console.error(' ' + result.error.message)
114
+ process.exit(1)
115
+ }
116
+ if (result.signal) {
117
+ // Node.js ignores some signals (e.g. SIGPIPE → SIG_IGN), so re-raising is
118
+ // unreliable. Exit with the POSIX convention 128+signum instead.
119
+ const signum = constants.signals[result.signal] ?? 0
120
+ process.exit(128 + signum)
121
+ } else {
122
+ process.exit(result.status ?? 1)
123
+ }
124
+ }
125
+
126
+ main()
package/install.cjs ADDED
@@ -0,0 +1,191 @@
1
+ #!/usr/bin/env node
2
+ // Postinstall for the claude wrapper package (name in ./package.json).
3
+ //
4
+ // Detects the platform, finds the matching native binary from optionalDependencies,
5
+ // and copies it over the bin/claude.exe placeholder. After this runs, `claude` execs
6
+ // the native binary directly — no Node.js process stays resident.
7
+ //
8
+ // If the native package isn't present (--omit=optional), prints instructions and
9
+ // leaves the placeholder stub in place. cli-wrapper.cjs (same directory) can be
10
+ // invoked manually as a fallback that keeps working via require.resolve + spawn.
11
+ //
12
+ // Platform detection + PLATFORMS map is duplicated in cli-wrapper.cjs — keep in sync.
13
+
14
+ const { spawnSync } = require('child_process')
15
+ const {
16
+ copyFileSync,
17
+ linkSync,
18
+ unlinkSync,
19
+ chmodSync,
20
+ readFileSync,
21
+ writeFileSync,
22
+ statSync,
23
+ } = require('fs')
24
+ const { arch } = require('os')
25
+ const path = require('path')
26
+
27
+ // Replaced at build time via sed. Keep the literals below as markers.
28
+ const PACKAGE_PREFIX = '@anthropic-ai/claude-code'
29
+ const BINARY_NAME = 'claude'
30
+ const WRAPPER_NAME = require('./package.json').name
31
+
32
+ const PLATFORMS = {
33
+ 'darwin-arm64': { pkg: PACKAGE_PREFIX + '-darwin-arm64', bin: BINARY_NAME },
34
+ 'darwin-x64': { pkg: PACKAGE_PREFIX + '-darwin-x64', bin: BINARY_NAME },
35
+ 'linux-x64': { pkg: PACKAGE_PREFIX + '-linux-x64', bin: BINARY_NAME },
36
+ 'linux-arm64': { pkg: PACKAGE_PREFIX + '-linux-arm64', bin: BINARY_NAME },
37
+ 'linux-x64-musl': {
38
+ pkg: PACKAGE_PREFIX + '-linux-x64-musl',
39
+ bin: BINARY_NAME,
40
+ },
41
+ 'linux-arm64-musl': {
42
+ pkg: PACKAGE_PREFIX + '-linux-arm64-musl',
43
+ bin: BINARY_NAME,
44
+ },
45
+ 'win32-x64': {
46
+ pkg: PACKAGE_PREFIX + '-win32-x64',
47
+ bin: BINARY_NAME + '.exe',
48
+ },
49
+ 'win32-arm64': {
50
+ pkg: PACKAGE_PREFIX + '-win32-arm64',
51
+ bin: BINARY_NAME + '.exe',
52
+ },
53
+ }
54
+
55
+ function detectMusl() {
56
+ if (process.platform !== 'linux') {
57
+ return false
58
+ }
59
+ // process.report is available in Node ≥12; glibcVersionRuntime is absent on musl.
60
+ // Faster than spawning `ldd` and avoids the ENOENT→musl false positive when ldd
61
+ // isn't on PATH (minimal containers).
62
+ const report =
63
+ typeof process.report?.getReport === 'function'
64
+ ? process.report.getReport()
65
+ : null
66
+ return report != null && report.header?.glibcVersionRuntime === undefined
67
+ }
68
+
69
+ function getPlatformKey() {
70
+ const platform = process.platform
71
+ let cpu = arch()
72
+ if (platform === 'linux') {
73
+ return 'linux-' + cpu + (detectMusl() ? '-musl' : '')
74
+ }
75
+ // Rosetta 2: an x64 Node on Apple Silicon reports arch()==='x64'. Prefer the
76
+ // native arm64 binary — the x64 build needs AVX, which Rosetta doesn't emulate.
77
+ if (platform === 'darwin' && cpu === 'x64') {
78
+ const r = spawnSync('sysctl', ['-n', 'sysctl.proc_translated'], {
79
+ encoding: 'utf8',
80
+ })
81
+ if (r.stdout?.trim() === '1') {
82
+ cpu = 'arm64'
83
+ }
84
+ }
85
+ return platform + '-' + cpu
86
+ }
87
+
88
+ function placeBinary(src, dest) {
89
+ // Try hardlink first (instant, zero extra disk for a ~500MB binary; src and
90
+ // dest are both under node_modules/ so same-filesystem is the common case).
91
+ // We attempt the link BEFORE touching dest — if src is missing (partial
92
+ // extraction) the first linkSync throws ENOENT and the fallback stub stays.
93
+ try {
94
+ linkSync(src, dest)
95
+ } catch (err) {
96
+ if (err.code === 'EEXIST') {
97
+ // Read the stub before unlinking so we can restore it if both link and
98
+ // copy fail (ENOSPC, NFS error mid-500MB-copy). Only read if dest is
99
+ // stub-sized — on re-install dest is the ~500MB binary.
100
+ const stub = statSync(dest).size < 4096 ? readFileSync(dest) : null
101
+ unlinkSync(dest)
102
+ try {
103
+ linkSync(src, dest)
104
+ } catch {
105
+ try {
106
+ copyFileSync(src, dest)
107
+ } catch (copyErr) {
108
+ if (stub)
109
+ try {
110
+ writeFileSync(dest, stub, { mode: 0o755 })
111
+ } catch {}
112
+ throw copyErr
113
+ }
114
+ }
115
+ } else if (err.code === 'EXDEV' || err.code === 'EPERM') {
116
+ // Cross-device or no-link-perms — copyFileSync overwrites existing dest.
117
+ copyFileSync(src, dest)
118
+ } else {
119
+ throw err
120
+ }
121
+ }
122
+ if (process.platform !== 'win32') {
123
+ chmodSync(dest, 0o755)
124
+ }
125
+ }
126
+
127
+ function main() {
128
+ const platformKey = getPlatformKey()
129
+ const info = PLATFORMS[platformKey]
130
+
131
+ if (!info) {
132
+ console.error(
133
+ `[${WRAPPER_NAME} postinstall] Unsupported platform: ${process.platform} ${arch()}`,
134
+ )
135
+ console.error(` Supported: ${Object.keys(PLATFORMS).join(', ')}`)
136
+ return
137
+ }
138
+
139
+ let src
140
+ try {
141
+ const pkgDir = path.dirname(require.resolve(info.pkg + '/package.json'))
142
+ src = path.join(pkgDir, info.bin)
143
+ } catch {
144
+ console.error(
145
+ `[${WRAPPER_NAME} postinstall] Native package "${info.pkg}" not found.`,
146
+ )
147
+ if (platformKey === 'darwin-arm64' && arch() === 'x64') {
148
+ console.error(
149
+ ' You are running x64 Node under Rosetta 2 on Apple Silicon. npm only',
150
+ )
151
+ console.error(
152
+ ' installed the darwin-x64 binary, which requires AVX (not emulated by',
153
+ )
154
+ console.error(
155
+ ' Rosetta). Install arm64 Node and reinstall — e.g. via nvm:',
156
+ )
157
+ console.error(
158
+ ' arch -arm64 zsh -c "nvm install --lts && npm i -g ' +
159
+ WRAPPER_NAME +
160
+ '"',
161
+ )
162
+ return
163
+ }
164
+ console.error(
165
+ ' This happens with --omit=optional or when the download failed.',
166
+ )
167
+ console.error(
168
+ ' The `claude` command will print instructions when invoked.',
169
+ )
170
+ console.error(' Fallback: node ' + path.join(__dirname, 'cli-wrapper.cjs'))
171
+ return
172
+ }
173
+
174
+ // Always write to bin/claude.exe — the package.json bin field points here.
175
+ // The .exe extension + no-shebang stub makes npm's cmd-shim (generated at
176
+ // install time, before postinstall) emit a direct exec on Windows; Unix
177
+ // ignores the extension. Same pattern as Bun's npm package.
178
+ const dest = path.join(__dirname, 'bin', 'claude.exe')
179
+
180
+ try {
181
+ placeBinary(src, dest)
182
+ } catch (err) {
183
+ console.error(
184
+ `[${WRAPPER_NAME} postinstall] Failed to place binary: ${err.message}`,
185
+ )
186
+ console.error(' Fallback: node ' + path.join(__dirname, 'cli-wrapper.cjs'))
187
+ process.exitCode = 1
188
+ }
189
+ }
190
+
191
+ main()
package/package.json CHANGED
@@ -1,8 +1,12 @@
1
1
  {
2
2
  "name": "@anthropic-ai/claude-code",
3
- "version": "2.1.112",
3
+ "version": "2.1.113",
4
4
  "bin": {
5
- "claude": "cli.js"
5
+ "claude": "bin/claude.exe"
6
+ },
7
+ "scripts": {
8
+ "postinstall": "node install.cjs",
9
+ "prepare": "node -e \"if (!process.env.AUTHORIZED) { console.error('ERROR: Direct publishing is not allowed.\\nPlease see the release workflow documentation to publish this package.'); process.exit(1); }\""
6
10
  },
7
11
  "engines": {
8
12
  "node": ">=18.0.0"
@@ -15,26 +19,21 @@
15
19
  "bugs": {
16
20
  "url": "https://github.com/anthropics/claude-code/issues"
17
21
  },
18
- "scripts": {
19
- "prepare": "node -e \"if (!process.env.AUTHORIZED) { console.error('ERROR: Direct publishing is not allowed.\\nPlease see the release workflow documentation to publish this package.'); process.exit(1); }\""
20
- },
21
22
  "dependencies": {},
22
23
  "optionalDependencies": {
23
- "@img/sharp-darwin-arm64": "^0.34.2",
24
- "@img/sharp-darwin-x64": "^0.34.2",
25
- "@img/sharp-linux-arm": "^0.34.2",
26
- "@img/sharp-linux-arm64": "^0.34.2",
27
- "@img/sharp-linux-x64": "^0.34.2",
28
- "@img/sharp-linuxmusl-arm64": "^0.34.2",
29
- "@img/sharp-linuxmusl-x64": "^0.34.2",
30
- "@img/sharp-win32-arm64": "^0.34.2",
31
- "@img/sharp-win32-x64": "^0.34.2"
24
+ "@anthropic-ai/claude-code-darwin-arm64": "2.1.113",
25
+ "@anthropic-ai/claude-code-darwin-x64": "2.1.113",
26
+ "@anthropic-ai/claude-code-linux-x64": "2.1.113",
27
+ "@anthropic-ai/claude-code-linux-arm64": "2.1.113",
28
+ "@anthropic-ai/claude-code-linux-x64-musl": "2.1.113",
29
+ "@anthropic-ai/claude-code-linux-arm64-musl": "2.1.113",
30
+ "@anthropic-ai/claude-code-win32-x64": "2.1.113",
31
+ "@anthropic-ai/claude-code-win32-arm64": "2.1.113"
32
32
  },
33
33
  "files": [
34
- "cli.js",
35
- "sdk-tools.d.ts",
36
- "vendor/ripgrep/",
37
- "vendor/audio-capture/",
38
- "vendor/seccomp/"
34
+ "bin/claude.exe",
35
+ "install.cjs",
36
+ "cli-wrapper.cjs",
37
+ "sdk-tools.d.ts"
39
38
  ]
40
39
  }