@bash0816/claude-code 2.1.159 → 2.1.161-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.
@@ -40,7 +40,18 @@ export ENTRY_JS_OFFSET
40
40
  export ENTRY_END_OFFSET
41
41
  export CURRENT_CLAUDE_VERSION
42
42
 
43
- node - "$@" <<'NODE'
43
+ _pf=0
44
+ for _a in "$@"; do
45
+ case "$_a" in
46
+ -p|--print) _pf=1; break ;;
47
+ --) break ;;
48
+ esac
49
+ done
50
+
51
+ if [ "$_pf" = "1" ] && [ "${CLAUDE_TERMUX_STDIN:-}" != "inherit" ]; then
52
+ _helper=$(mktemp "${TERMUX_TMPDIR}/claude-helper.XXXXXX.js")
53
+ trap 'rm -f "$_helper"' EXIT HUP INT TERM
54
+ cat <<'NODE' > "$_helper"
44
55
  const fs = require('fs');
45
56
  const path = require('path');
46
57
  const {
@@ -62,10 +73,39 @@ class RequestedExit extends Error {
62
73
  }
63
74
  }
64
75
 
65
- function ensureEntryFile() {
66
- const extractedFile = path.join(workdir, `cli.${entryJsOffset}.${entryEndOffset}.bare-path.js`);
67
- if (fs.existsSync(extractedFile)) return extractedFile;
76
+ function cleanupStaleEntryFiles(currentWorkdir = workdir, currentEntryJsOffset = entryJsOffset, currentEntryEndOffset = entryEndOffset, now = Date.now()) {
77
+ const prefix = `cli.${currentEntryJsOffset}.${currentEntryEndOffset}.`;
78
+ const suffix = '.bare-path.js';
79
+ const maxAgeMs = 24 * 60 * 60 * 1000;
80
+ let entries;
81
+ try {
82
+ entries = fs.readdirSync(currentWorkdir, { withFileTypes: true });
83
+ } catch {
84
+ return;
85
+ }
86
+ for (const entry of entries) {
87
+ if (!entry.isFile() && !entry.isSymbolicLink()) continue;
88
+ if (!entry.name.startsWith(prefix) || !entry.name.endsWith(suffix)) continue;
89
+ const filePath = path.join(currentWorkdir, entry.name);
90
+ let stats;
91
+ try {
92
+ stats = fs.statSync(filePath);
93
+ } catch {
94
+ continue;
95
+ }
96
+ if (Number.isFinite(stats.mtimeMs) && now - stats.mtimeMs < maxAgeMs) continue;
97
+ try {
98
+ fs.rmSync(filePath, { force: true });
99
+ } catch {}
100
+ }
101
+ }
68
102
 
103
+ function ensureEntryFile() {
104
+ cleanupStaleEntryFiles();
105
+ const extractedFile = path.join(
106
+ workdir,
107
+ `cli.${entryJsOffset}.${entryEndOffset}.${process.pid}.${Date.now().toString(36)}.${Math.random().toString(36).slice(2)}.bare-path.js`,
108
+ );
69
109
  const len = entryEndOffset - entryJsOffset;
70
110
  if (!(len > 0)) throw new Error('invalid replay offsets');
71
111
 
@@ -78,19 +118,319 @@ function ensureEntryFile() {
78
118
  return extractedFile;
79
119
  }
80
120
 
121
+ function isFullWidthCodePoint(codePoint) {
122
+ return Number.isFinite(codePoint) && (
123
+ codePoint >= 0x1100 && (
124
+ codePoint <= 0x115f ||
125
+ codePoint === 0x2329 ||
126
+ codePoint === 0x232a ||
127
+ (codePoint >= 0x2e80 && codePoint <= 0xa4cf && codePoint !== 0x303f) ||
128
+ (codePoint >= 0xac00 && codePoint <= 0xd7a3) ||
129
+ (codePoint >= 0xf900 && codePoint <= 0xfaff) ||
130
+ (codePoint >= 0xfe10 && codePoint <= 0xfe19) ||
131
+ (codePoint >= 0xfe30 && codePoint <= 0xfe6f) ||
132
+ (codePoint >= 0xff00 && codePoint <= 0xff60) ||
133
+ (codePoint >= 0xffe0 && codePoint <= 0xffe6) ||
134
+ (codePoint >= 0x1f300 && codePoint <= 0x1f6ff) ||
135
+ (codePoint >= 0x1fa70 && codePoint <= 0x1faff) ||
136
+ (codePoint >= 0x1f900 && codePoint <= 0x1f9ff) ||
137
+ (codePoint >= 0x20000 && codePoint <= 0x3fffd)
138
+ )
139
+ );
140
+ }
141
+
142
+ function graphemeWidth(grapheme) {
143
+ let width = 0;
144
+ const symbols = Array.from(String(grapheme ?? ''));
145
+ const codePoints = symbols.map(symbol => symbol.codePointAt(0)).filter(codePoint => Number.isFinite(codePoint));
146
+ if (codePoints.length === 0) return 0;
147
+ if (codePoints.length > 1 && codePoints.every(codePoint => codePoint >= 0x1f1e6 && codePoint <= 0x1f1ff)) {
148
+ return 2;
149
+ }
150
+ if (codePoints.includes(0x20e3) || codePoints.includes(0x200d)) {
151
+ return 2;
152
+ }
153
+ if (codePoints.includes(0xfe0f) || codePoints.some(codePoint => codePoint >= 0x2600 && codePoint <= 0x27bf)) {
154
+ return 2;
155
+ }
156
+ for (const symbol of symbols) {
157
+ const codePoint = symbol.codePointAt(0);
158
+ if (codePoint === undefined || codePoint === 0) continue;
159
+ if (codePoint < 32 || (codePoint >= 0x7f && codePoint < 0xa0)) continue;
160
+ if (codePoint === 0x200d || codePoint === 0xfe0f) continue;
161
+ if (/\p{M}/u.test(symbol)) continue;
162
+ if (isFullWidthCodePoint(codePoint)) return 2;
163
+ width = 1;
164
+ }
165
+ return width;
166
+ }
167
+
81
168
  function stringWidth(value) {
82
- const text = String(value ?? '');
169
+ const text = stripANSI(value);
83
170
  if (typeof Intl !== 'undefined' && typeof Intl.Segmenter === 'function') {
84
171
  const segmenter = new Intl.Segmenter('en', { granularity: 'grapheme' });
85
172
  let width = 0;
86
- for (const _segment of segmenter.segment(text)) width += 1;
173
+ for (const segment of segmenter.segment(text)) width += graphemeWidth(segment.segment);
87
174
  return width;
88
175
  }
89
- return Array.from(text).length;
176
+ return Array.from(text).reduce((width, symbol) => width + graphemeWidth(symbol), 0);
177
+ }
178
+
179
+ function stripANSI(value) {
180
+ return String(value ?? '')
181
+ .replace(/\x1B\[[0-?]*[ -/]*[@-~]/g, '')
182
+ .replace(/\x1B\][^\x07]*(?:\x07|\x1B\\)/g, '');
183
+ }
184
+
185
+ function wrapAnsi(value, columns, options = {}) {
186
+ const text = String(value ?? '');
187
+ const width = Number(columns);
188
+ const hard = options.hard !== false;
189
+ const trim = options.trim === true;
190
+ const wordWrap = options.wordWrap !== false;
191
+ if (!Number.isFinite(width) || width <= 0) return trim ? text.trimEnd() : text;
192
+
193
+ const ansiPattern = /\x1B\[[0-?]*[ -/]*[@-~]|\x1B\][^\x07]*(?:\x07|\x1B\\)/g;
194
+ const segmenter = typeof Intl !== 'undefined' && typeof Intl.Segmenter === 'function'
195
+ ? new Intl.Segmenter('en', { granularity: 'grapheme' })
196
+ : null;
197
+ const splitVisible = (chunk) => {
198
+ if (chunk === '') return [];
199
+ if (!segmenter) return Array.from(chunk);
200
+ return Array.from(segmenter.segment(chunk), part => part.segment);
201
+ };
202
+ const splitByGrapheme = hard || !wordWrap;
203
+ let result = '';
204
+ let currentWidth = 0;
205
+ let lastIndex = 0;
206
+ const appendVisible = (chunk) => {
207
+ const tokens = splitByGrapheme ? splitVisible(chunk) : (chunk.match(/\s+|[^\s]+/gu) || []);
208
+ for (const token of tokens) {
209
+ if (token === '\n') {
210
+ if (trim) result = result.replace(/[ \t]+$/g, '');
211
+ result += token;
212
+ currentWidth = 0;
213
+ continue;
214
+ }
215
+ const tokenWidth = stringWidth(token);
216
+ const isWhitespace = /^\s+$/u.test(token);
217
+ if (trim && isWhitespace && currentWidth === 0) continue;
218
+ if (currentWidth > 0 && currentWidth + tokenWidth > width) {
219
+ if (!splitByGrapheme && !isWhitespace) {
220
+ result = result.replace(/[ \t]+$/g, '');
221
+ result += '\n';
222
+ currentWidth = 0;
223
+ } else {
224
+ for (const piece of splitVisible(token)) {
225
+ const pieceWidth = stringWidth(piece);
226
+ if (currentWidth > 0 && currentWidth + pieceWidth > width) {
227
+ if (trim) result = result.replace(/[ \t]+$/g, '');
228
+ result += '\n';
229
+ currentWidth = 0;
230
+ }
231
+ if (trim && /^\s+$/u.test(piece) && currentWidth === 0) continue;
232
+ result += piece;
233
+ currentWidth += pieceWidth;
234
+ }
235
+ continue;
236
+ }
237
+ }
238
+ result += token;
239
+ currentWidth += tokenWidth;
240
+ }
241
+ };
242
+ for (const match of text.matchAll(ansiPattern)) {
243
+ appendVisible(text.slice(lastIndex, match.index ?? 0));
244
+ result += match[0];
245
+ lastIndex = (match.index ?? 0) + match[0].length;
246
+ }
247
+ appendVisible(text.slice(lastIndex));
248
+ return trim ? result.replace(/[ \t]+$/gm, '') : result;
249
+ }
250
+
251
+ function stableHash(value, seed) {
252
+ const text = String(value ?? '');
253
+ let hash = 2166136261;
254
+ if (seed !== undefined) {
255
+ const seedText = String(seed ?? '');
256
+ for (let i = 0; i < seedText.length; i += 1) {
257
+ hash ^= seedText.charCodeAt(i);
258
+ hash = Math.imul(hash, 16777619);
259
+ }
260
+ hash ^= 0x9e3779b9;
261
+ hash = Math.imul(hash, 16777619);
262
+ }
263
+ for (let i = 0; i < text.length; i += 1) {
264
+ hash ^= text.charCodeAt(i);
265
+ hash = Math.imul(hash, 16777619);
266
+ }
267
+ return hash >>> 0;
268
+ }
269
+
270
+ function replaceRequired(source, pattern, replacement, label, expectedCount) {
271
+ const text = String(source);
272
+ const matches = text.match(pattern);
273
+ if (!matches || matches.length === 0) {
274
+ throw new Error(`rewriteNativeChunkSource: missing ${label}`);
275
+ }
276
+ if (expectedCount !== undefined && matches.length !== expectedCount) {
277
+ throw new Error(`rewriteNativeChunkSource: unexpected ${label} count ${matches.length}`);
278
+ }
279
+ return text.replace(pattern, replacement);
280
+ }
281
+
282
+ function parseScalar(value) {
283
+ const text = String(value ?? '').trim();
284
+ if (text === '') return '';
285
+ if (text === 'true') return true;
286
+ if (text === 'false') return false;
287
+ if (text === 'null' || text === '~') return null;
288
+ if (/^-?(?:0|[1-9]\d*)(?:\.\d+)?$/.test(text)) return Number(text);
289
+ if (
290
+ (text.startsWith('"') && text.endsWith('"')) ||
291
+ (text.startsWith("'") && text.endsWith("'"))
292
+ ) {
293
+ return text.slice(1, -1);
294
+ }
295
+ return text;
296
+ }
297
+
298
+ function parseInlineArray(value) {
299
+ const inner = String(value ?? '').trim().slice(1, -1).trim();
300
+ if (inner === '') return [];
301
+ const items = [];
302
+ let current = '';
303
+ let quote = null;
304
+
305
+ for (let i = 0; i < inner.length; i += 1) {
306
+ const ch = inner[i];
307
+ if (quote) {
308
+ if (ch === quote && inner[i - 1] !== '\\') quote = null;
309
+ current += ch;
310
+ continue;
311
+ }
312
+ if (ch === '"' || ch === "'") {
313
+ quote = ch;
314
+ current += ch;
315
+ continue;
316
+ }
317
+ if (ch === ',') {
318
+ items.push(parseScalar(current));
319
+ current = '';
320
+ continue;
321
+ }
322
+ current += ch;
323
+ }
324
+
325
+ if (current !== '') items.push(parseScalar(current));
326
+ return items;
327
+ }
328
+
329
+ function yamlParse(text) {
330
+ const source = String(text ?? '');
331
+ const result = {};
332
+ for (const rawLine of source.split(/\r?\n/)) {
333
+ const line = rawLine.trim();
334
+ if (!line || line.startsWith('#')) continue;
335
+ const idx = line.indexOf(':');
336
+ if (idx < 0) continue;
337
+ const key = line.slice(0, idx).trim();
338
+ const rawValue = line.slice(idx + 1).trim();
339
+ if (!key) continue;
340
+ result[key] = rawValue.startsWith('[') && rawValue.endsWith(']')
341
+ ? parseInlineArray(rawValue)
342
+ : parseScalar(rawValue);
343
+ }
344
+ return result;
345
+ }
346
+
347
+ function yamlStringify(value) {
348
+ if (!value || typeof value !== 'object') return String(value ?? '');
349
+ const lines = [];
350
+ for (const [key, raw] of Object.entries(value)) {
351
+ if (Array.isArray(raw)) {
352
+ lines.push(`${key}: [${raw.map(item => JSON.stringify(String(item))).join(', ')}]`);
353
+ } else if (raw === null) {
354
+ lines.push(`${key}: null`);
355
+ } else if (typeof raw === 'string') {
356
+ lines.push(`${key}: ${JSON.stringify(raw)}`);
357
+ } else {
358
+ lines.push(`${key}: ${String(raw)}`);
359
+ }
360
+ }
361
+ return lines.join('\n');
362
+ }
363
+
364
+ function createYamlShim() {
365
+ const yaml = {
366
+ parse: yamlParse,
367
+ stringify: yamlStringify,
368
+ };
369
+ yaml.YAML = yaml;
370
+ yaml.default = yaml;
371
+ return yaml;
90
372
  }
91
373
 
92
374
  function createFakeRequire(realRequire) {
93
375
  const realChild = realRequire('child_process');
376
+ const realVm = realRequire('vm');
377
+
378
+ function injectBunIntoContext(context) {
379
+ if (!context || typeof context !== 'object') return context;
380
+ try {
381
+ if (!Object.prototype.hasOwnProperty.call(context, '__claudeYaml')) {
382
+ Object.defineProperty(context, '__claudeYaml', {
383
+ value: globalThis.__claudeYaml,
384
+ configurable: true,
385
+ writable: true,
386
+ });
387
+ }
388
+ if (!Object.prototype.hasOwnProperty.call(context, '__claudeBunShim')) {
389
+ Object.defineProperty(context, '__claudeBunShim', {
390
+ value: globalThis.__claudeBunShim,
391
+ configurable: true,
392
+ writable: true,
393
+ });
394
+ }
395
+ if (!Object.prototype.hasOwnProperty.call(context, '__claudeBun')) {
396
+ Object.defineProperty(context, '__claudeBun', {
397
+ value: globalThis.__claudeBunShim,
398
+ configurable: true,
399
+ writable: true,
400
+ });
401
+ }
402
+ if (Object.prototype.hasOwnProperty.call(context, 'Bun')) {
403
+ if (context.Bun && typeof context.Bun === 'object' && context.Bun !== globalThis.Bun) {
404
+ try {
405
+ context.Bun = globalThis.Bun;
406
+ } catch {
407
+ Object.defineProperty(context, 'Bun', {
408
+ value: globalThis.Bun,
409
+ configurable: true,
410
+ writable: true,
411
+ });
412
+ }
413
+ }
414
+ if (!context.Bun || typeof context.Bun !== 'object') {
415
+ Object.defineProperty(context, 'Bun', {
416
+ value: globalThis.Bun,
417
+ configurable: true,
418
+ writable: true,
419
+ });
420
+ }
421
+ } else {
422
+ Object.defineProperty(context, 'Bun', {
423
+ value: globalThis.Bun,
424
+ configurable: true,
425
+ writable: true,
426
+ });
427
+ }
428
+ if (context.Bun && globalThis.__claudeYaml) {
429
+ context.Bun.YAML = globalThis.__claudeYaml;
430
+ }
431
+ } catch {}
432
+ return context;
433
+ }
94
434
 
95
435
  function rewriteArgs(args) {
96
436
  if (
@@ -129,6 +469,49 @@ function createFakeRequire(realRequire) {
129
469
  return { default: WS, WebSocket: WS };
130
470
  }
131
471
 
472
+ if (id === 'vm' || id === 'node:vm') {
473
+ if (!realVm.__claudeBunShimPatched) {
474
+ const originalCreateContext = realVm.createContext.bind(realVm);
475
+ const originalRunInNewContext = realVm.runInNewContext.bind(realVm);
476
+ const originalRunInContext = realVm.runInContext.bind(realVm);
477
+ const originalRunInThisContext = realVm.runInThisContext && realVm.runInThisContext.bind(realVm);
478
+ const scriptProto = realVm.Script && realVm.Script.prototype;
479
+
480
+ realVm.createContext = (contextObject, ...rest) =>
481
+ originalCreateContext(injectBunIntoContext(contextObject), ...rest);
482
+ realVm.runInNewContext = (code, contextObject, ...rest) =>
483
+ originalRunInNewContext(code, injectBunIntoContext(contextObject), ...rest);
484
+ realVm.runInContext = (code, contextObject, ...rest) =>
485
+ originalRunInContext(code, injectBunIntoContext(contextObject), ...rest);
486
+ if (originalRunInThisContext) {
487
+ realVm.runInThisContext = (code, ...rest) => originalRunInThisContext(code, ...rest);
488
+ }
489
+
490
+ if (scriptProto && !scriptProto.__claudeBunShimPatched) {
491
+ const originalScriptRunInContext = scriptProto.runInContext;
492
+ const originalScriptRunInNewContext = scriptProto.runInNewContext;
493
+ const originalScriptRunInThisContext = scriptProto.runInThisContext;
494
+
495
+ scriptProto.runInContext = function (contextObject, ...rest) {
496
+ return originalScriptRunInContext.call(this, injectBunIntoContext(contextObject), ...rest);
497
+ };
498
+ scriptProto.runInNewContext = function (contextObject, ...rest) {
499
+ return originalScriptRunInNewContext.call(this, injectBunIntoContext(contextObject), ...rest);
500
+ };
501
+ if (originalScriptRunInThisContext) {
502
+ scriptProto.runInThisContext = function (...rest) {
503
+ return originalScriptRunInThisContext.call(this, ...rest);
504
+ };
505
+ }
506
+
507
+ Object.defineProperty(scriptProto, '__claudeBunShimPatched', { value: true });
508
+ }
509
+
510
+ Object.defineProperty(realVm, '__claudeBunShimPatched', { value: true });
511
+ }
512
+ return realVm;
513
+ }
514
+
132
515
  if (id === 'child_process') {
133
516
  return guardedChild;
134
517
  }
@@ -145,10 +528,54 @@ function createFakeRequire(realRequire) {
145
528
  };
146
529
  }
147
530
 
531
+ function rewriteNativeChunkSource(source) {
532
+ const rawPrefix = 'function(exports, require, module, __filename, __dirname) {';
533
+ const injectedPrefix = rawPrefix + 'var __claudeBun = globalThis.__claudeBunShim;';
534
+ let patched = String(source);
535
+ patched = replaceRequired(
536
+ patched,
537
+ /^function\(exports, require, module, __filename, __dirname\) \{(?:var __claudeBun = globalThis\.__claudeBunShim;)?/,
538
+ injectedPrefix,
539
+ 'module wrapper prefix',
540
+ 1,
541
+ );
542
+ patched = replaceRequired(
543
+ patched,
544
+ /\btypeof Bun\b/g,
545
+ 'typeof __claudeBun',
546
+ 'typeof Bun',
547
+ 3,
548
+ );
549
+ patched = replaceRequired(
550
+ patched,
551
+ /\btypeof globalThis\.Bun\b/g,
552
+ 'typeof globalThis.__claudeBun',
553
+ 'typeof globalThis.Bun',
554
+ 1,
555
+ );
556
+ patched = replaceRequired(
557
+ patched,
558
+ /\bglobalThis\.Bun\b/g,
559
+ 'globalThis.__claudeBun',
560
+ 'globalThis.Bun',
561
+ 1,
562
+ );
563
+ patched = replaceRequired(
564
+ patched,
565
+ /\bBun\./g,
566
+ '__claudeBun.',
567
+ 'Bun property access',
568
+ 31,
569
+ );
570
+ return patched;
571
+ }
572
+
148
573
  async function main() {
149
- const extractedFile = ensureEntryFile();
574
+ let extractedFile;
575
+ extractedFile = ensureEntryFile();
150
576
  const code = fs.readFileSync(extractedFile, 'utf8');
151
- const fn = eval('(' + code);
577
+ const patchedCode = rewriteNativeChunkSource(code);
578
+ const fn = eval('(' + patchedCode.replace(/\)\s*$/, '') + ')');
152
579
 
153
580
  const originalArgv = process.argv.slice();
154
581
  const originalExit = process.exit;
@@ -157,6 +584,10 @@ async function main() {
157
584
  const originalGlobalBun = globalThis.Bun;
158
585
  const asyncErrors = [];
159
586
 
587
+ globalThis.__claudeYaml = createYamlShim();
588
+ if (!globalThis.__claudeBunShim || typeof globalThis.__claudeBunShim !== 'object') {
589
+ globalThis.__claudeBunShim = {};
590
+ }
160
591
  const fakeRequire = createFakeRequire(require);
161
592
  function onAsyncError(error) {
162
593
  asyncErrors.push(error);
@@ -166,16 +597,70 @@ async function main() {
166
597
  process.once('uncaughtException', onAsyncError);
167
598
  process.once('unhandledRejection', onAsyncError);
168
599
  Object.defineProperty(process.versions, 'bun', { value: '1.1.8', configurable: true });
169
- globalThis.Bun = { version: '1.1.8', stringWidth };
600
+ const _realChild = require('child_process');
601
+ globalThis.Bun = {
602
+ version: '1.1.8',
603
+ stringWidth,
604
+ wrapAnsi,
605
+ stripANSI,
606
+ hash: stableHash,
607
+ which: (cmd) => {
608
+ try {
609
+ return _realChild.execFileSync('which', [String(cmd)], { encoding: 'utf8' }).trim() || null;
610
+ } catch { return null; }
611
+ },
612
+ semver: (() => {
613
+ const _cmp = (a, b) => {
614
+ const pa = String(a).replace(/[^0-9.]/g,'').split('.').map(Number);
615
+ const pb = String(b).replace(/[^0-9.]/g,'').split('.').map(Number);
616
+ for (let i = 0; i < 3; i++) { const d = (pa[i]||0)-(pb[i]||0); if (d) return d > 0 ? 1 : -1; }
617
+ return 0;
618
+ };
619
+ const _satisfies = (ver, range) => {
620
+ const s = String(range).trim();
621
+ const m = s.match(/^([><=!]{1,2})\s*([\d]+(?:\.[\d]+){0,2})$/);
622
+ if (m) {
623
+ const op = m[1], c = _cmp(ver, m[2]);
624
+ if (op === '>') return c > 0;
625
+ if (op === '>=') return c >= 0;
626
+ if (op === '<') return c < 0;
627
+ if (op === '<=') return c <= 0;
628
+ if (op === '=' || op === '==') return c === 0;
629
+ if (op === '!=') return c !== 0;
630
+ }
631
+ if (/^[\d]+(?:\.[\d]+){0,2}$/.test(s)) return _cmp(ver, s) === 0;
632
+ return false;
633
+ };
634
+ return {
635
+ order: (a, b) => _cmp(a, b),
636
+ compare: (a, b) => _cmp(a, b),
637
+ satisfies: (ver, range) => _satisfies(ver, range),
638
+ gt: (a, b) => _cmp(a, b) > 0,
639
+ gte: (a, b) => _cmp(a, b) >= 0,
640
+ lt: (a, b) => _cmp(a, b) < 0,
641
+ lte: (a, b) => _cmp(a, b) <= 0,
642
+ };
643
+ })(),
644
+ YAML: globalThis.__claudeYaml,
645
+ };
646
+ Object.assign(globalThis.__claudeBunShim, globalThis.Bun);
647
+ if (typeof globalThis.__claudeBunShim.gc !== 'function') {
648
+ globalThis.__claudeBunShim.gc = () => {};
649
+ }
650
+ globalThis.__claudeBun = globalThis.__claudeBunShim;
651
+ globalThis.Bun = globalThis.__claudeBunShim;
170
652
  process.argv = ['node', extractedFile, ...argv];
171
653
  process.exit = code => {
172
654
  throw new RequestedExit(code);
173
655
  };
174
656
 
657
+ const printWaitMs = Number(process.env.CLAUDE_TERMUX_PRINT_WAIT_MS || 5000);
175
658
  const moduleLike = { exports: {} };
176
659
  const maybePromise = fn(moduleLike.exports, fakeRequire, moduleLike, extractedFile, workdir);
177
660
  if (maybePromise && typeof maybePromise.then === 'function') await maybePromise;
178
- await new Promise(resolve => setTimeout(resolve, 200));
661
+ if (Number.isFinite(printWaitMs) && printWaitMs > 0) {
662
+ await new Promise(resolve => setTimeout(resolve, printWaitMs));
663
+ }
179
664
  if (asyncErrors.length > 0) throw asyncErrors[0];
180
665
  } catch (error) {
181
666
  if (error instanceof RequestedExit) {
@@ -186,6 +671,11 @@ async function main() {
186
671
  } finally {
187
672
  process.removeListener('uncaughtException', onAsyncError);
188
673
  process.removeListener('unhandledRejection', onAsyncError);
674
+ if (extractedFile) {
675
+ try {
676
+ fs.rmSync(extractedFile, { force: true });
677
+ } catch {}
678
+ }
189
679
  process.argv = originalArgv;
190
680
  process.exit = originalExit;
191
681
  try {
@@ -195,6 +685,9 @@ async function main() {
195
685
  Object.defineProperty(process.versions, 'bun', { value: originalBun, configurable: true });
196
686
  }
197
687
  } catch {}
688
+ delete globalThis.__claudeYaml;
689
+ delete globalThis.__claudeBunShim;
690
+ delete globalThis.__claudeBun;
198
691
  if (hadGlobalBun) globalThis.Bun = originalGlobalBun;
199
692
  else delete globalThis.Bun;
200
693
  }
@@ -209,3 +702,671 @@ main().catch(error => {
209
702
  process.exit(1);
210
703
  });
211
704
  NODE
705
+ export CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC="${CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC:-1}"
706
+ export ENABLE_CLAUDEAI_MCP_SERVERS="${ENABLE_CLAUDEAI_MCP_SERVERS:-0}"
707
+ export CLAUDE_CODE_SIMPLE="${CLAUDE_CODE_SIMPLE:-0}"
708
+ node "$_helper" "$@" </dev/null
709
+ _status=$?
710
+ rm -f "$_helper"
711
+ trap - EXIT HUP INT TERM
712
+ exit "$_status"
713
+ else
714
+ _bootstrap=$(mktemp "${TERMUX_TMPDIR}/claude-bootstrap.XXXXXX.js")
715
+ trap 'rm -f "$_bootstrap"' EXIT HUP INT TERM
716
+ cat <<'NODE' > "$_bootstrap"
717
+ const fs = require('fs');
718
+ const path = require('path');
719
+ const {
720
+ BLOCK_MESSAGE,
721
+ createGuardedChildProcess,
722
+ } = require(path.join(process.env.CLAUDE_TERMUX_PACKAGE_DIR, 'lib', 'native-update-guard.js'));
723
+
724
+ const sourceBin = process.env.SOURCE_BIN;
725
+ const workdir = process.env.WORKDIR;
726
+ const entryJsOffset = Number(process.env.ENTRY_JS_OFFSET);
727
+ const entryEndOffset = Number(process.env.ENTRY_END_OFFSET);
728
+ const argv = process.argv.slice(2);
729
+
730
+ class RequestedExit extends Error {
731
+ constructor(code) {
732
+ super(`process.exit ${code}`);
733
+ this.name = 'RequestedExit';
734
+ this.code = code;
735
+ }
736
+ }
737
+
738
+ function cleanupStaleEntryFiles(currentWorkdir = workdir, currentEntryJsOffset = entryJsOffset, currentEntryEndOffset = entryEndOffset, now = Date.now()) {
739
+ const prefix = `cli.${currentEntryJsOffset}.${currentEntryEndOffset}.`;
740
+ const suffix = '.bare-path.js';
741
+ const maxAgeMs = 24 * 60 * 60 * 1000;
742
+ let entries;
743
+ try {
744
+ entries = fs.readdirSync(currentWorkdir, { withFileTypes: true });
745
+ } catch {
746
+ return;
747
+ }
748
+ for (const entry of entries) {
749
+ if (!entry.isFile() && !entry.isSymbolicLink()) continue;
750
+ if (!entry.name.startsWith(prefix) || !entry.name.endsWith(suffix)) continue;
751
+ const filePath = path.join(currentWorkdir, entry.name);
752
+ let stats;
753
+ try {
754
+ stats = fs.statSync(filePath);
755
+ } catch {
756
+ continue;
757
+ }
758
+ if (Number.isFinite(stats.mtimeMs) && now - stats.mtimeMs < maxAgeMs) continue;
759
+ try {
760
+ fs.rmSync(filePath, { force: true });
761
+ } catch {}
762
+ }
763
+ }
764
+
765
+ function ensureEntryFile() {
766
+ cleanupStaleEntryFiles();
767
+ const extractedFile = path.join(
768
+ workdir,
769
+ `cli.${entryJsOffset}.${entryEndOffset}.${process.pid}.${Date.now().toString(36)}.${Math.random().toString(36).slice(2)}.bare-path.js`,
770
+ );
771
+ const len = entryEndOffset - entryJsOffset;
772
+ if (!(len > 0)) throw new Error('invalid replay offsets');
773
+
774
+ const fd = fs.openSync(sourceBin, 'r');
775
+ const buf = Buffer.alloc(len);
776
+ fs.readSync(fd, buf, 0, len, entryJsOffset);
777
+ fs.closeSync(fd);
778
+
779
+ fs.writeFileSync(extractedFile, buf.toString('utf8').replace(/[\0\s]+$/g, ''));
780
+ return extractedFile;
781
+ }
782
+
783
+ function isFullWidthCodePoint(codePoint) {
784
+ return Number.isFinite(codePoint) && (
785
+ codePoint >= 0x1100 && (
786
+ codePoint <= 0x115f ||
787
+ codePoint === 0x2329 ||
788
+ codePoint === 0x232a ||
789
+ (codePoint >= 0x2e80 && codePoint <= 0xa4cf && codePoint !== 0x303f) ||
790
+ (codePoint >= 0xac00 && codePoint <= 0xd7a3) ||
791
+ (codePoint >= 0xf900 && codePoint <= 0xfaff) ||
792
+ (codePoint >= 0xfe10 && codePoint <= 0xfe19) ||
793
+ (codePoint >= 0xfe30 && codePoint <= 0xfe6f) ||
794
+ (codePoint >= 0xff00 && codePoint <= 0xff60) ||
795
+ (codePoint >= 0xffe0 && codePoint <= 0xffe6) ||
796
+ (codePoint >= 0x1f300 && codePoint <= 0x1f6ff) ||
797
+ (codePoint >= 0x1fa70 && codePoint <= 0x1faff) ||
798
+ (codePoint >= 0x1f900 && codePoint <= 0x1f9ff) ||
799
+ (codePoint >= 0x20000 && codePoint <= 0x3fffd)
800
+ )
801
+ );
802
+ }
803
+
804
+ function graphemeWidth(grapheme) {
805
+ let width = 0;
806
+ const symbols = Array.from(String(grapheme ?? ''));
807
+ const codePoints = symbols.map(symbol => symbol.codePointAt(0)).filter(codePoint => Number.isFinite(codePoint));
808
+ if (codePoints.length === 0) return 0;
809
+ if (codePoints.length > 1 && codePoints.every(codePoint => codePoint >= 0x1f1e6 && codePoint <= 0x1f1ff)) {
810
+ return 2;
811
+ }
812
+ if (codePoints.includes(0x20e3) || codePoints.includes(0x200d)) {
813
+ return 2;
814
+ }
815
+ if (codePoints.includes(0xfe0f) || codePoints.some(codePoint => codePoint >= 0x2600 && codePoint <= 0x27bf)) {
816
+ return 2;
817
+ }
818
+ for (const symbol of symbols) {
819
+ const codePoint = symbol.codePointAt(0);
820
+ if (codePoint === undefined || codePoint === 0) continue;
821
+ if (codePoint < 32 || (codePoint >= 0x7f && codePoint < 0xa0)) continue;
822
+ if (codePoint === 0x200d || codePoint === 0xfe0f) continue;
823
+ if (/\p{M}/u.test(symbol)) continue;
824
+ if (isFullWidthCodePoint(codePoint)) return 2;
825
+ width = 1;
826
+ }
827
+ return width;
828
+ }
829
+
830
+ function stringWidth(value) {
831
+ const text = stripANSI(value);
832
+ if (typeof Intl !== 'undefined' && typeof Intl.Segmenter === 'function') {
833
+ const segmenter = new Intl.Segmenter('en', { granularity: 'grapheme' });
834
+ let width = 0;
835
+ for (const segment of segmenter.segment(text)) width += graphemeWidth(segment.segment);
836
+ return width;
837
+ }
838
+ return Array.from(text).reduce((width, symbol) => width + graphemeWidth(symbol), 0);
839
+ }
840
+
841
+ function stripANSI(value) {
842
+ return String(value ?? '')
843
+ .replace(/\x1B\[[0-?]*[ -/]*[@-~]/g, '')
844
+ .replace(/\x1B\][^\x07]*(?:\x07|\x1B\\)/g, '');
845
+ }
846
+
847
+ function wrapAnsi(value, columns, options = {}) {
848
+ const text = String(value ?? '');
849
+ const width = Number(columns);
850
+ const hard = options.hard !== false;
851
+ const trim = options.trim === true;
852
+ const wordWrap = options.wordWrap !== false;
853
+ if (!Number.isFinite(width) || width <= 0) return trim ? text.trimEnd() : text;
854
+
855
+ const ansiPattern = /\x1B\[[0-?]*[ -/]*[@-~]|\x1B\][^\x07]*(?:\x07|\x1B\\)/g;
856
+ const segmenter = typeof Intl !== 'undefined' && typeof Intl.Segmenter === 'function'
857
+ ? new Intl.Segmenter('en', { granularity: 'grapheme' })
858
+ : null;
859
+ const splitVisible = (chunk) => {
860
+ if (chunk === '') return [];
861
+ if (!segmenter) return Array.from(chunk);
862
+ return Array.from(segmenter.segment(chunk), part => part.segment);
863
+ };
864
+ const splitByGrapheme = hard || !wordWrap;
865
+ let result = '';
866
+ let currentWidth = 0;
867
+ let lastIndex = 0;
868
+ const appendVisible = (chunk) => {
869
+ const tokens = splitByGrapheme ? splitVisible(chunk) : (chunk.match(/\s+|[^\s]+/gu) || []);
870
+ for (const token of tokens) {
871
+ if (token === '\n') {
872
+ if (trim) result = result.replace(/[ \t]+$/g, '');
873
+ result += token;
874
+ currentWidth = 0;
875
+ continue;
876
+ }
877
+ const tokenWidth = stringWidth(token);
878
+ const isWhitespace = /^\s+$/u.test(token);
879
+ if (trim && isWhitespace && currentWidth === 0) continue;
880
+ if (currentWidth > 0 && currentWidth + tokenWidth > width) {
881
+ if (!splitByGrapheme && !isWhitespace) {
882
+ result = result.replace(/[ \t]+$/g, '');
883
+ result += '\n';
884
+ currentWidth = 0;
885
+ } else {
886
+ for (const piece of splitVisible(token)) {
887
+ const pieceWidth = stringWidth(piece);
888
+ if (currentWidth > 0 && currentWidth + pieceWidth > width) {
889
+ if (trim) result = result.replace(/[ \t]+$/g, '');
890
+ result += '\n';
891
+ currentWidth = 0;
892
+ }
893
+ if (trim && /^\s+$/u.test(piece) && currentWidth === 0) continue;
894
+ result += piece;
895
+ currentWidth += pieceWidth;
896
+ }
897
+ continue;
898
+ }
899
+ }
900
+ result += token;
901
+ currentWidth += tokenWidth;
902
+ }
903
+ };
904
+ for (const match of text.matchAll(ansiPattern)) {
905
+ appendVisible(text.slice(lastIndex, match.index ?? 0));
906
+ result += match[0];
907
+ lastIndex = (match.index ?? 0) + match[0].length;
908
+ }
909
+ appendVisible(text.slice(lastIndex));
910
+ return trim ? result.replace(/[ \t]+$/gm, '') : result;
911
+ }
912
+
913
+ function stableHash(value, seed) {
914
+ const text = String(value ?? '');
915
+ let hash = 2166136261;
916
+ if (seed !== undefined) {
917
+ const seedText = String(seed ?? '');
918
+ for (let i = 0; i < seedText.length; i += 1) {
919
+ hash ^= seedText.charCodeAt(i);
920
+ hash = Math.imul(hash, 16777619);
921
+ }
922
+ hash ^= 0x9e3779b9;
923
+ hash = Math.imul(hash, 16777619);
924
+ }
925
+ for (let i = 0; i < text.length; i += 1) {
926
+ hash ^= text.charCodeAt(i);
927
+ hash = Math.imul(hash, 16777619);
928
+ }
929
+ return hash >>> 0;
930
+ }
931
+
932
+ function replaceRequired(source, pattern, replacement, label, expectedCount) {
933
+ const text = String(source);
934
+ const matches = text.match(pattern);
935
+ if (!matches || matches.length === 0) {
936
+ throw new Error(`rewriteNativeChunkSource: missing ${label}`);
937
+ }
938
+ if (expectedCount !== undefined && matches.length !== expectedCount) {
939
+ throw new Error(`rewriteNativeChunkSource: unexpected ${label} count ${matches.length}`);
940
+ }
941
+ return text.replace(pattern, replacement);
942
+ }
943
+
944
+ function parseScalar(value) {
945
+ const text = String(value ?? '').trim();
946
+ if (text === '') return '';
947
+ if (text === 'true') return true;
948
+ if (text === 'false') return false;
949
+ if (text === 'null' || text === '~') return null;
950
+ if (/^-?(?:0|[1-9]\d*)(?:\.\d+)?$/.test(text)) return Number(text);
951
+ if (
952
+ (text.startsWith('"') && text.endsWith('"')) ||
953
+ (text.startsWith("'") && text.endsWith("'"))
954
+ ) {
955
+ return text.slice(1, -1);
956
+ }
957
+ return text;
958
+ }
959
+
960
+ function parseInlineArray(value) {
961
+ const inner = String(value ?? '').trim().slice(1, -1).trim();
962
+ if (inner === '') return [];
963
+ const items = [];
964
+ let current = '';
965
+ let quote = null;
966
+
967
+ for (let i = 0; i < inner.length; i += 1) {
968
+ const ch = inner[i];
969
+ if (quote) {
970
+ if (ch === quote && inner[i - 1] !== '\\') quote = null;
971
+ current += ch;
972
+ continue;
973
+ }
974
+ if (ch === '"' || ch === "'") {
975
+ quote = ch;
976
+ current += ch;
977
+ continue;
978
+ }
979
+ if (ch === ',') {
980
+ items.push(parseScalar(current));
981
+ current = '';
982
+ continue;
983
+ }
984
+ current += ch;
985
+ }
986
+
987
+ if (current !== '') items.push(parseScalar(current));
988
+ return items;
989
+ }
990
+
991
+ function yamlParse(text) {
992
+ const source = String(text ?? '');
993
+ const result = {};
994
+ for (const rawLine of source.split(/\r?\n/)) {
995
+ const line = rawLine.trim();
996
+ if (!line || line.startsWith('#')) continue;
997
+ const idx = line.indexOf(':');
998
+ if (idx < 0) continue;
999
+ const key = line.slice(0, idx).trim();
1000
+ const rawValue = line.slice(idx + 1).trim();
1001
+ if (!key) continue;
1002
+ result[key] = rawValue.startsWith('[') && rawValue.endsWith(']')
1003
+ ? parseInlineArray(rawValue)
1004
+ : parseScalar(rawValue);
1005
+ }
1006
+ return result;
1007
+ }
1008
+
1009
+ function yamlStringify(value) {
1010
+ if (!value || typeof value !== 'object') return String(value ?? '');
1011
+ const lines = [];
1012
+ for (const [key, raw] of Object.entries(value)) {
1013
+ if (Array.isArray(raw)) {
1014
+ lines.push(`${key}: [${raw.map(item => JSON.stringify(String(item))).join(', ')}]`);
1015
+ } else if (raw === null) {
1016
+ lines.push(`${key}: null`);
1017
+ } else if (typeof raw === 'string') {
1018
+ lines.push(`${key}: ${JSON.stringify(raw)}`);
1019
+ } else {
1020
+ lines.push(`${key}: ${String(raw)}`);
1021
+ }
1022
+ }
1023
+ return lines.join('\n');
1024
+ }
1025
+
1026
+ function createYamlShim() {
1027
+ const yaml = {
1028
+ parse: yamlParse,
1029
+ stringify: yamlStringify,
1030
+ };
1031
+ yaml.YAML = yaml;
1032
+ yaml.default = yaml;
1033
+ return yaml;
1034
+ }
1035
+
1036
+ function createFakeRequire(realRequire) {
1037
+ const realChild = realRequire('child_process');
1038
+ const realVm = realRequire('vm');
1039
+
1040
+ function injectBunIntoContext(context) {
1041
+ if (!context || typeof context !== 'object') return context;
1042
+ try {
1043
+ if (!Object.prototype.hasOwnProperty.call(context, '__claudeYaml')) {
1044
+ Object.defineProperty(context, '__claudeYaml', {
1045
+ value: globalThis.__claudeYaml,
1046
+ configurable: true,
1047
+ writable: true,
1048
+ });
1049
+ }
1050
+ if (!Object.prototype.hasOwnProperty.call(context, '__claudeBunShim')) {
1051
+ Object.defineProperty(context, '__claudeBunShim', {
1052
+ value: globalThis.__claudeBunShim,
1053
+ configurable: true,
1054
+ writable: true,
1055
+ });
1056
+ }
1057
+ if (!Object.prototype.hasOwnProperty.call(context, '__claudeBun')) {
1058
+ Object.defineProperty(context, '__claudeBun', {
1059
+ value: globalThis.__claudeBunShim,
1060
+ configurable: true,
1061
+ writable: true,
1062
+ });
1063
+ }
1064
+ if (Object.prototype.hasOwnProperty.call(context, 'Bun')) {
1065
+ if (context.Bun && typeof context.Bun === 'object' && context.Bun !== globalThis.Bun) {
1066
+ try {
1067
+ context.Bun = globalThis.Bun;
1068
+ } catch {
1069
+ Object.defineProperty(context, 'Bun', {
1070
+ value: globalThis.Bun,
1071
+ configurable: true,
1072
+ writable: true,
1073
+ });
1074
+ }
1075
+ }
1076
+ if (!context.Bun || typeof context.Bun !== 'object') {
1077
+ Object.defineProperty(context, 'Bun', {
1078
+ value: globalThis.Bun,
1079
+ configurable: true,
1080
+ writable: true,
1081
+ });
1082
+ }
1083
+ } else {
1084
+ Object.defineProperty(context, 'Bun', {
1085
+ value: globalThis.Bun,
1086
+ configurable: true,
1087
+ writable: true,
1088
+ });
1089
+ }
1090
+ if (context.Bun && globalThis.__claudeYaml) {
1091
+ context.Bun.YAML = globalThis.__claudeYaml;
1092
+ }
1093
+ } catch {}
1094
+ return context;
1095
+ }
1096
+
1097
+ function rewriteArgs(args) {
1098
+ if (
1099
+ Array.isArray(args) &&
1100
+ args[0] === 'xdg-open' &&
1101
+ Array.isArray(args[1]) &&
1102
+ typeof args[1][0] === 'string'
1103
+ ) {
1104
+ return ['termux-open-url', [args[1][0]], ...args.slice(2)];
1105
+ }
1106
+ return args;
1107
+ }
1108
+
1109
+ const guardedChild = createGuardedChildProcess(
1110
+ {
1111
+ spawn: (...args) => realChild.spawn(...rewriteArgs(args)),
1112
+ execFile: (...args) => realChild.execFile(...args),
1113
+ exec: (...args) => realChild.exec(...args),
1114
+ spawnSync: (...args) => realChild.spawnSync(...rewriteArgs(args)),
1115
+ execFileSync: (...args) => realChild.execFileSync(...args),
1116
+ execSync: (...args) => realChild.execSync(...args),
1117
+ },
1118
+ value => process.stderr.write(value),
1119
+ );
1120
+
1121
+ return function fakeRequire(id) {
1122
+ if (id === 'ws') {
1123
+ class WS {
1124
+ on() {}
1125
+ once() {}
1126
+ addEventListener() {}
1127
+ close() {}
1128
+ send() {}
1129
+ ping() {}
1130
+ }
1131
+ return { default: WS, WebSocket: WS };
1132
+ }
1133
+
1134
+ if (id === 'vm' || id === 'node:vm') {
1135
+ if (!realVm.__claudeBunShimPatched) {
1136
+ const originalCreateContext = realVm.createContext.bind(realVm);
1137
+ const originalRunInNewContext = realVm.runInNewContext.bind(realVm);
1138
+ const originalRunInContext = realVm.runInContext.bind(realVm);
1139
+ const originalRunInThisContext = realVm.runInThisContext && realVm.runInThisContext.bind(realVm);
1140
+ const scriptProto = realVm.Script && realVm.Script.prototype;
1141
+
1142
+ realVm.createContext = (contextObject, ...rest) =>
1143
+ originalCreateContext(injectBunIntoContext(contextObject), ...rest);
1144
+ realVm.runInNewContext = (code, contextObject, ...rest) =>
1145
+ originalRunInNewContext(code, injectBunIntoContext(contextObject), ...rest);
1146
+ realVm.runInContext = (code, contextObject, ...rest) =>
1147
+ originalRunInContext(code, injectBunIntoContext(contextObject), ...rest);
1148
+ if (originalRunInThisContext) {
1149
+ realVm.runInThisContext = (code, ...rest) => originalRunInThisContext(code, ...rest);
1150
+ }
1151
+
1152
+ if (scriptProto && !scriptProto.__claudeBunShimPatched) {
1153
+ const originalScriptRunInContext = scriptProto.runInContext;
1154
+ const originalScriptRunInNewContext = scriptProto.runInNewContext;
1155
+ const originalScriptRunInThisContext = scriptProto.runInThisContext;
1156
+
1157
+ scriptProto.runInContext = function (contextObject, ...rest) {
1158
+ return originalScriptRunInContext.call(this, injectBunIntoContext(contextObject), ...rest);
1159
+ };
1160
+ scriptProto.runInNewContext = function (contextObject, ...rest) {
1161
+ return originalScriptRunInNewContext.call(this, injectBunIntoContext(contextObject), ...rest);
1162
+ };
1163
+ if (originalScriptRunInThisContext) {
1164
+ scriptProto.runInThisContext = function (...rest) {
1165
+ return originalScriptRunInThisContext.call(this, ...rest);
1166
+ };
1167
+ }
1168
+
1169
+ Object.defineProperty(scriptProto, '__claudeBunShimPatched', { value: true });
1170
+ }
1171
+
1172
+ Object.defineProperty(realVm, '__claudeBunShimPatched', { value: true });
1173
+ }
1174
+ return realVm;
1175
+ }
1176
+
1177
+ if (id === 'child_process') {
1178
+ return guardedChild;
1179
+ }
1180
+
1181
+ if (id === 'node:child_process') {
1182
+ return guardedChild;
1183
+ }
1184
+
1185
+ if (id.startsWith('/$bunfs/root/')) {
1186
+ throw new Error('bunfs require blocked: ' + id);
1187
+ }
1188
+
1189
+ return realRequire(id);
1190
+ };
1191
+ }
1192
+
1193
+ function rewriteNativeChunkSource(source) {
1194
+ const rawPrefix = 'function(exports, require, module, __filename, __dirname) {';
1195
+ const injectedPrefix = rawPrefix + 'var __claudeBun = globalThis.__claudeBunShim;';
1196
+ let patched = String(source);
1197
+ patched = replaceRequired(
1198
+ patched,
1199
+ /^function\(exports, require, module, __filename, __dirname\) \{(?:var __claudeBun = globalThis\.__claudeBunShim;)?/,
1200
+ injectedPrefix,
1201
+ 'module wrapper prefix',
1202
+ 1,
1203
+ );
1204
+ patched = replaceRequired(
1205
+ patched,
1206
+ /\btypeof Bun\b/g,
1207
+ 'typeof __claudeBun',
1208
+ 'typeof Bun',
1209
+ 3,
1210
+ );
1211
+ patched = replaceRequired(
1212
+ patched,
1213
+ /\btypeof globalThis\.Bun\b/g,
1214
+ 'typeof globalThis.__claudeBun',
1215
+ 'typeof globalThis.Bun',
1216
+ 1,
1217
+ );
1218
+ patched = replaceRequired(
1219
+ patched,
1220
+ /\bglobalThis\.Bun\b/g,
1221
+ 'globalThis.__claudeBun',
1222
+ 'globalThis.Bun',
1223
+ 1,
1224
+ );
1225
+ patched = replaceRequired(
1226
+ patched,
1227
+ /\bBun\./g,
1228
+ '__claudeBun.',
1229
+ 'Bun property access',
1230
+ 31,
1231
+ );
1232
+ return patched;
1233
+ }
1234
+
1235
+ async function main() {
1236
+ let extractedFile;
1237
+ extractedFile = ensureEntryFile();
1238
+ const code = fs.readFileSync(extractedFile, 'utf8');
1239
+ const patchedCode = rewriteNativeChunkSource(code);
1240
+ const fn = eval('(' + patchedCode.replace(/\)\s*$/, '') + ')');
1241
+
1242
+ const originalArgv = process.argv.slice();
1243
+ const originalExit = process.exit;
1244
+ const originalBun = process.versions.bun;
1245
+ const hadGlobalBun = Object.prototype.hasOwnProperty.call(globalThis, 'Bun');
1246
+ const originalGlobalBun = globalThis.Bun;
1247
+ const asyncErrors = [];
1248
+
1249
+ globalThis.__claudeYaml = createYamlShim();
1250
+ if (!globalThis.__claudeBunShim || typeof globalThis.__claudeBunShim !== 'object') {
1251
+ globalThis.__claudeBunShim = {};
1252
+ }
1253
+ const fakeRequire = createFakeRequire(require);
1254
+ function onAsyncError(error) {
1255
+ asyncErrors.push(error);
1256
+ }
1257
+
1258
+ try {
1259
+ process.once('uncaughtException', onAsyncError);
1260
+ process.once('unhandledRejection', onAsyncError);
1261
+ Object.defineProperty(process.versions, 'bun', { value: '1.1.8', configurable: true });
1262
+ const _realChild = require('child_process');
1263
+ globalThis.Bun = {
1264
+ version: '1.1.8',
1265
+ stringWidth,
1266
+ wrapAnsi,
1267
+ stripANSI,
1268
+ hash: stableHash,
1269
+ which: (cmd) => {
1270
+ try {
1271
+ return _realChild.execFileSync('which', [String(cmd)], { encoding: 'utf8' }).trim() || null;
1272
+ } catch { return null; }
1273
+ },
1274
+ semver: (() => {
1275
+ const _cmp = (a, b) => {
1276
+ const pa = String(a).replace(/[^0-9.]/g,'').split('.').map(Number);
1277
+ const pb = String(b).replace(/[^0-9.]/g,'').split('.').map(Number);
1278
+ for (let i = 0; i < 3; i++) { const d = (pa[i]||0)-(pb[i]||0); if (d) return d > 0 ? 1 : -1; }
1279
+ return 0;
1280
+ };
1281
+ const _satisfies = (ver, range) => {
1282
+ const s = String(range).trim();
1283
+ const m = s.match(/^([><=!]{1,2})\s*([\d]+(?:\.[\d]+){0,2})$/);
1284
+ if (m) {
1285
+ const op = m[1], c = _cmp(ver, m[2]);
1286
+ if (op === '>') return c > 0;
1287
+ if (op === '>=') return c >= 0;
1288
+ if (op === '<') return c < 0;
1289
+ if (op === '<=') return c <= 0;
1290
+ if (op === '=' || op === '==') return c === 0;
1291
+ if (op === '!=') return c !== 0;
1292
+ }
1293
+ if (/^[\d]+(?:\.[\d]+){0,2}$/.test(s)) return _cmp(ver, s) === 0;
1294
+ return false;
1295
+ };
1296
+ return {
1297
+ order: (a, b) => _cmp(a, b),
1298
+ compare: (a, b) => _cmp(a, b),
1299
+ satisfies: (ver, range) => _satisfies(ver, range),
1300
+ gt: (a, b) => _cmp(a, b) > 0,
1301
+ gte: (a, b) => _cmp(a, b) >= 0,
1302
+ lt: (a, b) => _cmp(a, b) < 0,
1303
+ lte: (a, b) => _cmp(a, b) <= 0,
1304
+ };
1305
+ })(),
1306
+ YAML: globalThis.__claudeYaml,
1307
+ };
1308
+ Object.assign(globalThis.__claudeBunShim, globalThis.Bun);
1309
+ if (typeof globalThis.__claudeBunShim.gc !== 'function') {
1310
+ globalThis.__claudeBunShim.gc = () => {};
1311
+ }
1312
+ globalThis.__claudeBun = globalThis.__claudeBunShim;
1313
+ globalThis.Bun = globalThis.__claudeBunShim;
1314
+ process.argv = ['node', extractedFile, ...argv];
1315
+ process.exit = code => {
1316
+ throw new RequestedExit(code);
1317
+ };
1318
+
1319
+ const moduleLike = { exports: {} };
1320
+ const maybePromise = fn(moduleLike.exports, fakeRequire, moduleLike, extractedFile, workdir);
1321
+ if (maybePromise && typeof maybePromise.then === 'function') await maybePromise;
1322
+ if (asyncErrors.length > 0) throw asyncErrors[0];
1323
+ } catch (error) {
1324
+ if (error instanceof RequestedExit) {
1325
+ process.exitCode = error.code;
1326
+ return;
1327
+ }
1328
+ throw error;
1329
+ } finally {
1330
+ process.removeListener('uncaughtException', onAsyncError);
1331
+ process.removeListener('unhandledRejection', onAsyncError);
1332
+ process.argv = originalArgv;
1333
+ process.exit = originalExit;
1334
+ process.once('exit', () => {
1335
+ if (extractedFile) {
1336
+ try {
1337
+ fs.rmSync(extractedFile, { force: true });
1338
+ } catch {}
1339
+ }
1340
+ try {
1341
+ if (originalBun === undefined) {
1342
+ delete process.versions.bun;
1343
+ } else {
1344
+ Object.defineProperty(process.versions, 'bun', { value: originalBun, configurable: true });
1345
+ }
1346
+ } catch {}
1347
+ delete globalThis.__claudeYaml;
1348
+ delete globalThis.__claudeBunShim;
1349
+ delete globalThis.__claudeBun;
1350
+ if (hadGlobalBun) globalThis.Bun = originalGlobalBun;
1351
+ else delete globalThis.Bun;
1352
+ });
1353
+ }
1354
+ }
1355
+
1356
+ main().catch(error => {
1357
+ if (error && error.code === 'CLAUDE_TERMUX_OFFICIAL_UPDATE_BLOCKED') {
1358
+ console.error(BLOCK_MESSAGE);
1359
+ process.exit(error.status || 1);
1360
+ }
1361
+ console.error(error && error.stack ? error.stack : String(error));
1362
+ process.exit(1);
1363
+ });
1364
+ NODE
1365
+ export CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC="${CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC:-1}"
1366
+ export ENABLE_CLAUDEAI_MCP_SERVERS="${ENABLE_CLAUDEAI_MCP_SERVERS:-0}"
1367
+ node "$_bootstrap" "$@"
1368
+ _status=$?
1369
+ rm -f "$_bootstrap"
1370
+ trap - EXIT HUP INT TERM
1371
+ exit "$_status"
1372
+ fi