charmbracelet/crush · error
invalid host URL: %v
Error message
invalid host URL: %v
What it means
connectToServer in internal/cmd/root.go parses the --host flag via server.ParseHostURL before connecting to a running crush server. An unparseable host URL (missing scheme, invalid characters, malformed unix socket path) returns 'invalid host URL: %v', preventing any client/server connection.
Source
Thrown at internal/cmd/root.go:391
if protoWs.Config.IsConfigured() {
if err := clientWs.InitCoderAgent(cmd.Context()); err != nil {
slog.Error("Failed to initialize coder agent", "error", err)
}
}
// Clean up via Shutdown rather than connectToServer's closure: it stops
// the subscription's reconnect/recovery loop first, so our own exit
// cannot be mistaken for a lost workspace and re-created mid-quit.
return clientWs, clientWs.Shutdown, nil
}
// connectToServer ensures the server is running, creates a client and
// workspace, and returns a cleanup function that deletes the workspace.
func connectToServer(cmd *cobra.Command) (*client.Client, *proto.Workspace, func(), error) {
hostURL, err := server.ParseHostURL(clientHost)
if err != nil {
return nil, nil, nil, fmt.Errorf("invalid host URL: %v", err)
}
if err := ensureServer(cmd, hostURL); err != nil {
return nil, nil, nil, err
}
debug, _ := cmd.Flags().GetBool("debug")
yolo, _ := cmd.Flags().GetBool("yolo")
channels, _ := cmd.Flags().GetStringSlice("channels")
dataDir, _ := cmd.Flags().GetString("data-dir")
cwd, err := ResolveCwd(cmd)
if err != nil {
return nil, nil, nil, err
}
c, err := client.NewClient(cwd, hostURL.Scheme, hostURL.Host)
if err != nil {View on GitHub (pinned to 7944b8e522)
Solutions
- Prefix the host with a scheme: `--host http://localhost:8080` or `--host unix:///path/to/socket`
- Check the CRUSH_HOST/clientHost env var for typos or stray whitespace/quotes
- For IPv6 use bracketed form: http://[::1]:8080
- Omit --host entirely to use the default local socket
Example fix
// before crush --host localhost:3117 // after crush --host http://localhost:3117
Defensive patterns
Strategy: validation
Validate before calling
u, err := url.Parse(host)
if err != nil || (u.Scheme != "http" && u.Scheme != "https" && u.Scheme != "unix") {
return fmt.Errorf("host must be http(s):// or unix://, got %q", host)
} Try / catch
hostURL, err := server.ParseHostURL(clientHost)
if err != nil {
return fmt.Errorf("invalid host URL %q: %w", clientHost, err)
} Prevention
- Always include the scheme (http:// or unix://) in --host
- Quote the host value in shells to avoid stray characters
- Use bracketed IPv6 literals: http://[::1]:8080
When it happens
Trigger: Passing `--host` with a malformed value: e.g. `--host localhost:8080` without scheme, `--host 'http://:port'`, or an invalid unix:// path; CRUSH_HOST / clientHost set to a bad value in the environment.
Common situations: Copy-pasting a host string without `http://` or `unix://` prefix; quoting issues in shell causing stray characters; typo like `htp://`; IPv6 literal without brackets.
Related errors
- %s model: provider %q not found in configuration. Use 'crush
- %s model %q not found
- failed to get config: %w
- failed to load configuration: %v
- failed to override models: %w
AI-assisted analysis of charmbracelet/crush@7944b8e522 (2026-08-29).
Data as JSON: /api/errors/30636c1af8f3bc68.
Report an issue: GitHub.