Skip to content
Back to search

difit

A lightweight command-line tool that spins up a local web server to display Git commit diffs in a GitHub-like Files changed view

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today
Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/yoshiko-pg-difit/badge.svg)](/listings/yoshiko-pg-difit)

HTML

<a href="/listings/yoshiko-pg-difit"><img src="/api/listings/yoshiko-pg-difit/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

Install instructions from the README

As written by the repo's author. findsafeskills has not verified these steps.

Try it first

npx difit  # View the latest commit diff in WebUI

Install and use

npm install -g difit
difit  # View the latest commit diff in WebUI

Enable use from AI agents

npx skills add yoshiko-pg/difit # Add the Skills to your agent

Installed skills include:

- `difit`: ask the user for a review in the difit viewer when the user explicitly opts in to difit - `difit-review`: review a specific diff or PR and show the findings inside the difit viewer, when the user explicitly asks for difit

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

README.md · README · 285 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

  1. <h1 align="center">
  2. <img src="public/logo.png" alt="difit" width="260">
  3. </h1>
  4. <p align="center">
  5. <a href="https://www.npmjs.com/package/difit"><img src="https://img.shields.io/npm/v/difit.svg" alt="npm version"></a>
  6. <a href="https://github.com/yoshiko-pg/difit/actions/workflows/pr.yml"><img src="https://github.com/yoshiko-pg/difit/actions/workflows/pr.yml/badge.svg" alt="CI"></a>
  7. </p>
  8. <p align="center">
  9. English | <a href="./README.ja.md">日本語</a> | <a href="./README.zh.md">简体中文</a> | <a href="./README.ko.md">한국어</a>
  10. </p>
  11. ![difit screenshot](docs/images/screenshot.png)
  12. **difit** is a CLI tool that lets you view and review local git diffs with a GitHub-style viewer. In addition to clean visuals, comments can be copied as prompts for AI. The local code review tool for the AI era!
  13. ## ⚡ Quick Start
  14. Try it first
  15. ```bash
  16. npx difit # View the latest commit diff in WebUI
  17. ```
  18. Install and use
  19. ```bash
  20. npm install -g difit
  21. difit # View the latest commit diff in WebUI
  22. ```
  23. Enable use from AI agents
  24. ```bash
  25. npx skills add yoshiko-pg/difit # Add the Skills to your agent
  26. ```
  27. Installed skills include:
  28. - `difit`: ask the user for a review in the difit viewer when the user explicitly opts in to difit
  29. - `difit-review`: review a specific diff or PR and show the findings inside the difit viewer, when the user explicitly asks for difit
  30. ## 🚀 Usage
  31. ### Basic Usage
  32. ```bash
  33. difit <target> # View single commit diff
  34. difit <target> [compare-with] # Compare two commits/branches
  35. ```
  36. ### Single commit review
  37. ```bash
  38. difit # HEAD (latest) commit
  39. difit 6f4a9b7 # Specific commit
  40. difit feature # Latest commit on feature branch
  41. ```
  42. ### Compare two commits
  43. ```bash
  44. difit @ main # Compare with main branch (@ is alias for HEAD)
  45. difit feature main # Compare branches
  46. difit . origin/main # Compare working directory with remote main
  47. ```
  48. ### Special Arguments
  49. difit supports special keywords for common diff scenarios:
  50. ```bash
  51. difit . # All uncommitted changes (staging area + unstaged)
  52. difit staged # Staging area changes
  53. difit working # Unstaged changes only
  54. ```
  55. ### GitHub PR
  56. ```bash
  57. difit --pr https://github.com/owner/repo/pull/123
  58. ```
  59. `--pr` mode fetches patches by running `gh pr diff --patch` under the hood.
  60. It also imports unresolved inline review threads from the PR so they appear as startup comments in difit.
  61. Authentication is handled by GitHub CLI:
  62. 1. **Login once** (recommended): `gh auth login`
  63. 2. **Token-based auth** (CI/non-interactive): set `GH_TOKEN` or `GITHUB_TOKEN`
  64. #### GitHub Enterprise Server
  65. For Enterprise Server PRs, authenticate GitHub CLI against your Enterprise host:
  66. 1. `gh auth login --hostname YOUR-ENTERPRISE-SERVER`
  67. 2. Or set `GH_HOST=YOUR-ENTERPRISE-SERVER` with `GH_TOKEN`/`GITHUB_TOKEN`
  68. ### Initial Comments
  69. You can inject initial review comments when launching difit:
  70. ```bash
  71. difit --comment '{"type":"thread","filePath":"src/example.ts","position":{"side":"new","line":10},"body":"The background for this change is..."}'
  72. ```
  73. `--comment` is repeatable and accepts either a single JSON object or a JSON array. Supported types:
  74. - `thread`: create a new thread at the specified diff position
  75. - `reply`: add a reply to the latest existing thread at the same diff position
  76. If the same comment already exists, difit skips importing it.
  77. ### Stdin
  78. By using a pipe to pass unified diffs via stdin, you can view diffs from any tool with difit.
  79. ```bash
  80. # View diffs from other tools
  81. diff -u file1.txt file2.txt | difit
  82. # Review saved patches
  83. cat changes.patch | difit
  84. # Compare against merge base
  85. git diff --merge-base main feature | difit
  86. # Review an entire existing file as newly added
  87. git diff -- /dev/null path/to/file | difit
  88. # Explicit stdin mode
  89. git diff --cached | difit -
  90. ```
  91. Stdin mode is selected with intent-first rules:
  92. - `-` explicitly enables stdin mode
  93. - If positional arguments (`<target>` / `[compare-with]`) or `--pr` are provided, difit treats the command as Git/PR mode and does not auto-read stdin
  94. - Auto stdin detection applies only when no explicit mode is selected and stdin is a pipe/file/socket
  95. ## ⚙️ CLI Options
  96. | Flag | Default | Description |
  97. | --------------------- | --------------- | ------------------------------------------------------------------------------------------------------- |
  98. | `<target>` | HEAD | Commit hash, tag, HEAD~n, branch, or special arguments |
  99. | `[compare-with]` | - | Optional second commit to compare with (shows diff between the two) |
  100. | `--merge-base` | false | Resolve the base revision with `git merge-base` before diffing (Git revision mode only) |
  101. | `--pr <url>` | - | GitHub PR URL to review (e.g., https://github.com/owner/repo/pull/123) |
  102. | `--comment <json>` | - | Inject initial comments (repeatable; accepts a JSON object or array) |
  103. | `--port` | 4966 | Preferred port; falls back to +1 if occupied |
  104. | `--host` | 127.0.0.1 | Host address to bind server to (use 0.0.0.0 for external access) |
  105. | `--no-open` | false | Don't automatically open browser |
  106. | `--clean` | false | Clear all existing comments and viewed files on startup |
  107. | `--include-untracked` | false | Automatically include untracked files in diff (only with `.` or `working`) |
  108. | `--keep-alive` | false | Keep server running after browser disconnects (stop manually with Ctrl+C) |
  109. | `--background` | false | Keep the server running in the background and output JSON connection info |
  110. | `--context <lines>` | git default (3) | Limit surrounding context lines per change (`0` shows changes only; not available with `--pr` or stdin) |
  111. ## 💬 Comment System
  112. difit includes a review comment system that makes it easy to provide feedback to AI coding agents:
  113. 1. **Add Comments**: Click the comment button on any diff line or drag to select a range
  114. 2. **Edit Comments**: Edit existing comments with the edit button
  115. 3. **Generate Prompts**: Comments include a "Copy Prompt" button that formats the context for AI coding agents
  116. 4. **Copy All**: Use "Copy All Prompt" to copy all comments in a structured format
  117. 5. **Persistent Storage**: Comments are saved in browser localStorage per commit
  118. ### Comment Prompt Format
  119. ```sh
  120. src/components/Button.tsx:L42 # This line is automatically added
  121. Make this variable name more descriptive
  122. ```
  123. For range selections:
  124. ```sh
  125. src/components/Button.tsx:L42-L48 # This line is automatically added
  126. This section is unnecessary
  127. ```
  128. ## 🤖 Calling from Agents
  129. You can install the following Skills to work with difit from AI agents.
  130. ```sh
  131. npx skills add yoshiko-pg/difit
  132. ```
  133. Installed skills include:
  134. - `difit`: ask the user for a review in the difit viewer when the user explicitly opts in to difit
  135. - `difit-review`: review a specific diff or PR and show the findings inside the difit viewer, when the user explicitly asks for difit
  136. After code edits or automated review, the agent can start the difit server with the appropriate skill.
  137. ## 🎨 Syntax Highlighting Languages
  138. - **JavaScript/TypeScript**: `.js`, `.jsx`, `.ts`, `.tsx`, `.svelte`
  139. - **Web Technologies**: HTML, CSS, JSON, XML, Markdown
  140. - **Shell Scripts**: `.sh`, `.bash`, `.zsh`, `.fish`
  141. - **Backend Languages**: PHP, SQL, Ruby, Java, Groovy, Scala, Perl, Elixir, Haskell, Clojure
  142. - **Systems Languages**: C, C++, C#, Rust, Go
  143. - **Mobile Languages**: Swift, Kotlin, Dart
  144. - **Infrastructure as Code**: Terraform (HCL), Nix
  145. - **Others**: Python, Protobuf, YAML, Solidity, Vim script, GDScript
  146. ## 🔍 Auto-collapsed Files
  147. difit automatically identifies and collapses certain files to keep your view clean:
  148. - **Deleted files**: Removed files are auto-collapsed since they don't require close review
  149. - **Generated files**: Auto-generated code is collapsed by default. This includes:
  150. - Lock files (`package-lock.json`, `go.sum`, `Cargo.lock`, `Gemfile.lock`, etc.)
  151. - Minified files (`*.min.js`, `*.min.css`)
  152. - Source maps (`*.map`)
  153. - Generated code:
  154. - Orval (`*.msw.ts`, `*.zod.ts`, `*.api.ts`)
  155. - Dart (`*.g.dart`, `*.freezed.dart`)
  156. - C# (`*.g.cs`, `*.designer.cs`)
  157. - Protobuf (`*.pb.go`, `*.pb.cc`, `*.pb.h`)
  158. - Frameworks:
  159. - Ruby on Rails (`db/schema.rb`)
  160. - Laravel (`_ide_helper.php`)
  161. - Gradle (`gradle.lockfile`)
  162. - Python (`uv.lock`, `pdm.lock`)
  163. - Generic generated files (`*.generated.cs`, `*.generated.ts`, `*.generated.js`)
  164. - Content-based detection:
  165. - Files containing `@generated` marker
  166. - Files containing `DO NOT EDIT` header
  167. - Language-specific generated headers (Go, Python, etc.)
  168. ## 🛠️ Development
  169. ```bash
  170. # Install dependencies
  171. pnpm install
  172. # Start development server (with hot reload)
  173. # This runs both Vite dev server and CLI with NODE_ENV=development
  174. pnpm run dev
  175. # Build and start production server
  176. pnpm run start <target>
  177. # Build for production
  178. pnpm run build
  179. # Run tests
  180. pnpm test
  181. # Run typecheck, lint, and format
  182. pnpm run check
  183. pnpm run format
  184. ```
  185. ### Development Workflow
  186. - **`pnpm run dev`**: Starts both Vite dev server (with hot reload) and CLI server simultaneously
  187. - **`pnpm run start <target>`**: Builds everything and starts production server (for testing final build)
  188. - **Development mode**: Uses Vite's dev server for hot reload and fast development
  189. - **Production mode**: Serves built static files (used by npx and production builds)
  190. ## 🏗️ Architecture
  191. - **CLI**: Commander.js for argument parsing with comprehensive validation
  192. - **Backend**: Express server with simple-git for diff processing
  193. - **GitHub Integration**: GitHub CLI (`gh pr diff --patch`) for PR patch retrieval
  194. - **Frontend**: React 18 + TypeScript + Vite
  195. - **Styling**: Tailwind CSS v4 with GitHub-like dark theme
  196. - **Syntax Highlighting**: Prism.js with dynamic language loading
  197. - **Testing**: Vitest for unit tests with co-located test files
  198. - **Quality**: oxlint, oxfmt, lefthook pre-commit hooks
  199. ## 📋 Requirements
  200. - Node.js ≥ 21.0.0
  201. - Git repository with commits to review
  202. - GitHub CLI (`gh`) for `--pr` mode
  203. ## 📄 License
  204. MIT

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.