This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
revui is a terminal-based code review tool for git diffs, built with Go and the Bubble Tea TUI framework. It provides vim-style navigation, side-by-side and unified diff views, inline commenting, and multiple output options (tmux integration, clipboard, file) — designed for pasting review comments into AI coding assistants.
# Build
go build ./cmd/revui
# Run
./revui # auto-detect base branch from origin/HEAD
./revui --base main # explicit base branch
./revui --remote upstream # auto-detect from a different remote
# Test
go test ./... # all tests
go test ./internal/ui/ -v # single package
go test -run TestDiffView ./internal/ui/ # single test
# Benchmarks
go test ./... -bench=. -benchmem -count=3
# Lint/format
go vet ./...
go fmt ./...The app follows Bubble Tea's composable model pattern. Each UI component implements Init(), Update(), View().
Package structure:
cmd/revui/— Entry point. Parses flags, validates git repo, auto-detects base branch, runs the TUI.internal/git/— Git operations viaos/exec.Runnershells out to git;parse.goparses unified diff output into structured types (FileDiff→Hunk→Line). TheGitRunnerinterface (defined ininternal/ui/root.go) enables mock-based testing.internal/comment/— In-memoryStorefor review comments with O(1) lookup by file+line via map index.format.gorenders comments as markdown.internal/output/— Output delivery to multiple targets. Detects tmux environment, can send to Claude panes via tmux, tmux paste buffer, system clipboard, or file.internal/ui/— All TUI components:root.go—RootModelorchestrates focus routing betweenFileList,DiffViewer, andCommentInput. Handles global keys (Tab for view toggle,ZZto finish,qto quit).filelist.go— Left panel file list with j/k navigation.diffview.go— Main diff rendering (unified and side-by-side). Hot path (~710 lines). Flattens hunks into[]diffLinefor scrolling. Handles visual mode line selection, search (/,n,N), and comment navigation (]c,[c).sidebyside.go— Pairs left/right lines for side-by-side rendering.commentinput.go— Modal text input overlay.help.go— Help overlay (?).
Data flow: main.go → RootModel → routes keys to focused sub-model → DiffViewer calls GitRunner to lazy-load diffs per file → comments stored in comment.Store → on ZZ, comment.Format() produces markdown → OutputSelector presents available targets (Claude panes, tmux buffer, clipboard, file) → output.Deliver() sends to chosen target.
- Dependency injection:
GitRunnerinterface lets UI tests usemockGitRunnerinstead of real git. - Lazy loading: Diffs are fetched per-file on selection, not upfront.
- Performance-conscious rendering:
strings.BuilderwithGrow(), fixed-size byte arrays for line number formatting, reused empty lipgloss styles. Changes todiffview.gorendering should be benchmarked. - Test helpers:
setupTestRepo()creates real git repos in temp dirs for git package tests.makeTestDiff()andnewTestRoot()for UI tests. Tests are table-driven.
j/k navigate, Tab toggles unified/side-by-side, v enters visual mode, c adds comment, ]c/[c next/prev comment, / search, ZZ finish (choose output target), q quit, ? help.