golang/go · error

%s %s: dir has been modified (%v)

Error message

%s %s: dir has been modified (%v)

What it means

Thrown during `go mod verify` when the computed hash of the module's extracted directory (`hD`) does not match the stored ziphash (`h`). This indicates the unpacked module directory has been modified after extraction, diverging from the hash recorded at download time. The `%v` argument is the directory path.

Source

Thrown at src/cmd/go/internal/modcmd/verify.go:140

		hZ, err := dirhash.HashZip(zip, dirhash.DefaultHash)
		if err != nil {
			errs = append(errs, fmt.Errorf("%s %s: %v", mod.Path, mod.Version, err))
			return errs
		} else if hZ != h {
			errs = append(errs, fmt.Errorf("%s %s: zip has been modified (%v)", mod.Path, mod.Version, zip))
		}
	}
	if dirErr != nil && errors.Is(dirErr, fs.ErrNotExist) {
		// ok
	} else {
		hD, err := dirhash.HashDir(dir, mod.Path+"@"+mod.Version, dirhash.DefaultHash)
		if err != nil {

			errs = append(errs, fmt.Errorf("%s %s: %v", mod.Path, mod.Version, err))
			return errs
		}
		if hD != h {
			errs = append(errs, fmt.Errorf("%s %s: dir has been modified (%v)", mod.Path, mod.Version, dir))
		}
	}
	return errs
}

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Clean and re-download: `go clean -modcache && go mod download`
  2. Avoid editing files under GOMODCACHE/pkg/mod directly; use vendor directories or replace directives instead
  3. Audit for scripts or tools that write into the module cache

Example fix

// before
go mod verify  // dir has been modified
// after
go clean -modcache && go mod download && go mod verify
Defensive patterns

Strategy: retry

Try / catch

// If directory tamper detected, reset cache
if strings.Contains(err.Error(), "dir has been modified") {
    goCleanModcache()
    goModDownload()
    goModVerify()
}

Prevention

When it happens

Trigger: Running `go mod verify` where `dirhash.HashDir` succeeds but `hD != h`. The extracted directory's content differs from what the original zip produced. This is the directory-level counterpart of the zip tamper check.

Common situations: Manual editing of cached source files; tools that patch or vendor into the cache; filesystem corruption; accidental modifications from IDE or file managers pointing at GOMODCACHE; partial overwrites.

Related errors


AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12). Data as JSON: /api/errors/818dcf737fe76874. Report an issue: GitHub.