kovidgoyal/kitty · error
Failed to get the current working directory with error: %w
Error message
Failed to get the current working directory with error: %w
What it means
os.Getwd() failed while edit_in_kitty was building the environment payload (it embeds the current working directory for the editor session). Getwd fails when the CWD has been deleted or become unreadable — the kernel can no longer resolve '.' to a path.
Source
Thrown at tools/cmd/edit_in_kitty/main.go:217
data := strings.Builder{}
data.Grow(len(file_data) * 4)
add := func(key, val string) {
if data.Len() > 0 {
data.WriteString(",")
}
data.WriteString(key)
data.WriteString("=")
data.WriteString(val)
}
add_encoded := func(key, val string) { add(key, encode(val)) }
if unix.Access(path, unix.R_OK|unix.W_OK) != nil {
return 1, fmt.Errorf("%s is not readable and writeable", path)
}
cwd, err := os.Getwd()
if err != nil {
return 1, fmt.Errorf("Failed to get the current working directory with error: %w", err)
}
add_encoded("cwd", cwd)
for _, arg := range os.Args[2:] {
add_encoded("a", arg)
}
add("file_inode", fmt.Sprintf("%d:%d:%d", s.Dev, s.Ino, s.Mtim.Nano()))
add_encoded("file_data", utils.UnsafeBytesToString(file_data))
fmt.Println("Waiting for editing to be completed, press Esc to abort...")
write_data := func(data_type string, rdata []byte) (err error) {
err = utils.AtomicWriteFile(path, bytes.NewReader(rdata), fs.FileMode(s.Mode).Perm())
if err != nil {
err = fmt.Errorf("Failed to write data to %s with error: %w", path, err)
}
return
}
exit_code, err = edit_loop(data.String(), true, write_data)
if err != nil {
if err == tui.Canceled {View on GitHub (pinned to 6d5d0c4406)
Solutions
- cd to a valid directory (e.g. cd ~ or cd /) before retrying
- Recreate the deleted directory if the shell must stay there: mkdir -p <old-cwd>
- Avoid launching editors from long-lived shells in temp dirs that get cleaned up
- If a mount vanished, remount it or cd out of it
Example fix
# before (shell sits in a deleted dir) edit-in-kitty notes.txt # getwd ENOENT # after cd ~ && edit-in-kitty /path/to/notes.txt
Defensive patterns
Strategy: fallback
Validate before calling
// Verify CWD is resolvable before launching the editor
if wd, err := os.Getwd(); err != nil {
fmt.Fprintln(os.Stderr, "CWD lost; cd to a valid directory first")
os.Chdir(os.Getenv("HOME")) // recover into a known-good dir
} Try / catch
if err != nil && strings.Contains(err.Error(), "Failed to get the current working directory") {
os.Chdir("/")
// retry with an absolute file path Prevention
- cd out of temp/project dirs before they're cleaned up
- Pass absolute file paths so a lost CWD never corrupts the edit target
- Scripts should os.Chdir to a stable dir before spawning editors
When it happens
Trigger: Running edit_in_kitty from a directory that was deleted (rm -rf by another process) or whose permissions no longer allow traversal, or from inside a mount point that vanished. Also possible when PWD env is stale and the fallback syscall fails with ENOENT/EACCES.
Common situations: Shell sitting in a removed temp/project dir (common after a build script cleans up), deleted container overlay dirs, or unmounted FUSE mounts that were the CWD.
Related errors
- Failed to open %s for reading with error: %w
- Failed to stat %s with error: %w
- Failed to read from %s with error: %w
- %s is not readable and writeable
- resolving base symlinks: %w
AI-assisted analysis of kovidgoyal/kitty@6d5d0c4406 (2026-08-27).
Data as JSON: /api/errors/6be9fc8b2854f899.
Report an issue: GitHub.