ForHosting KIT · Developer Utilities

Compute a code file line diff

See exactly what changed between two versions of a file: rewriting return a + b as two new lines shows 2 added, 1 removed and 3 unchanged, with old and new line numbers and a classic diff view. Free in your browser.

  • Free
  • Runs in your browser
  • No sign-up
  • Your data stays on your device
Use it from WebAPIEmailTelegramApp soon

Compare two versions of a source file and get a deterministic, line-by-line account of what changed. The result identifies every added, removed, and unchanged line, includes old and new line numbers where they apply, and provides a familiar unified-style diff for logs or review screens. It works with any text-based programming language and does not attempt to interpret syntax, execute the code, contact a repository, or modify either version. That makes it useful as a small, predictable building block for developer tools, teaching systems, migration checks, and automated review workflows.

Provide the two code versions

Either version may be empty, which naturally represents a newly created or completely deleted file, but they cannot both be empty because there would be nothing meaningful to compare. Line endings are normalized before comparison, so text using Windows CRLF and text using Unix LF can be compared without reporting every line as changed. The comparison is deliberately language-neutral: JavaScript, Python, Go, Rust, configuration files, templates, SQL, and other line-oriented text all follow the same rules.

Lines are compared exactly after newline normalization. Spaces, tabs, capitalization, punctuation, and comments remain significant because those details can change program behavior. Provide the complete text rather than a patch.

The result never evaluates code and never resolves imports, so untrusted snippets can be compared as plain text. For predictable resource use, each version is limited to 2,000 lines; split unusually large generated files into smaller sections before submitting them.

Read structured changes and the unified-style view

The summary counts added, removed, and unchanged lines. Each structured record has a type and its exact text. Fields that do not apply are omitted, keeping downstream handling clearer than placeholder null values.

A changed line is represented as one removal and one addition, matching the core semantics used by traditional line diff tools. The output covers the whole supplied file rather than collapsing distant unchanged regions into separate context hunks. This choice makes the result simple to parse and ensures that the structured list and textual view describe exactly the same sequence.

Use deterministic output in developer workflows

The algorithm finds an ordered common subsequence, which allows insertions and deletions to be recognized even when line numbers shift. Duplicate lines are handled by position and ordering rather than by treating the file as a set. When more than one valid alignment exists, the implementation applies a stable tie-breaking rule, so identical inputs always produce identical output.

Use the structured array when building a side-by-side viewer, counting change types, annotating line numbers, or enforcing a policy. Here, the narrower line model provides transparent behavior, no network dependency, and a result that can be reproduced locally from the same two strings.

Build a code review view

Render structured added, removed, and unchanged records with the correct old and new line numbers.

Check generated source changes

Compare generated output across two runs and store a deterministic unified-style record in build logs.

Explain an exercise revision

Show students exactly which source lines were inserted or deleted without executing submitted code.

What does one comparison cost?

The browser experience can run the same deterministic logic locally.

Which programming languages are supported?

Any text-based language is supported because comparison is performed on lines and does not depend on syntax.

Are whitespace-only changes reported?

Yes. Spaces and tabs are significant, so a line whose whitespace changes is represented as removed and added.

Can one version be empty?

Yes. One empty version represents a new or deleted file. An error is returned only when both versions are empty.

Does the result use unified diff format?

It provides familiar file markers, a range header, and line prefixes, plus structured records. It is a unified-style whole-file view rather than multiple compressed context hunks.

Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.

POSThttps://api.kit.forhosting.com/dev2/diff-two-code-files

Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.

curl -X POST https://api.kit.forhosting.com/dev2/diff-two-code-files \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"original_code":"function greet(name) {\n  return `Hello, ${name}`;\n}\n","revised_code":"function greet(name = \"world\") {\n  return `Hello, ${name}!`;\n}\n"}'
{
  "original_code": "function greet(name) {\n  return `Hello, ${name}`;\n}\n",
  "revised_code": "function greet(name = \"world\") {\n  return `Hello, ${name}!`;\n}\n"
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "dev2.diff_two_code_files",
  "status": "queued",
  "_links": {
    "result": "/tasks/tsk_…/result"
  }
}

The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

Provide the two code versions

Send the earlier source text in original_code and the later source text in revised_code.

Read structured changes and the unified-style view

The response contains an identical flag, a summary, a structured lines array, and unified-style text. Unchanged records include both old_line and new_line because the line exists in both versions. Removed records include old_line, while added records include new_line. The unified_diff field begins with original and revised file markers followed by a range header and prefixed lines: a space means unchanged, a minus sign means removed, and a plus sign means added.

Use deterministic output in developer workflows

Use unified_diff when writing a readable log entry, attaching a compact artifact to a task, or feeding a tool that understands familiar prefix markers. This capability intentionally does not perform syntax-aware matching, rename detection, token-level highlighting, merge conflict resolution, or repository access. Those jobs require language parsers or version-control context.

Read the full KIT documentation →