chenhg5/cc-connect · error
cannot create config directory: %w
Error message
cannot create config directory: %w
What it means
Windows build of AcquireInstanceLock: os.MkdirAll on the config directory failed, producing "cannot create config directory: %w" before any Win32 lock APIs are invoked. Causes are the usual Windows filesystem errors: access denied, path occupied by a file, invalid path characters, or read-only media.
Source
Thrown at cmd/cc-connect/instance_lock_windows.go:31
const killWaitTimeout = 5 * time.Second
const killWaitInterval = 25 * time.Millisecond
const processQueryLimitedInformation = 0x1000
type InstanceLock struct {
handle syscall.Handle
path string
acquired bool
}
func AcquireInstanceLock(configPath string) (*InstanceLock, error) {
configDir := filepath.Dir(configPath)
configBase := filepath.Base(configPath)
lockName := fmt.Sprintf(".%s.lock", configBase)
lockPath := filepath.Join(configDir, lockName)
if err := os.MkdirAll(configDir, 0755); err != nil {
return nil, fmt.Errorf("cannot create config directory: %w", err)
}
pathPtr, err := syscall.UTF16PtrFromString(lockPath)
if err != nil {
return nil, fmt.Errorf("cannot convert lock path: %w", err)
}
handle, createErr := syscall.CreateFile(
pathPtr,
syscall.GENERIC_READ|syscall.GENERIC_WRITE,
syscall.FILE_SHARE_READ,
nil,
syscall.OPEN_ALWAYS,
syscall.FILE_ATTRIBUTE_NORMAL,
0,
)
if createErr != nil {View on GitHub (pinned to 4000b2338a)
Solutions
- Move the config to a user-writable location (e.g. %APPDATA%\cc-connect\config.toml).
- Check ACLs on the parent directory (icacls <dir>) and grant the running user modify rights.
- Enable long-path support or shorten the path if MAX_PATH is exceeded.
- Check drive space and read-only attribute of the volume.
Defensive patterns
Strategy: validation
Validate before calling
dir := filepath.Dir(configPath)
if fi, err := os.Stat(dir); err == nil && !fi.IsDir() {
return fmt.Errorf("%s is a file", dir)
}
if err := os.MkdirAll(dir, 0755); err != nil {
return fmt.Errorf("config dir not creatable: %w", err)
} Try / catch
lock, err := AcquireInstanceLock(configPath)
if err != nil && strings.Contains(err.Error(), "cannot create config directory") {
slog.Error("Windows: check ACLs/path length/drive state", "dir", dir, "err", err)
os.Exit(1)
} Prevention
- Install configs under %APPDATA%, not Program Files.
- Keep paths under 260 chars or enable long paths (LongPathsEnabled).
- Grant the service account modify rights on the config directory.
When it happens
Trigger: Calling AcquireInstanceLock(configPath) on Windows where filepath.Dir(configPath) cannot be created: ACL denies write, a file exists at the directory path, path length limits (MAX_PATH) exceeded, or the drive is read-only/full.
Common situations: Config placed under C:\Program Files (needs admin), path > 260 characters, running as a service account without a writable profile directory, or OneDrive-synced folder locked.
Understand the failure class
Background: mkdir permission denied (EACCES): failed to create directory errors explained — this error's family across 32 libraries.
Related errors
- cannot create config directory: %w
- create data dir: %w
- codex: mkdir codex home: %w
- cannot open lock file: %w
- cannot read sessions directory %s: %w
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/5895d17bd5f960e6.
Report an issue: GitHub.