Skip to content

Diagnostics and debug logs

This page owns the diagnostics/debug-log side of the ops layer: debug flags, debug log files, startup profiling marks, event-loop stall diagnostics, crash/error reporting, and support-oriented local evidence.

Use Telemetry and tracing for traffic/telemetry/OTEL export behavior, Feature gates reference for GrowthBook and tengu_* feature gates, and Updater and doctor for the user-facing doctor and updater command paths.

Source anchors

Semantic aliasSourceApproximate locationString or symbolMeaning
DebugLogsDirEnvcli.jsline ~62, byte 0x311eaCLAUDE_CODE_DEBUG_LOGS_DIRDebug-log directory override.
DebugLogLevelEnvcli.jsline ~62, byte 0x31362CLAUDE_CODE_DEBUG_LOG_LEVELDebug-log level override.
DebugFileFlagParsercli.jsline ~62, byte 0x31599--debug-fileSpecific debug-log path flag parser.
DebugFilterFlagcli.jsline ~19525, byte 0xdbf757-d, --debug [filter]Debug mode with category filtering.
RootDebugFlagcli.jsline ~19525, byte 0xdbf764--debug [filter]Root debug flag/filter.
DoctorDiagnosticsScreencli.jsline ~605, byte 0x38fcfe/doctor diagnostics screenInteractive diagnostics surface.
EventLoopStallDetectorcli.jsline ~19294, byte 0xd9426astartEventLoopStallDetectorOptional event-loop stall diagnostic.
StartupProfilingMarkerscli.jsline ~64, byte 0x33865import_time, cli_entry, main_tsx_imports_loadedStartup profiling markers.
ShutdownErrorFlushCoordinatorcli.jsline ~1676, byte 0x4fb763recordUncaughtAndCheckBreaker, gracefulShutdown, flushAnalyticsSinksError/crash recording and shutdown flush coordination.

Diagnostic map

flowchart TD
Runtime[Claude Code runtime] --> DebugFlags[--debug / --debug-file]
Runtime --> StartupMarks[startup profiling marks]
Runtime --> Stall[event-loop stall detector]
Runtime --> Errors[uncaught/error reporter]
DebugFlags --> Logs[debug log files]
StartupMarks --> Logs
Stall --> Logs
Errors --> Logs
Logs --> Support[support/debug evidence]

Debug-log controls

SurfaceRuntime role
--debug [filter] / -dEnables debug logging, optionally filtered by categories such as api,hooks or negated filters.
--debug-to-stderr / -d2eSends debug logs to stderr instead of only file-backed output.
--debug-file <path>Writes debug logs to a specific file and implicitly enables debug mode.
DEBUG, DEBUG_SDKEnvironment switches that can also enable debug behavior in selected paths.
CLAUDE_CODE_DEBUG_LOGS_DIROverrides the default debug-log directory.
CLAUDE_CODE_DEBUG_LOG_LEVELSets the log-level threshold when recognized.
latest symlinkThe debug writer updates a latest symlink next to log files.

Startup and runtime diagnostics

Diagnostic familyEvidenceMeaning
Startup marksimport_time, cli_entry, main_tsx_imports_loaded, cli_before_main_importGives support a boot timeline before the main loop starts.
Event-loop stallsstartEventLoopStallDetectorAdds a runtime liveness diagnostic around bootstrap/session execution.
Doctor diagnostics screen/doctor diagnostics screenInteractive diagnostics entry; command-level ownership is in Updater and doctor.
Crash/error recordingrecordUncaughtAndCheckBreakerCentralizes uncaught exception/breaker classification before shutdown.
Shutdown flushgracefulShutdown, flushAnalyticsSinksGives logs/telemetry sinks a final best-effort drain.

Error reporting boundary

Error reporting is related to diagnostics but gated separately from debug logs. DISABLE_ERROR_REPORTING and traffic policy determine whether error reports are sent externally; local debug logs can still exist depending on debug settings. For the traffic and external sink behavior, see Telemetry and tracing.

Interpretation rules

  1. Treat debug logs as local support evidence, not as public API.
  2. Do not log credential/token values from env vars or settings.
  3. Keep debug-log controls here; keep traffic/telemetry/OTEL controls in Telemetry and tracing.
  4. Use Environment variables reference for canonical env-var names.

Created and maintained by Yingting Huang.