Problem
When running coder support bundle inside a running workspace without passing the [owner/workspace] argument, the resulting bundle is missing critical workspace-specific information:
- No workspace metadata
- No agent logs (startup logs, connected agent info)
- No connection diagnostics (DERP, agent dial)
- No build logs or template version info
The command currently warns:
Running inside Coder workspace; this can affect results!
No workspace specified. This will result in incomplete information.
...but does not use the readily available environment variables to auto-detect the current workspace.
Current Behavior
The command at cli/support.go already detects it is running inside a workspace via os.LookupEnv("CODER") (line 131), but only emits a warning. When no args are given, wsID and agtID remain uuid.Nil, causing WorkspaceInfo() and AgentInfo() in support/support.go to bail out early (lines 450, 543).
Available Environment Variables
The Coder agent sets these env vars inside every workspace (see agent/agent.go:1547-1549):
| Variable |
Example Value |
CODER_WORKSPACE_NAME |
my-workspace |
CODER_WORKSPACE_OWNER_NAME |
johndoe |
CODER_WORKSPACE_AGENT_NAME |
main |
These are already used elsewhere in the CLI (e.g., cli/open.go:68 builds inWorkspaceName from them).
Proposed Solution
When no workspace argument is provided and CODER=true, default the workspace and agent from environment variables:
if len(inv.Args) == 0 {
if val, found := os.LookupEnv("CODER"); found && val == "true" {
wsName := os.Getenv("CODER_WORKSPACE_NAME")
wsOwner := os.Getenv("CODER_WORKSPACE_OWNER_NAME")
agentName := os.Getenv("CODER_WORKSPACE_AGENT_NAME")
if wsName != "" && wsOwner != "" {
cliui.Info(inv.Stderr, "Detected workspace from environment: "+wsOwner+"/"+wsName)
// Use wsOwner/wsName to resolve workspace, agentName to resolve agent
}
}
}
This keeps the explicit argument as the primary path and only falls back to auto-detection when inside a workspace with no args.
Additional Notes
- The
Use string says bundle <workspace> [<agent>] (angle brackets imply required), but RequireRangeArgs(0, 2) allows 0 args. The usage string could be updated to bundle [<workspace>] [<agent>] to reflect the actual optionality.
- No other CLI commands (
ssh, ping, speedtest) auto-detect from env vars today, but the support bundle is a particularly good candidate since it is a diagnostic tool often run from within a broken workspace.
Note: This issue was created with the assistance of Coder Agents.
Problem
When running
coder support bundleinside a running workspace without passing the[owner/workspace]argument, the resulting bundle is missing critical workspace-specific information:The command currently warns:
...but does not use the readily available environment variables to auto-detect the current workspace.
Current Behavior
The command at
cli/support.goalready detects it is running inside a workspace viaos.LookupEnv("CODER")(line 131), but only emits a warning. When no args are given,wsIDandagtIDremainuuid.Nil, causingWorkspaceInfo()andAgentInfo()insupport/support.goto bail out early (lines 450, 543).Available Environment Variables
The Coder agent sets these env vars inside every workspace (see
agent/agent.go:1547-1549):CODER_WORKSPACE_NAMEmy-workspaceCODER_WORKSPACE_OWNER_NAMEjohndoeCODER_WORKSPACE_AGENT_NAMEmainThese are already used elsewhere in the CLI (e.g.,
cli/open.go:68buildsinWorkspaceNamefrom them).Proposed Solution
When no workspace argument is provided and
CODER=true, default the workspace and agent from environment variables:This keeps the explicit argument as the primary path and only falls back to auto-detection when inside a workspace with no args.
Additional Notes
Usestring saysbundle <workspace> [<agent>](angle brackets imply required), butRequireRangeArgs(0, 2)allows 0 args. The usage string could be updated tobundle [<workspace>] [<agent>]to reflect the actual optionality.ssh,ping,speedtest) auto-detect from env vars today, but the support bundle is a particularly good candidate since it is a diagnostic tool often run from within a broken workspace.