multica-ai/multica · error

get working directory: %w

Error message

get working directory: %w

What it means

runRepoCheckout wraps the error from os.Getwd(), which it calls to pass the current working directory as the checkout target in the request body ("workdir" field). os.Getwd fails when the process's working directory has been deleted or the OS cannot determine it (permission loss on a parent directory, unlinked cwd).

Source

Thrown at server/cmd/multica/cmd_repo.go:350

	return nil
}

func runRepoCheckout(cmd *cobra.Command, args []string) error {
	repoURL := args[0]

	daemonPort := os.Getenv("MULTICA_DAEMON_PORT")
	if daemonPort == "" {
		return fmt.Errorf("MULTICA_DAEMON_PORT not set (this command is intended to be run by an agent inside a daemon task)")
	}

	workspaceID := os.Getenv("MULTICA_WORKSPACE_ID")
	agentName := os.Getenv("MULTICA_AGENT_NAME")
	taskID := os.Getenv("MULTICA_TASK_ID")

	// Use current working directory as the checkout target.
	workDir, err := os.Getwd()
	if err != nil {
		return fmt.Errorf("get working directory: %w", err)
	}

	reqBody := map[string]any{
		"url":           repoURL,
		"workspace_id":  workspaceID,
		"workdir":       workDir,
		"ref":           repoCheckoutRef,
		"agent_name":    agentName,
		"task_id":       taskID,
		"checkout_mode": strings.TrimSpace(os.Getenv("MULTICA_REPO_CHECKOUT_MODE")),
		"retry_busy":    true,
	}

	data, err := json.Marshal(reqBody)
	if err != nil {
		return fmt.Errorf("encode request: %w", err)
	}

View on GitHub (pinned to 2c0912b6ec)

Solutions

  1. cd into an existing directory before running the command (in shell: cd "$PWD" or cd /tmp first to force re-resolution).
  2. If an agent framework deleted the workdir, recreate it and restart the task.
  3. Check permissions on every parent of the intended workdir (need +x to traverse).

Example fix

# before: cwd was deleted
multica repo checkout https://github.com/acme/api

# after
mkdir -p /workspace && cd /workspace && multica repo checkout https://github.com/acme/api
Defensive patterns

Strategy: validation

Validate before calling

wd, err := os.Getwd()
if err != nil {
	// force re-anchoring to a known-good dir before continuing
	if err := os.Chdir(os.TempDir()); err != nil {
		return fmt.Errorf("recover working directory: %w", err)
	}
	wd, _ = os.Getwd()
}

Prevention

When it happens

Trigger: The shell or agent process is sitting in a directory that was deleted (common in CI cleanup steps or agents that rm -rf their workdir), or the path to cwd is no longer searchable/executable for the process.

Common situations: Agent tasks that delete and recreate their working directory while the CLI still runs from the old inode; containerized runs where the workdir was mounted over or removed; restricted environments revoking execute permission on a parent dir.

Related errors


AI-assisted analysis of multica-ai/multica@2c0912b6ec (2026-08-15). Data as JSON: /api/errors/da0e5adaa9ac3d5c. Report an issue: GitHub.