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 aliasString or symbolMeaning
DebugLogsDirEnvCLAUDE_CODE_DEBUG_LOGS_DIRDebug-log directory override.
DebugLogLevelEnvCLAUDE_CODE_DEBUG_LOG_LEVELDebug-log level override.
DebugFileFlagParser--debug-fileSpecific debug-log path flag parser.
DebugFilterFlag-d, --debug [filter]Debug mode with category filtering.
RootDebugFlag--debug [filter]Root debug flag/filter.
DoctorDiagnosticsScreen/doctor diagnostics screenInteractive diagnostics surface.
EventLoopStallDetectorstartEventLoopStallDetectorOptional event-loop stall diagnostic.
StartupProfilingMarkersimport_time, cli_entry, main_tsx_imports_loadedStartup profiling markers.
ShutdownErrorFlushCoordinatorrecordUncaughtAndCheckBreaker, gracefulShutdown, flushAnalyticsSinksError/crash recording and shutdown flush coordination.

Bundle modules in cli.renamed.js

Semantic aliasLoader line(s)Representative renamed exportsAtlas entry
SecretRedaction11510redact, redactObject, redactSensitiveKeys, redactedJsonPreview, stripUrlSecrets, scanBundle module map — observability and ops
StartupPerformanceProfiler12438profileReport, profileCheckpoint, logStartupPerf, isDetailedProfilingEnabled, getStartupPerfLogPathBundle module map — observability and ops
ProcessIoErrorHandlers11183, 11235writeToStdout, writeToStderr, registerProcessOutputErrorHandlers, peekForStdinData, exitWithError, setBgExitCause, readAndClearBgExitCauseBundle module map — observability and ops

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.