@@ -416,6 +416,14 @@ func connectToServer(cmd *cobra.Command) (*client.Client, *proto.Workspace, func
416416// version matches the client; on mismatch it shuts down the old server
417417// and starts a fresh one.
418418func ensureServer(cmd *cobra.Command, hostURL *url.URL) error {
419+ // Initialize the persistent log here so stale-socket diagnostics
420+ // emitted before connectToServer runs are captured in the per-host
421+ // server log file. crushlog.Setup uses sync.Once internally, so the
422+ // later call from connectToServer becomes a no-op.
423+ debug, _ := cmd.Flags().GetBool("debug")
424+ logFile := filepath.Join(config.GlobalCacheDir(), "server-"+safeHostName(hostURL), "crush.log")
425+ crushlog.Setup(logFile, debug)
426+
419427 switch hostURL.Scheme {
420428 case "unix", "npipe":
421429 needsStart := false