Devcontainer re-build every laptop sleep

Problem

In VS Code the dev container can live for weeks. Each laptop sleep cycle does not cause a re-build of the container. It seems like the docker container continues running and VS Code simple re-attaches to the running container.

The specific problem with calling devcontainer up is twofold:

  1. This causes an image re-build which is slow (even with caching).
  2. This calls the initializeCommand which for our use case calls an interactive browser-based signin. This causes timeout failures and eventual errors.

Asking Claude to investigate the logs came up with the following details for what it thinks is wrong:
Cursor incorrectly calls devcontainer up even when reconnecting to existing containers (Container is new: false), causing unnecessary re-execution of initializeCommand. This breaks workflows with interactive setup commands and differs from VS Code’s behavior.

Evidence

  1. Logs show: “Container is new: false” followed by “devcontainer up”
  2. VS Code documentation states it has separate “attach to existing container” behavior
  3. We use an interactive login for initializeCommand which fails during automatic reconnections

Expected Behavior (like VS Code)

  • Existing container → docker start <container> + direct connection
  • initializeCommand should only run during initial container creation
  • Process interruptions should only require reconnection, not full rebuild

Reference Implementation

VS Code’s Dev Containers extension correctly distinguishes between:

  1. Container creation (uses devcontainer up)
  2. Container reconnection (uses direct Docker attachment)

Hi @jlord_vectra, thank you for sharing this issue. We are looking into it.

Hi @jlord_vectra – I took a look at the behavior of vscode, and it appears that they always call devcontainer up and the initializeCommand, even when connecting to an already running container.

I would recommend making your initialize command idempotent – can you check to see if the token is valid before initializing the sign in flow?

However, devcontainer up should not build the container by default, if it already exists and is running. Could you share the logs from the “Remote - Dev Containers” output so we can take a closer look?

I think you are correct and the root of the problem is that cursor periodically calls devcontainer up. This then invokes initializeCommand. If the token is valid then it is fine, but if the token has expired (which happens every 8 hours) then it opens a browser window to sign in. If that times out then the process exits and cursor thinks the container has crashed.

Sadly, I don’t think I can get an idempotent command. We have internal customizations on the docker build which is why I use the initializeCommand. I do not want my build process to drift from the build process used in CI. Part of this build process is having a valid token for the container repository. I can only think of brittle ways to improve the initializeCommand that are likely to add headaches. The failure of a build of the devcontainer is a very bad user experience in vscode (I know that bad user experience is the upstream project). I am trying to make it so no other engineers need to deal with that.

I can’t figure out why vscode does not have this same behavior. There are several log filters in vscode and I don’t know which one to pick. It is difficult to determine where I would expect to see the behavior where it wakes from laptop sleep.

From running devcontainer up from the cli I can see that it does run the initializeCommand each time. I think this means that vscode would have the same issue if it was running the same command regularly. I assume that vs-code only runs devcontainer up the first time I use rebuild and re-open in container from the command palette or an equivalent command. After that I would assume they re-connect to the same container but I do not know how.

These vs-code logs look like it is losing connection and re-connecting to the container, but I cannot guarantee that they are the correct logs to indicate how it behaves differently:

