From c77c0fce524a62f34c50d2f6c1d3350d1fc050d9 Mon Sep 17 00:00:00 2001 From: Danielle Maywood Date: Wed, 7 Jan 2026 16:06:00 +0000 Subject: [PATCH] fix(cli/open): wait for agent to be created (#21448) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix https://github.com/coder/internal/issues/596 --- 🤖 Claude Code with Claude Opus 4.5 --- cli/open.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/cli/open.go b/cli/open.go index 89e30e4c6d..192695d415 100644 --- a/cli/open.go +++ b/cli/open.go @@ -169,8 +169,8 @@ func (r *RootCmd) openVSCode() *serpent.Command { // Note that this is irrelevant for devcontainer sub agents, as // they always have a directory set. if workspaceAgent.Directory != "" { - workspace, workspaceAgent, err = waitForAgentCond(ctx, client, workspace, workspaceAgent, func(_ codersdk.WorkspaceAgent) bool { - return workspaceAgent.LifecycleState != codersdk.WorkspaceAgentLifecycleCreated + workspace, workspaceAgent, err = waitForAgentCond(ctx, client, workspace, workspaceAgent, func(wa codersdk.WorkspaceAgent) bool { + return wa.LifecycleState != codersdk.WorkspaceAgentLifecycleCreated }) if err != nil { return xerrors.Errorf("wait for agent: %w", err) @@ -183,7 +183,13 @@ func (r *RootCmd) openVSCode() *serpent.Command { directory = inv.Args[1] } - directory, err = resolveAgentAbsPath(workspaceAgent.ExpandedDirectory, directory, workspaceAgent.OperatingSystem, insideThisWorkspace) + // If we're opening into a dev container, we should use the directory of the dev container. + workingDirectory := workspaceAgent.ExpandedDirectory + if workingDirectory == "" && devcontainer.Agent != nil { + workingDirectory = devcontainer.Agent.Directory + } + + directory, err = resolveAgentAbsPath(workingDirectory, directory, workspaceAgent.OperatingSystem, insideThisWorkspace) if err != nil { return xerrors.Errorf("resolve agent path: %w", err) }