← Claude Code Hub
✦ Tip #224 Oct 10, 2026

"Premature close" in Claude Code: check for a missing git or gh first

"Premature close" in Claude Code usually hides a git or gh that isn't installed: up to 2.1.289 the error never said which. How to find it with one command, and when it really is the network.

"Premature close" in Claude Code: up to 2.1.289 the error says nothing; from 2.1.290 it names git. The fix: which git gh, install what is missing, claude update

TL;DR Run which git gh. If either comes back not found, install it and update Claude Code to 2.1.290 or later with claude update: from that version on, the error names the missing program. If "Premature close" shows up inside an API error, it's your connection, not git.

"Premature close" is the generic message of a stream that closes before it finishes. Up to 2.1.289, on macOS and Linux, Claude Code showed it when it tried to run a program that isn't installed, such as git or gh, instead of saying which one was missing. Version 2.1.290 fixed it on October 5, 2026:

Fixed errors reading "Premature close" instead of naming the missing program when a tool Claude Code runs, such as git or gh, is not installed (macOS, Linux)

Missing program or network: how to tell

  • It appears when Claude Code runs git or gh itself, for example when it creates a worktree with claude --worktree or talks to GitHub through gh. The program is almost certainly missing. Follow the steps below.
  • It appears inside an API or connection error. The same text shows up when the connection drops halfway through a response. git has nothing to do with it there: first check whether Claude Code is down or it's you.

How to fix it

1. Find the missing program

which git gh

With both installed, each one answers with its path:

/opt/homebrew/bin/git
/opt/homebrew/bin/gh

If one is missing, zsh says not found (bash prints nothing for it). This is the real output with both taken off the PATH:

git not found
gh not found

On macOS, /usr/bin/git exists even without Xcode's Command Line Tools. Check that git --version answers with a version number. If it offers to install the tools or errors out instead, install them with xcode-select --install.

2. Install what's missing

# macOS with Homebrew
brew install git gh

# Debian, Ubuntu
sudo apt install git

For gh on Linux, the GitHub CLI install guide has the repository for each distribution. If gh is new on your machine, sign in with gh auth login before going back to Claude Code.

3. Update Claude Code

claude update

From 2.1.290 on, if a program goes missing again, the error names it. I checked on 2.1.293: I took git off the PATH and ran claude --worktree in a repository. Instead of "Premature close", the output was:

Error creating worktree: Failed to resolve base branch "HEAD": git rev-parse failed

If claude update doesn't move you to a new version because you installed with Homebrew or npm, how to update Claude Code has the command for each case.

Official docs: Troubleshooting · Claude Code changelog, 2.1.290

Free guide

The 51 essentials, as a guide.

One page per tip. Five chapters. What I actually use daily in production. No theory, no fluff.

  • I. Getting started 10 tips
  • II. Awareness 3 tips
  • III. Mastery 22 tips
  • IV. Autonomy 10 tips
  • V. Comparison 6 tips
Are you a professional Web developer?

You'll receive the guide by email · You join the Gravitas newsletter · Unsubscribe anytime

of 51
#

Wmedia · 51 Tips
Free guide · 51 tips · 5 chapters

The 51 essentials, as a guide.

Are you a professional Web developer? · Unsubscribe anytime
Workshop for teams

Multiply your team's output without sacrificing quality: a 6 to 8 hour AI First workshop, online, on the Claude platform.

See the workshop

Want the 51 Claude Code essentials as a guide?