2025-07-21 14:32:44.013 [info] [Window] Extension host (Remote) is responsive.
2025-07-21 14:44:48.830 [info] [Window] [remote-connection][ExtensionHost][aa7c4…][reconnect] received socket close event (wasClean: false, code: 1006, reason: ).
2025-07-21 14:44:48.832 [error] [Window] {"isTrusted":true}
2025-07-21 14:44:48.832 [info] [Window] [remote-connection][ExtensionHost][aa7c4…][reconnect] starting reconnecting loop. You can get more information with the trace log level.
2025-07-21 14:44:48.832 [info] [Window] [remote-connection][ExtensionHost][aa7c4…][reconnect] resolving connection...
2025-07-21 14:44:48.833 [info] [Window] [remote-connection][ExtensionHost][aa7c4…][reconnect] connecting to WebSocket(127.0.0.1:34855)...
2025-07-21 14:44:48.834 [info] [Window] Creating a socket (renderer-ExtensionHost-aa7c44ec-4ac6-4e88-8b63-9cf43fdfac41)...
2025-07-21 14:44:48.837 [info] [Window] [remote-connection][Management   ][550ab…][reconnect] received socket close event (wasClean: false, code: 1006, reason: ).
2025-07-21 14:44:48.837 [error] [Window] {"isTrusted":true}
2025-07-21 14:44:48.838 [info] [Window] [remote-connection][Management   ][550ab…][reconnect] starting reconnecting loop. You can get more information with the trace log level.
2025-07-21 14:44:48.850 [info] [Window] [remote-connection][Management   ][550ab…][reconnect] resolving connection...
2025-07-21 14:44:48.850 [info] [Window] Invoking resolveAuthority(dev-container)...
2025-07-21 14:44:48.850 [info] [Window] [LocalProcess0][resolveAuthority(dev-container,3)][0ms] obtaining proxy...
2025-07-21 14:44:48.850 [info] [Window] [LocalProcess0][resolveAuthority(dev-container,3)][1ms] invoking...
2025-07-21 14:44:49.145 [info] [Window] [LocalProcess0][resolveAuthority(dev-container,3)][297ms] returned WebSocket(127.0.0.1:34855)
2025-07-21 14:44:49.145 [info] [Window] resolveAuthority(dev-container) returned 'WebSocket(127.0.0.1:34855)' after 298 ms
2025-07-21 14:44:49.145 [info] [Window] [remote-connection][Management   ][550ab…][reconnect] connecting to WebSocket(127.0.0.1:34855)...
2025-07-21 14:44:49.145 [info] [Window] Creating a socket (renderer-Management-550abb4d-a70d-41e9-b6fa-7a98e9eacea6)...
2025-07-21 14:44:49.146 [info] [Window] Creating a socket (renderer-ExtensionHost-aa7c44ec-4ac6-4e88-8b63-9cf43fdfac41) returned an error after 312 ms.
2025-07-21 14:44:49.147 [error] [Window] CodeExpectedError: WebSocket close with status code 1006
    at WebSocket.<anonymous> (vscode-file://vscode-app/Applications/Visual%20Studio%20Code.app/Contents/Resources/app/out/vs/workbench/workbench.desktop.main.js:3360:91246)
2025-07-21 14:44:49.147 [error] [Window] [remote-connection][ExtensionHost][aa7c4…][reconnect][WebSocket(127.0.0.1:34855)] socketFactory.connect() failed or timed out. Error:
2025-07-21 14:44:49.147 [error] [Window] CodeExpectedError: WebSocket close with status code 1006
    at WebSocket.<anonymous> (vscode-file://vscode-app/Applications/Visual%20Studio%20Code.app/Contents/Resources/app/out/vs/workbench/workbench.desktop.main.js:3360:91246)
2025-07-21 14:44:49.147 [info] [Window] [remote-connection][ExtensionHost][aa7c4…][reconnect] A temporarily not available error occurred while trying to reconnect, will try again...
2025-07-21 14:44:49.147 [info] [Window] [remote-connection][ExtensionHost][aa7c4…][reconnect] waiting for 5 seconds before reconnecting...
2025-07-21 14:44:49.379 [info] [Window] Creating a socket (renderer-Management-550abb4d-a70d-41e9-b6fa-7a98e9eacea6) was successful after 233 ms.
2025-07-21 14:44:49.399 [info] [Window] [remote-connection][Management   ][550ab…][reconnect] reconnected!
2025-07-21 14:44:53.860 [info] [Window] Extension host (Remote) is unresponsive.
2025-07-21 14:44:54.866 [info] [Window] [remote-connection][ExtensionHost][aa7c4…][reconnect] resolving connection...
2025-07-21 14:44:54.866 [info] [Window] [remote-connection][ExtensionHost][aa7c4…][reconnect] connecting to WebSocket(127.0.0.1:34855)...
2025-07-21 14:44:54.866 [info] [Window] Creating a socket (renderer-ExtensionHost-aa7c44ec-4ac6-4e88-8b63-9cf43fdfac41)...
2025-07-21 14:44:55.012 [info] [Window] Creating a socket (renderer-ExtensionHost-aa7c44ec-4ac6-4e88-8b63-9cf43fdfac41) was successful after 146 ms.
2025-07-21 14:44:55.021 [info] [Window] [remote-connection][ExtensionHost][aa7c4…][reconnect] reconnected!
2025-07-21 14:44:55.040 [info] [Window] Extension host (Remote) is responsive.
2025-07-21 15:11:49.931 [info] [Window] Extension host (Remote) is unresponsive.
2025-07-21 15:12:36.119 [info] [Window] Extension host (Remote) is responsive.
2025-07-21 15:12:41.043 [info] [Window] Extension host (Remote) is unresponsive.
2025-07-21 15:13:43.169 [info] [Window] Extension host (Remote) is responsive.
2025-07-21 15:16:55.886 [info] [Window] Extension host (Remote) is unresponsive.
2025-07-21 15:34:16.591 [info] [Window] Extension host (Remote) is responsive.
2025-07-21 17:05:11.519 [info] [Window] Extension host (Remote) is unresponsive.
2025-07-21 17:22:49.437 [info] [Window] Extension host (Remote) is responsive.
2025-07-21 17:23:53.331 [info] [Window] Extension host (Remote) is unresponsive.
2025-07-21 17:41:28.601 [info] [Window] Extension host (Remote) is responsive.
2025-07-21 18:22:11.573 [info] [Window] Extension host (Remote) is unresponsive.
2025-07-21 18:39:54.153 [info] [Window] Extension host (Remote) is responsive.
2025-07-21 19:16:49.026 [info] [Window] Extension host (Remote) is unresponsive.
2025-07-21 19:17:29.112 [info] [Window] Extension host (Remote) is responsive.
2025-07-21 19:52:51.814 [info] [Window] Extension host (Remote) is unresponsive.
2025-07-21 19:53:37.927 [info] [Window] Extension host (Remote) is responsive.
2025-07-21 20:27:53.218 [info] [Window] Extension host (Remote) is unresponsive.
2025-07-21 20:44:17.105 [info] [Window] Extension host (Remote) is responsive.
2025-07-21 21:19:47.297 [info] [Window] Extension host (Remote) is unresponsive.
2025-07-21 21:20:30.388 [info] [Window] Extension host (Remote) is responsive.
2025-07-21 21:37:20.268 [info] [Window] Extension host (Remote) is unresponsive.
2025-07-21 21:53:40.562 [info] [Window] Extension host (Remote) is responsive.
2025-07-21 22:44:23.409 [info] [Window] Extension host (Remote) is unresponsive.
2025-07-21 23:01:03.325 [info] [Window] Extension host (Remote) is responsive.
2025-07-22 00:12:37.116 [info] [Window] Extension host (Remote) is unresponsive.
2025-07-22 00:13:33.400 [info] [Window] Extension host (Remote) is responsive.
2025-07-22 00:13:38.106 [info] [Window] Extension host (Remote) is unresponsive.
2025-07-22 00:14:33.145 [info] [Window] Extension host (Remote) is responsive.
2025-07-22 00:31:49.168 [info] [Window] Extension host (Remote) is unresponsive.
2025-07-22 00:32:45.192 [info] [Window] Extension host (Remote) is responsive.
2025-07-22 01:16:30.146 [info] [Window] Extension host (Remote) is unresponsive.
2025-07-22 01:17:26.178 [info] [Window] Extension host (Remote) is responsive.
2025-07-22 03:02:41.717 [info] [Window] Extension host (Remote) is unresponsive.
2025-07-22 03:19:05.178 [info] [Window] Extension host (Remote) is responsive.
2025-07-22 03:37:24.835 [info] [Window] Extension host (Remote) is unresponsive.
2025-07-22 03:53:25.058 [info] [Window] Extension host (Remote) is responsive.
2025-07-22 05:52:21.460 [info] [Window] Extension host (Remote) is unresponsive.
2025-07-22 05:53:17.492 [info] [Window] Extension host (Remote) is responsive.
2025-07-22 06:52:34.942 [info] [Window] Extension host (Remote) is unresponsive.
2025-07-22 06:53:13.024 [info] [Window] Extension host (Remote) is responsive.
2025-07-22 06:54:16.925 [info] [Window] Extension host (Remote) is unresponsive.
2025-07-22 06:55:13.012 [info] [Window] Extension host (Remote) is responsive.
2025-07-22 07:07:16.923 [info] [Window] Extension host (Remote) is unresponsive.
2025-07-22 07:08:12.946 [info] [Window] Extension host (Remote) is responsive.
2025-07-22 07:12:53.738 [info] [Window] [remote-connection][ExtensionHost][aa7c4…][reconnect] received socket close event (wasClean: false, code: 1006, reason: ).
2025-07-22 07:12:53.739 [error] [Window] {"isTrusted":true}
2025-07-22 07:12:53.739 [info] [Window] [remote-connection][ExtensionHost][aa7c4…][reconnect] starting reconnecting loop. You can get more information with the trace log level.
2025-07-22 07:12:53.739 [info] [Window] [remote-connection][ExtensionHost][aa7c4…][reconnect] resolving connection...
2025-07-22 07:12:53.739 [info] [Window] [remote-connection][ExtensionHost][aa7c4…][reconnect] connecting to WebSocket(127.0.0.1:34855)...
2025-07-22 07:12:53.740 [info] [Window] Creating a socket (renderer-ExtensionHost-aa7c44ec-4ac6-4e88-8b63-9cf43fdfac41)...
2025-07-22 07:12:53.750 [info] [Window] [remote-connection][Management   ][550ab…][reconnect] received socket close event (wasClean: false, code: 1006, reason: ).
2025-07-22 07:12:53.751 [error] [Window] {"isTrusted":true}
2025-07-22 07:12:53.751 [info] [Window] [remote-connection][Management   ][550ab…][reconnect] starting reconnecting loop. You can get more information with the trace log level.
2025-07-22 07:12:53.753 [info] [Window] [remote-connection][Management   ][550ab…][reconnect] resolving connection...
2025-07-22 07:12:53.753 [info] [Window] Invoking resolveAuthority(dev-container)...
2025-07-22 07:12:53.754 [info] [Window] [LocalProcess0][resolveAuthority(dev-container,4)][0ms] obtaining proxy...
2025-07-22 07:12:53.754 [info] [Window] [LocalProcess0][resolveAuthority(dev-container,4)][1ms] invoking...
2025-07-22 07:12:53.820 [info] [Window] [LocalProcess0][resolveAuthority(dev-container,4)][66ms] returned WebSocket(127.0.0.1:34855)
2025-07-22 07:12:53.820 [info] [Window] resolveAuthority(dev-container) returned 'WebSocket(127.0.0.1:34855)' after 67 ms
2025-07-22 07:12:53.820 [info] [Window] [remote-connection][Management   ][550ab…][reconnect] connecting to WebSocket(127.0.0.1:34855)...
2025-07-22 07:12:53.820 [info] [Window] Creating a socket (renderer-Management-550abb4d-a70d-41e9-b6fa-7a98e9eacea6)...
2025-07-22 07:12:53.821 [info] [Window] Creating a socket (renderer-ExtensionHost-aa7c44ec-4ac6-4e88-8b63-9cf43fdfac41) returned an error after 81 ms.
2025-07-22 07:12:53.822 [error] [Window] CodeExpectedError: WebSocket close with status code 1006
    at WebSocket.<anonymous> (vscode-file://vscode-app/Applications/Visual%20Studio%20Code.app/Contents/Resources/app/out/vs/workbench/workbench.desktop.main.js:3360:91246)
2025-07-22 07:12:53.822 [error] [Window] [remote-connection][ExtensionHost][aa7c4…][reconnect][WebSocket(127.0.0.1:34855)] socketFactory.connect() failed or timed out. Error:
2025-07-22 07:12:53.822 [error] [Window] CodeExpectedError: WebSocket close with status code 1006
    at WebSocket.<anonymous> (vscode-file://vscode-app/Applications/Visual%20Studio%20Code.app/Contents/Resources/app/out/vs/workbench/workbench.desktop.main.js:3360:91246)
2025-07-22 07:12:53.822 [info] [Window] [remote-connection][ExtensionHost][aa7c4…][reconnect] A temporarily not available error occurred while trying to reconnect, will try again...
2025-07-22 07:12:53.822 [info] [Window] [remote-connection][ExtensionHost][aa7c4…][reconnect] waiting for 5 seconds before reconnecting...
2025-07-22 07:12:53.948 [info] [Window] Creating a socket (renderer-Management-550abb4d-a70d-41e9-b6fa-7a98e9eacea6) was successful after 128 ms.
2025-07-22 07:12:53.961 [info] [Window] [remote-connection][Management   ][550ab…][reconnect] reconnected!
2025-07-22 07:12:56.915 [info] [Window] Extension host (Remote) is unresponsive.
2025-07-22 07:12:58.908 [info] [Window] [remote-connection][ExtensionHost][aa7c4…][reconnect] resolving connection...
2025-07-22 07:12:58.908 [info] [Window] [remote-connection][ExtensionHost][aa7c4…][reconnect] connecting to WebSocket(127.0.0.1:34855)...
2025-07-22 07:12:58.908 [info] [Window] Creating a socket (renderer-ExtensionHost-aa7c44ec-4ac6-4e88-8b63-9cf43fdfac41)...
2025-07-22 07:12:59.027 [info] [Window] Creating a socket (renderer-ExtensionHost-aa7c44ec-4ac6-4e88-8b63-9cf43fdfac41) was successful after 121 ms.
2025-07-22 07:12:59.036 [info] [Window] [remote-connection][ExtensionHost][aa7c4…][reconnect] reconnected!
2025-07-22 07:12:59.276 [info] [Window] Extension host (Remote) is responsive.

To be clear: I see the logs in cursor under “Remote - Dev Containers”. I just don’t see a similar set of logs for vscode. It looks like they don’t expose the logs from their own dev container extension in the same way. I don’t know if those logs exist or how to get them for vscode.