[BUG] TypeError: undefined is not a constructor (evaluating 'new window.WebSocket') on macOS Homebrew installation
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
<img width="1512" height="430" alt="Image" src="https://github.com/user-attachments/assets/7f65f396-51f2-428b-b2e0-e9d5ddeaa2fe" /> ----
Claude Code Version: 2.0.55
Installation Method: Homebrew (brew install --cask claude-code)
OS: macOS (arm64)
Runtime: Bun v1.3.2
Description
Claude Code crashes immediately on launch with a WebSocket constructor error. The application attempts to use window.WebSocket which is undefined in the Node/Bun runtime environment.
Error Output
TypeError: undefined is not a constructor (evaluating 'new window.WebSocket(pG)')
at JB (/$bunfs/root/claude:799:20129)
at <anonymous> (/$bunfs/root/claude:799:22032)
at <anonymous> (/$bunfs/root/claude:11:522)
at <anonymous> (/$bunfs/root/claude:799:22443)
The error suggests the bundled code is trying to use browser-specific APIs (window.WebSocket) in a Node/Bun context
This appears to be a bundling/build issue specific to the Homebrew cask distribution
The code references React DevTools hooks, suggesting possible dev dependencies bundled in production
Installation Info
bash$ brew info claude-code
==> claude-code: 2.0.55
https://www.anthropic.com/claude-code
Installed
/opt/homebrew/Caskroom/claude-code/2.0.55 (168.8MB)
Installed using the formulae.brew.sh API on 2025-11-27 at 09:13:19
Attempted Fixes
Reinstalled via brew reinstall --cask claude-code - issue persists
Cleared all cache directories - issue persists
Ran brew doctor - no issues found
Possible Root Cause
The bundled binary appears to have browser-specific code that wasn't properly polyfilled or replaced for the Node/Bun runtime. The WebSocket constructor should likely be using the ws package or Bun's native WebSocket implementation instead of window.WebSocket.
What Should Happen?
Expected Behavior
Claude Code should launch successfully and display the welcome screen.
Actual Behavior
Application crashes with WebSocket constructor error, making it completely unusable.
Error Messages/Logs
CLAUDE
794 |
795 | `,V1),{type:"error",errorType:"uncaught",id:cR,responseID:kR,message:V1.message,stack:V1.stack}}if(s5===null)return{id:cR,responseID:kR,type:"not-found"};JXT(s5);var n0=rN({},s5);return n0.context=x2(n0.context,VU("context",null)),n0.hooks=x2(n0.hooks,VU("hooks","hooks")),n0.props=x2(n0.props,VU("props",null)),n0.state=x2(n0.state,VU("state",null)),{id:cR,responseID:kR,type:"full-data",value:n0}}function nUR(kR){var cR=CXT(kR)?s5:lUR(kR);if(cR===null){console.warn('Could not find Fiber with id "'.concat(kR,'"'));return}var JT=typeof console.groupCollapsed==="function";if(JT)console.groupCollapsed("[Click to expand] %c<".concat(cR.displayName||"Component"," />"),"color: var(--dom-tag-name-color); font-weight: normal;");if(cR.props!==null)console.log("Props:",cR.props);if(cR.state!==null)console.log("State:",cR.state);if(cR.hooks!==null)console.log("Hooks:",cR.hooks);var WT=gUR(kR);if(WT!==null)console.log("Nodes:",WT);if(cR.source!==null)console.log("Location:",cR.source);if(window.chrome||/firefox/i.test(navi | ... truncated
796 | In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function uv(j){if(typeof Symbol<"u"&&Symbol.iterator in Object(j))return Array.from(j)}function kAR(j){if(Array.isArray(j))return kL(j)}function cv(j,n){var r;if(typeof Symbol>"u"||j[Symbol.iterator]==null){if(Array.isArray(j)||(r=Vk(j))||n&&j&&typeof j.length==="number"){if(r)j=r;var HR=0,s=function(){};return{s,n:function(){if(HR>=j.length)return{done:!0};return{done:!1,value:j[HR++]}},e:function(_T){throw _T},f:s}}throw TypeError(`Invalid attempt to iterate non-iterable instance.
797 | In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var KR=!0,xR=!1,iR;return{s:function(){r=j[Symbol.iterator]()},n:function(){var _T=r.next();return KR=_T.done,_T},e:function(_T){xR=!0,iR=_T},f:function(){try{if(!KR&&r.return!=null)r.return()}finally{if(xR)throw iR}}}}function Vk(j,n){if(!j)return;if(typeof j==="string")return kL(j,n);var r=Object.prototype.toString.call(j).slice(8,-1);if(r==="Object"&&j.constructor)r=j.constructor.name;if(r==="Map"||r==="Set")return Array.from(j);if(r==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return kL(j,n)}function kL(j,n){if(n==null||n>j.length)n=j.length;for(var r=0,HR=Array(n);r<n;r++)HR[r]=j[r];return HR}var lv=["error","trace","warn"],ML="\x1B[2m%s\x1B[0m",qU=/\s{4}(in|at)\s{1}/,bn=/:\d+:\d+(\n|$)/;function jn(j){return qU.test(j)||bn.test(j)}var oN=/^%c/;function MAR(j,n){return j.length>=2&&oN.test(j[0])&&j[1]==="color: ".concat(pv(n)||"")}function pv(j){switch(j){case"warn":return Z4.browserTheme==="light"?" | ... truncated
798 | In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function eN(j,n){if(!j)return;if(typeof j==="string")return FX(j,n);var r=Object.prototype.toString.call(j).slice(8,-1);if(r==="Object"&&j.constructor)r=j.constructor.name;if(r==="Map"||r==="Set")return Array.from(j);if(r==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return FX(j,n)}function OU(j){if(typeof Symbol<"u"&&Symbol.iterator in Object(j))return Array.from(j)}function vn(j){if(Array.isArray(j))return FX(j)}function FX(j,n){if(n==null||n>j.length)n=j.length;for(var r=0,HR=Array(n);r<n;r++)HR[r]=j[r];return HR}function PD(j,n){if(!(j instanceof n))throw TypeError("Cannot call a class as a function")}function HK(j,n){for(var r=0;r<n.length;r++){var HR=n[r];if(HR.enumerable=HR.enumerable||!1,HR.configurable=!0,"value"in HR)HR.writable=!0;Object.defineProperty(j,HR.key,HR)}}function rv(j,n,r){if(n)HK(j.prototype,n);if(r)HK(j,r);return j}function GK(j,n){if(typeof n!=="function"&&n!==null)throw TypeError | ... truncated
799 | `),o0=q0.length>1?q0[1]:null;return o0}function X_(){return R8}function ID(TB){var q0=eH(TB);if(q0!==null)mD.push(q0)}function l_(TB){if(mD.length>0){var q0=mD.pop(),o0=eH(TB);if(o0!==null)R8.push([q0,o0])}}var jW={},Y4=new Map,r1={},EG=new Map,p_=new Map,j3={rendererInterfaces:Y4,listeners:r1,backends:p_,renderers:EG,emit:G1,getFiberRoots:dD,inject:jT,on:W0,off:g9,sub:O9,supportsFiber:!0,checkDCE:xR,onCommitFiberUnmount:EH,onCommitFiberRoot:UB,onPostCommitFiberRoot:HH,setStrictMode:pG,getInternalModuleRanges:X_,registerInternalModuleStart:ID,registerInternalModuleStop:l_};return Object.defineProperty(j,"__REACT_DEVTOOLS_GLOBAL_HOOK__",{configurable:!1,enumerable:!1,get:function(){return j3}}),j3}function sq(j,n,r){var HR=j[n];return j[n]=function(s){return r.call(this,HR,arguments)},HR}function h3R(j,n){var r={};for(var HR in n)r[HR]=sq(j,HR,n[HR]);return r}function r5(j,n){for(var r in n)j[r]=n[r]}function kI(j){if(typeof j.forceUpdate==="function")j.forceUpdate();else if(j.updater!=null&&typeof j.updater.e | ... truncated
TypeError: undefined is not a constructor (evaluating 'new window.WebSocket(pG)')
at JB (/$bunfs/root/claude:799:20129)
at <anonymous> (/$bunfs/root/claude:799:22032)
at <anonymous> (/$bunfs/root/claude:11:522)
at <anonymous> (/$bunfs/root/claude:799:22443)
╭─── Claude Code v2.0.55 ────────────────────────────────────────────────────────────────────────────────────────────────╮
│ │ Tips for getting started │
│ Welcome back! │ Run /init to create a CLAUDE.md file with instructions for Claude │
│ │ ───────────────────────────────────────────────────────────────── │
│ ▐▛███▜▌ │ Recent activity │
│ ▝▜█████▛▘ │ No recent activity │
│ ▘▘ ▝▝ │ │
│ │ │
│ global.anthropic.claude-opus-… · API Usage Billing │ │
│ ~/…/go api + react admin/kamero-backend-go-apis │ │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
/model to try Opus 4.5. Note: you may need to request access from your cloud provider
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
> Try "fix lint errors"
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
? for shortcuts Thinking off (tab to toggle)
Bun v1.3.2 (macOS arm64)
Steps to Reproduce
Steps to Reproduce
Install Claude Code via Homebrew: brew install --cask claude-code
Launch the application by running claude
Error occurs immediately on startup
Claude Model
Opus
Is this a regression?
Yes, this worked in a previous version
Last Working Version
_No response_
Claude Code Version
v1.3.2
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Terminal.app (macOS)
Additional Information
_No response_
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