MCPcopy Create free account
hub / github.com/T-Lab-CUHKSZ/claude-code / isBeingDebugged

Function isBeingDebugged

src/main.tsx:245–276  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

243
244// Check if running in debug/inspection mode
245function isBeingDebugged() {
246 const isBun = isRunningWithBun();
247
248 // Check for inspect flags in process arguments (including all variants)
249 const hasInspectArg = process.execArgv.some(arg => {
250 if (isBun) {
251 // Note: Bun has an issue with single-file executables where application arguments
252 // from process.argv leak into process.execArgv (similar to https://github.com/oven-sh/bun/issues/11673)
253 // This breaks use of --debug mode if we omit this branch
254 // We're fine to skip that check, because Bun doesn't support Node.js legacy --debug or --debug-brk flags
255 return /--inspect(-brk)?/.test(arg);
256 } else {
257 // In Node.js, check for both --inspect and legacy --debug flags
258 return /--inspect(-brk)?|--debug(-brk)?/.test(arg);
259 }
260 });
261
262 // Check if NODE_OPTIONS contains inspect flags
263 const hasInspectEnv = process.env.NODE_OPTIONS && /--inspect(-brk)?|--debug(-brk)?/.test(process.env.NODE_OPTIONS);
264
265 // Check if inspector is available and active (indicates debugging)
266 try {
267 // Dynamic import would be better but is async - use global object instead
268 // eslint-disable-next-line @typescript-eslint/no-explicit-any
269 const inspector = (global as any).require('inspector');
270 const hasInspectorUrl = !!inspector.url();
271 return hasInspectorUrl || hasInspectArg || hasInspectEnv;
272 } catch {
273 // Ignore error and fall back to argument detection
274 return hasInspectArg || hasInspectEnv;
275 }
276}
277
278// Exit if we detect node debugging or inspection
279if ("external" !== 'ant' && isBeingDebugged()) {

Callers 1

main.tsxFile · 0.85

Calls 1

isRunningWithBunFunction · 0.85

Tested by

no test coverage detected