This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
gdgh is a zero-dependency Go CLI tool that converts git diffs into styled HTML pages. It supports line-by-line and side-by-side views with light/dark color schemes.
# Build
go build -o gdgh ./cmd
# Run directly
go run ./cmd [flags]
# Run tests
go test ./...
# Run a single package's tests
go test ./internal/diff/
go test ./internal/html/
# Example usage
go run ./cmd -- HEAD~1 # diff last commit, open in browser
go run ./cmd -s side -o stdout -- HEAD~1 # side-by-side to stdout
go run ./cmd -i file testdata/sample.diff # from file
cat testdata/sample.diff | go run ./cmd -i stdin -s sideThe pipeline is: parse → render → output.
cmd/main.go— CLI entry point. Handles flags, reads diff input (fromgit diff, a file, or stdin), invokes the parser and renderer, then writes output (browser preview, stdout, or file).internal/diff/parser.go— Parses unified diff text intoDiffResult(containing[]FileDiff, each with[]Hunk, each with[]Line). Handles bothgit diffformat and plain unified diffs.internal/html/renderer.go— Takes a*diff.DiffResultandOptions, returns a complete self-contained HTML string. CSS is inlined viagetCSS(). Supports two render paths:renderFileLineByLineandrenderFileSideBySide(which callsbuildSidePairsto align removed/added lines).
There are no external dependencies — the module only uses the Go standard library.
testdata/ contains a sample diff (sample.diff) and reference HTML outputs (output-line.html, output-side.html, output-side-dark.html) useful for verifying renderer output visually.