Skip to content

feat: add --quiet flag to coder ssh command #18883

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions cli/cliui/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type AgentOptions struct {
Fetch func(ctx context.Context, agentID uuid.UUID) (codersdk.WorkspaceAgent, error)
FetchLogs func(ctx context.Context, agentID uuid.UUID, after int64, follow bool) (<-chan []codersdk.WorkspaceAgentLog, io.Closer, error)
Wait bool // If true, wait for the agent to be ready (startup script).
Quiet bool // If true, suppress startup logs and connection indicators.
DocsURL string
}

Expand Down Expand Up @@ -103,6 +104,18 @@ func Agent(ctx context.Context, writer io.Writer, agentID uuid.UUID, opts AgentO
return errAgentShuttingDown
}

// In quiet mode, skip all logging and just wait for ready state
if opts.Quiet {
if agent.Status == codersdk.WorkspaceAgentConnected && agent.LifecycleState == codersdk.WorkspaceAgentLifecycleReady {
Copy link
Preview

Copilot AI Jul 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The quiet mode logic duplicates the ready state check that exists later in the function. Consider extracting this condition into a helper function or variable to avoid duplication.

Suggested change
if agent.Status == codersdk.WorkspaceAgentConnected && agent.LifecycleState == codersdk.WorkspaceAgentLifecycleReady {
if isAgentReady(agent) {

Copilot uses AI. Check for mistakes.

return nil
}
// Just fetch the next state without showing any output
if agent, err = fetch(); err != nil {
return xerrors.Errorf("fetch: %w", err)
}
continue
}

switch agent.Status {
case codersdk.WorkspaceAgentConnecting, codersdk.WorkspaceAgentTimeout:
// Since we were waiting for the agent to connect, also show
Expand Down
9 changes: 9 additions & 0 deletions cli/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func (r *RootCmd) ssh() *serpent.Command {
wsPollInterval time.Duration
waitEnum string
noWait bool
quiet bool
logDirPath string
remoteForwards []string
env []string
Expand Down Expand Up @@ -288,6 +289,7 @@ func (r *RootCmd) ssh() *serpent.Command {
Fetch: client.WorkspaceAgent,
FetchLogs: client.WorkspaceAgentLogsAfter,
Wait: wait,
Quiet: quiet,
DocsURL: appearanceConfig.DocsURL,
})
if err != nil {
Expand Down Expand Up @@ -670,6 +672,13 @@ func (r *RootCmd) ssh() *serpent.Command {
Value: serpent.BoolOf(&noWait),
UseInstead: []serpent.Option{waitOption},
},
{
Flag: "quiet",
FlagShorthand: "q",
Env: "CODER_SSH_QUIET",
Description: "Suppress machine setup logs and connection indicators.",
Value: serpent.BoolOf(&quiet),
},
{
Flag: "log-dir",
Description: "Specify the directory containing SSH diagnostic log files.",
Expand Down
Loading
Loading