charmbracelet/crush · error
failed to check project init: status code %d
Error message
failed to check project init: status code %d
What it means
ProjectNeedsInitialization only treats HTTP 200 as success; any other status yields this error. The server was reached but rejected the needs-init query, so the client cannot report initialization state.
Source
Thrown at internal/client/config.go:174
return fmt.Errorf("failed to refresh OAuth token: %w", err)
}
defer rsp.Body.Close()
if rsp.StatusCode != http.StatusOK {
return fmt.Errorf("failed to refresh OAuth token: status code %d", rsp.StatusCode)
}
return nil
}
// ProjectNeedsInitialization checks if the project needs
// initialization.
func (c *Client) ProjectNeedsInitialization(ctx context.Context, id string) (bool, error) {
rsp, err := c.get(ctx, fmt.Sprintf("/workspaces/%s/project/needs-init", id), nil, nil)
if err != nil {
return false, fmt.Errorf("failed to check project init: %w", err)
}
defer rsp.Body.Close()
if rsp.StatusCode != http.StatusOK {
return false, fmt.Errorf("failed to check project init: status code %d", rsp.StatusCode)
}
var result struct {
NeedsInit bool `json:"needs_init"`
}
if err := json.NewDecoder(rsp.Body).Decode(&result); err != nil {
return false, fmt.Errorf("failed to decode project init response: %w", err)
}
return result.NeedsInit, nil
}
// MarkProjectInitialized marks the project as initialized on the
// server.
func (c *Client) MarkProjectInitialized(ctx context.Context, id string) error {
rsp, err := c.post(ctx, fmt.Sprintf("/workspaces/%s/project/init", id), nil, nil, nil)
if err != nil {
return fmt.Errorf("failed to mark project initialized: %w", err)
}
defer rsp.Body.Close()View on GitHub (pinned to 7944b8e522)
Solutions
- Check the numeric status in the message: 401/403 means re-authenticate, 404 means the workspace id is wrong or deleted
- Verify the workspace was created and the id is current
- Check server logs and health for 5xx before retrying
- Refresh the client's credentials if auth recently expired
Example fix
// before
needsInit, err := client.ProjectNeedsInitialization(ctx, id)
if err != nil {
return err
}
// after
needsInit, err := client.ProjectNeedsInitialization(ctx, id)
if err != nil {
if strings.Contains(err.Error(), "status code 404") {
return ErrWorkspaceNotFound
}
return err
} Defensive patterns
Strategy: try-catch
Validate before calling
// Validate the workspace exists first
workspaces, err := client.ListWorkspaces(ctx)
if err != nil {
return err
}
exists := false
for _, w := range workspaces {
if w.ID == id {
exists = true
}
}
if !exists {
return fmt.Errorf("workspace %s does not exist", id)
} Type guard
func isStatusError(err error, code int) bool {
return err != nil && strings.Contains(err.Error(), fmt.Sprintf("status code %d", code))
} Try / catch
needsInit, err := c.ProjectNeedsInitialization(ctx, id)
if err != nil {
if isStatusError(err, 404) {
return ErrWorkspaceNotFound
}
if isStatusError(err, 401) {
return reauthenticateAndRetry(ctx)
}
return err
} Prevention
- Refresh auth tokens before they expire to avoid 401/403 on bootstrap checks
- Validate workspace ids against a list call before status queries
- Do not blanket-retry 4xx statuses; only retry 429/5xx
- Keep client and server versions aligned on the needs-init endpoint
When it happens
Trigger: Calling ProjectNeedsInitialization and the server returns non-200: 401/403 for unauthorized workspace access, 404 when the workspace id does not exist, or 5xx server error.
Common situations: Stale workspace id after the server database was reset; expired auth token in the client; querying a workspace deleted by another user; server regression deploying a broken needs-init endpoint.
Related errors
- failed to get init prompt: status code %d
- failed to refresh OAuth token: status code %d
- failed to check project init: %w
- failed to mark project initialized: %w
- failed to mark project initialized: status code %d
AI-assisted analysis of charmbracelet/crush@7944b8e522 (2026-08-29).
Data as JSON: /api/errors/fd21a65206db7cba.
Report an issue: GitHub.