JanDeDobbeleer/oh-my-posh · warning

%s environment variable not set, do you have the posh-git mo

Error message

%s environment variable not set, do you have the posh-git module installed?

What it means

On PowerShell, the git segment can read git status from the POSH_GIT_STATUS environment variable populated by the posh-git module. If the variable is unset, the segment logs '<env> environment variable not set, do you have the posh-git module installed?' and reports no posh-git status.

Source

Thrown at src/segments/posh_git.go:51

	Deleted  []string `json:"Deleted"`
	Unmerged []string `json:"Unmerged"`
}

func (s *GitStatus) parsePoshGitStatus(p *poshGitStatus) {
	if p == nil {
		return
	}

	s.Added = len(p.Added)
	s.Deleted = len(p.Deleted)
	s.Modified = len(p.Modified)
	s.Unmerged = len(p.Unmerged)
}

func (g *Git) hasPoshGitStatus() bool {
	envStatus := g.env.Getenv(poshGitEnv)
	if envStatus == "" {
		log.Error(fmt.Errorf("%s environment variable not set, do you have the posh-git module installed?", poshGitEnv))
		return false
	}

	var posh poshGit
	err := json.Unmarshal([]byte(envStatus), &posh)
	if err != nil {
		log.Error(err)
		return false
	}

	g.setDir(posh.GitDir)
	g.Working = &GitStatus{}
	g.Working.parsePoshGitStatus(posh.Working)
	g.Staging = &GitStatus{}
	g.Staging.parsePoshGitStatus(posh.Index)
	g.HEAD = g.parsePoshGitHEAD(posh.Branch)
	g.stashCount = posh.StashCount
	g.Ahead = posh.AheadBy

View on GitHub (pinned to 0976794618)

Solutions

  1. Install and import the posh-git module in your PowerShell profile before oh-my-posh initializes (`Install-Module posh-git; Import-Module posh-git)`
  2. Only enable the poshgit mode inside PowerShell; switch to the default git status mode in other shells
  3. Verify `$env:POSH_GIT_STATUS` is populated after a prompt renders in PowerShell
  4. Remove the poshgit option from the git segment config if you don't use posh-git

Example fix

// before: theme segment works only with posh-git
"git": { "display_mode": "poshgit" }
// after: default native status, no module needed
"git": { "display_mode": "files" }
Defensive patterns

Strategy: validation

Validate before calling

// check the variable is present before enabling poshgit mode
if os.Getenv("POSH_GIT_STATUS") == "" {
    // module not imported; use default git status mode
}

Prevention

When it happens

Trigger: Rendering the git segment with the poshgit display_mode in a shell where the posh-git module is not installed, not imported in the profile, or an older posh-git version that doesn't export POSH_GIT_STATUS.

Common situations: Using oh-my-posh in bash/zsh/fish where posh-git (a PowerShell-only module) never sets the variable; posh-git removed from the PowerShell $PROFILE; running oh-my-posh without importing posh-git before the prompt renders; typos in profile ordering so the prompt initializes before posh-git.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of JanDeDobbeleer/oh-my-posh@0976794618 (2026-08-31). Data as JSON: /api/errors/3fdfbdf4f46d699d. Report an issue: GitHub.