Every command supports --format json for machine-readable output.
-s, --staged Show staged changes only-c, --commit <sha> Diff a specific commit--from <ref> --to <ref> Diff a commit range-f, --format <fmt> terminal, json, plain, or markdown--file-exts <ext>... Filter by extension (e.g. .py .rs)-v, --verbose Show inline before/after content--stdin Read file changes from stdin (no git needed)<entity> Name of the entity to analyze--file <path> Disambiguate when multiple entities share a name--deps Show direct dependencies only--dependents Show direct dependents only--tests Show affected test entities only--json Output as JSON--file-exts <ext>... Filter by extension<file> File to blame--json Output as JSON<entity> Name of the entity to trace--file <path> File containing the entity (auto-detected if omitted)--limit <n> Maximum commits to scan (default: 50)-v, --verbose Show content diff between versions--json Output as JSON[path] File or directory path; defaults to .--json Output as JSON<entity> Name of the entity--file <path> Disambiguate when multiple entities share a name--budget <n> Token budget (default: 8000)--json Output as JSON--file-exts <ext>... Filter by extensiongit diff runs through sem automaticallyPipe into your AI agent, CI pipeline, or automation.
{ "summary": { "fileCount": 2, "added": 1, "modified": 1, "deleted": 1, "total": 3 }, "changes": [ { "entityId": "src/auth.ts::function::validateToken", "changeType": "added", "entityType": "function", "entityName": "validateToken", "filePath": "src/auth.ts" } ] }
Three-phase algorithm. Detects additions, modifications, deletions, renames, and moves.
Phase 1: Exact ID
Same entity ID in before/after? Modified or unchanged.
Phase 2: Structural hash
Same AST structure, different name? Renamed or moved.
Phase 3: Fuzzy similarity
>80% token overlap? Probable rename.
| Feature | git diff | sem diff |
|---|---|---|
| Granularity | lines | entities (functions, classes, properties) |
| Code parsing | no | tree-sitter (21 languages) |
| Config files | lines | key-path entities |
| Rename detection | heuristic (file-level) | 3-phase (ID + hash + fuzzy) |
| Machine output | patch format | JSON |
| Agent accuracy | 41.5% | 95.9% (benchmark) |
| Speed | 9ms | 8ms |
Measured with hyperfine on the sem repo. 50 runs, median reported.
Same commit (5 files), same repo.
Faster than git diff while adding semantic parsing, rename detection, and structural hashing.
Built-in instrumentation via sem diff --profile. Shows where time is spent inside the binary.
CPU time breakdown for sem diff --commit (large, 13 files). Hover for details.
| Format | Extensions | Entities |
|---|---|---|
| TypeScript | .ts .tsx .mts .cts | functions, classes, interfaces, types, enums, exports |
| JavaScript | .js .jsx .mjs .cjs | functions, classes, variables, exports |
| Python | .py | functions, classes, decorated definitions |
| Go | .go | functions, methods, types, vars, consts |
| Rust | .rs | functions, structs, enums, impls, traits, mods, consts |
| Java | .java | classes, methods, interfaces, enums, fields, constructors |
| C | .c .h | functions, structs, enums, unions, typedefs |
| C++ | .cpp .cc .hpp | functions, classes, structs, enums, namespaces, templates |
| C# | .cs | classes, methods, interfaces, enums, structs, properties |
| Ruby | .rb | methods, classes, modules |
| PHP | .php | functions, classes, methods, interfaces, traits, enums |
| Swift | .swift | functions, classes, protocols, structs, enums, properties |
| Elixir | .ex .exs | modules, functions, macros, guards, protocols |
| Bash | .sh | functions |
| HCL/Terraform | .hcl .tf .tfvars | blocks, attributes (qualified names) |
| Kotlin | .kt .kts | classes, interfaces, objects, functions, properties |
| Fortran | .f90 .f95 .f | functions, subroutines, modules, programs |
| Vue | .vue | template/script/style blocks + inner TS/JS entities |
| XML | .xml .plist .svg .csproj | elements (nested, tag-name identity) |
| ERB | .erb | blocks, expressions, code tags |
| Svelte | .svelte .svelte.js .svelte.ts | component blocks, rune modules + inner JS/TS entities |
| JSON | .json | properties, objects (RFC 6901 paths) |
| YAML | .yml .yaml | sections, properties (dot paths) |
| TOML | .toml | sections, properties |
| CSV | .csv .tsv | rows (first column as ID) |
| Markdown | .md .mdx | heading-based sections |