chenhg5/cc-connect · error

cannot detect working directory: %w

Error message

cannot detect working directory: %w

What it means

daemon.Resolve defaults cfg.WorkDir to the current working directory via os.Getwd(). This error is returned when Getwd fails — typically because the current directory has been deleted or the process has no readable path to it.

Source

Thrown at daemon/manager.go:135

	return time.Now().Format(time.RFC3339)
}

func Resolve(cfg *Config) error {
	if cfg.BinaryPath == "" {
		exe, err := os.Executable()
		if err != nil {
			return fmt.Errorf("cannot detect binary path: %w", err)
		}
		real, err := filepath.EvalSymlinks(exe)
		if err == nil {
			exe = real
		}
		cfg.BinaryPath = exe
	}
	if cfg.WorkDir == "" {
		wd, err := os.Getwd()
		if err != nil {
			return fmt.Errorf("cannot detect working directory: %w", err)
		}
		cfg.WorkDir = wd
	}
	if cfg.LogFile == "" {
		cfg.LogFile = DefaultLogFile()
	}
	if cfg.LogMaxSize <= 0 {
		cfg.LogMaxSize = DefaultLogMaxSize
	}
	if cfg.LogMaxBackups < 1 {
		cfg.LogMaxBackups = DefaultLogMaxBackups
	}
	if cfg.EnvPATH == "" {
		cfg.EnvPATH = os.Getenv("PATH")
	}
	if len(cfg.EnvExtra) == 0 {
		cfg.EnvExtra = captureDaemonEnv(cfg.NoCaptureSecrets)
		if !cfg.NoCaptureSecrets {

View on GitHub (pinned to 4000b2338a)

Solutions

  1. cd to an existing directory (e.g. your home dir) and re-run the install command.
  2. Set WorkDir explicitly in the daemon Config instead of relying on the default.
  3. Recreate the deleted directory, or restart the shell so it lands in a valid cwd.

Example fix

// before (shell sitting in a deleted dir)
$ cc-connect daemon install   # error: cannot detect working directory
// after
$ cd ~ && cc-connect daemon install
Defensive patterns

Strategy: fallback

Validate before calling

if wd, err := os.Getwd(); err != nil {
    return fmt.Errorf("current directory invalid (%v); cd to an existing dir or set WorkDir", err)
}

Try / catch

if err := daemon.Resolve(cfg); err != nil {
    if strings.Contains(err.Error(), "cannot detect working directory") {
        home, _ := os.UserHomeDir()
        cfg.WorkDir = home // explicit fallback
        err = daemon.Resolve(cfg)
    }
    if err != nil { return err }
}

Prevention

When it happens

Trigger: Calling Resolve with an empty WorkDir while the process's working directory was removed (e.g. the parent dir was deleted while the shell sat in it), or when permission changes make the cwd path unresolvable.

Common situations: Running `cc-connect daemon install` from a directory that was deleted or renamed in another terminal; running from a temp dir that got cleaned up; restricted sandbox losing access to cwd.

Related errors


AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06). Data as JSON: /api/errors/dfc03bdd8717c48e. Report an issue: GitHub.