charmbracelet/crush · error
cannot reload: working directory not set
Error message
cannot reload: working directory not set
What it means
ReloadFromDisk re-runs the whole config load/merge flow against the store's workingDir. If the store was constructed without a working directory, there is no path to look config files up from, so it refuses immediately with this error before taking the write lock.
Source
Thrown at internal/config/store.go:1168
}
slices.Sort(s.trackedConfigPaths)
// Capture initial snapshots
s.RefreshStalenessSnapshot()
}
// captureStalenessSnapshot is an alias for CaptureStalenessSnapshot for internal use.
func (s *ConfigStore) captureStalenessSnapshot(paths []string) {
s.CaptureStalenessSnapshot(paths)
}
// ReloadFromDisk re-runs the config load/merge flow and updates the in-memory
// config atomically. It rebuilds the staleness snapshot after successful reload.
// On failure, the store state is rolled back to its previous state.
// Concurrent calls are serialised via writeMu.
func (s *ConfigStore) ReloadFromDisk(ctx context.Context) error {
if s.workingDir == "" {
return fmt.Errorf("cannot reload: working directory not set")
}
s.writeMu.Lock()
defer s.writeMu.Unlock()
return s.reloadFromDiskLocked(ctx)
}
// reloadFromDiskLocked performs the actual reload. Caller must hold writeMu.
func (s *ConfigStore) reloadFromDiskLocked(ctx context.Context) error {
// Migrate deprecated disable_notifications before reloading config.
migrateDisableNotifications()
configPaths := lookupConfigs(s.workingDir)
cfg, loadedPaths, err := loadFromConfigPaths(ctx, configPaths)
if err != nil {
return fmt.Errorf("failed to reload config: %w", err)
}
// Apply defaults (using existing data directory if set)View on GitHub (pinned to 7944b8e522)
Solutions
- Construct the store with a valid working directory (the project cwd).
- Skip reload when workingDir is empty: guard the call site.
- Recreate the store with the proper constructor that captures the cwd.
Example fix
// before
store.ReloadFromDisk(ctx) // panics-free but errors: no workingDir
// after
if store.WorkingDir() != "" {
store.ReloadFromDisk(ctx)
} Defensive patterns
Strategy: type-guard
Validate before calling
if store.WorkingDir() == "" { store = NewConfigStore(cwd) } Type guard
func canReload(s *ConfigStore) bool { return s != nil && s.WorkingDir() != "" } Try / catch
if err := store.ReloadFromDisk(ctx); err != nil && strings.Contains(err.Error(), "working directory not set") {
store = NewConfigStore(os.Getenv("PWD"))
} Prevention
- Always construct the store via its constructor with cwd
- Skip reload paths in embedded/test contexts without a cwd
When it happens
Trigger: Calling ConfigStore.ReloadFromDisk(ctx) on a store created with an empty workingDir — e.g. a store built programmatically in tests or via an API path that did not pass the cwd.
Common situations: Embedding the config store in another tool without wiring the working directory; test fixtures that build a bare ConfigStore{}.
Related errors
- failed to reload config: %w
- failed to load providers during reload: %w
- requested channels differ from the existing workspace; chann
- agent coordinator not initialized
- could not create request: %w
AI-assisted analysis of charmbracelet/crush@7944b8e522 (2026-08-29).
Data as JSON: /api/errors/6e9956296ea84aa6.
Report an issue: GitHub.