jesseduffield/lazygit · error

CreatePipe (in): %w

Error message

CreatePipe (in): %w

What it means

StartPty on Windows first creates the child-stdin pipe via CreatePipe. If the syscall fails, this wrapped error is returned; the deferred cleanup only closes handles that were successfully created, so a failure here leaks nothing. It almost always reflects resource exhaustion rather than API misuse.

Source

Thrown at pkg/commands/oscommands/pty_windows.go:281

		}
	}
	if len(found) != 1 {
		return 0
	}
	h, err := windows.OpenProcess(windows.SYNCHRONIZE|windows.PROCESS_TERMINATE, false, found[0])
	if err != nil {
		return 0
	}
	return h
}

func StartPty(cmd *exec.Cmd, cols, rows uint16) (sp StartedPty, err error) {
	// Two pipes: one for the child's stdin (we never write to it, but ConPTY
	// needs a handle), one for the child's stdout/stderr multiplexed through
	// the pseudoconsole.
	var inRead, inWrite, outRead, outWrite windows.Handle
	if err = windows.CreatePipe(&inRead, &inWrite, nil, 0); err != nil {
		return StartedPty{}, fmt.Errorf("CreatePipe (in): %w", err)
	}
	defer func() {
		if err != nil {
			_ = windows.CloseHandle(inWrite)
		}
	}()
	if err = windows.CreatePipe(&outRead, &outWrite, nil, 0); err != nil {
		_ = windows.CloseHandle(inRead)
		return StartedPty{}, fmt.Errorf("CreatePipe (out): %w", err)
	}
	defer func() {
		if err != nil {
			_ = windows.CloseHandle(outRead)
		}
	}()

	// CreatePseudoConsole dupes the handles it needs internally; we release
	// our references to the child-side ends immediately after.

View on GitHub (pinned to c477a2959b)

Solutions

  1. Close other running interactive commands/processes and retry to free handles.
  2. Restart lazygit if the session accumulated leaked handles (e.g. after crashes of spawned commands).
  3. If persistent, check the machine's handle limits / antivirus interference with pipe creation.
  4. As a workaround, use lazygit's non-PTY command running where the feature allows.
Defensive patterns

Strategy: fallback

Try / catch

sp, err := oscommands.StartPty(cmd, cols, rows)
if err != nil {
    if strings.Contains(err.Error(), "CreatePipe") {
        // resource exhaustion: degrade to plain pipes instead of a PTY
        return cmd.StdoutPipe()
    }
    return err
}

Prevention

When it happens

Trigger: windows.CreatePipe returning an error: handle/memory exhaustion (no free handles), restrictive job limits on the lazygit process, or kernel resource pressure while spawning many interactive commands.

Common situations: Running many PTY-backed commands (interactive shells in lazygit) concurrently for long sessions; sandboxed/CI environments capping handle counts; heavy system load.

Related errors


AI-assisted analysis of jesseduffield/lazygit@c477a2959b (2026-08-15). Data as JSON: /api/errors/4cdd6af3e85f2871. Report an issue: GitHub.