> ## Documentation Index
> Fetch the complete documentation index at: https://docs.refactron.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Quickstart

> Install Refactron from npm and verify your first diff end to end, then give the same gate to your AI agent over MCP.

In the next ten minutes you'll install Refactron, verify a real change against a real test suite, and read your first `SAFE` / `UNSAFE` / `UNPROVEN` verdict.

## Install

Requires Node.js ≥ 18.

```bash theme={null}
npm install -g refactron
```

That puts two binaries on your `PATH`: `refactron` (the CLI) and `refactron-mcp` (the MCP server). To skip the install, run `npx refactron <command>` instead.

To earn a `SAFE` verdict end to end you also need a Python project with a passing `pytest` suite, plus `coverage.py` for the coverage measurement:

```bash theme={null}
pip install pytest coverage
```

> [!NOTE]
>
> Prefer PyPI? `pip install refactron==0.4.8` installs a thin `refactron` shim that shells out to
> the npm CLI. It is not a Node-free path: you still need Node.js ≥ 18 **and** `npm install -g
>     refactron`. When the npm CLI is missing, the shim prints the exact matching install command
> and exits non-zero. The shim provides the `refactron` command only; `refactron-mcp` comes from the
> npm package.

## Authenticate

`verify-diff` is auth-gated. Log in once on this machine (this runs a device-code flow and opens your browser to approve a code):

```bash theme={null}
refactron login
```

For CI or a headless box, export a token instead of the browser flow:

```bash theme={null}
export REFACTRON_TOKEN=refactron_live_...
```

An unauthenticated run exits `7`.

## Verify a diff

Point Refactron at a repo and a unified diff. The diff can come from anywhere: an agent, a codemod, or your own `git diff`.

**1. Capture a change as a diff**

From a Python project with a test suite:

```bash theme={null}
cd /path/to/your/project
git diff > change.diff          # or: your agent wrote change.diff
# already staged or committed? use `git diff --staged` or `git diff main...HEAD`
```

**2. Verify it**

Run `verify-diff` from inside the project you just captured the diff from:

```bash theme={null}
refactron verify-diff . --diff change.diff --test-cmd "python3 -m pytest -q"
```

Refactron copies your project into an isolated shadow tree, applies the diff there,
runs the gates, and measures whether your tests exercise the changed lines. Your
real working tree is never modified.

> [!NOTE]
>
> Coverage is **Python-only**, so only an all-Python diff can return `SAFE`; a TypeScript or
> mixed diff passes the gates and returns `UNPROVEN`. Form that expectation before the verdict
> prints below.

**3. Read the verdict**

One of three outcomes prints:

```text theme={null}
[SAFE] Tests pass and the changed code is covered.
```

```text theme={null}
[UNPROVEN] Tests pass, but the changed code is not exercised by any test.
  uncovered: calc.py:14
```

```text theme={null}
[UNSAFE] <the failing test output>
```

`SAFE` and `UNPROVEN` exit `0`; `UNSAFE` exits `1`, so it fails a CI job on its own.

What just happened:

* **`SAFE`**: the gates passed *and* your tests ran every changed statement they could reach. Proven.
* **`UNPROVEN`**: the gates passed, but the change isn't proven. Two causes, two responses:
  * A line is named in the output (`uncovered: calc.py:14`): add a test that exercises it, then re-run to earn `SAFE`.
  * The reason is "coverage of the changed code could not be determined": that's the [Python-only limit](https://docs.refactron.dev/verification/verdicts.md#the-python-only-limitation) (a non-Python or mixed diff, or no `coverage.py`). The gates still passed, but no added test changes the verdict today.
* **`UNSAFE`**: a gate rejected the change. A tests-gate failure prints the failing-test tail; a syntax or imports failure prints that gate's reason.

Add `--json` for the full reproducible report. See [Verdicts](https://docs.refactron.dev/verification/verdicts.md) for the complete model.

> [!WARNING]
>
> Coverage is **Python-only** (via `coverage.py`). A TypeScript or mixed-language diff can never
> reach `SAFE` today; it returns `UNPROVEN` ("coverage of the changed code could not be
> determined"). The gates still run; only the coverage half is Python-only.

## Give the gate to your agent (MCP)

The same engine is available as an [MCP](https://modelcontextprotocol.io) tool, `verify_change`, so an AI agent can verify a change before it lands it. Register the stdio server with your client. For Claude Code:

```bash theme={null}
claude mcp add refactron -- refactron-mcp
```

The agent proposes an edit (as full-file contents or a unified diff), calls `verify_change`, and gets back the same `SAFE` / `UNSAFE` / `UNPROVEN` report, then decides whether to land it. Full setup, for every client, in the [MCP tab](https://docs.refactron.dev/mcp/overview.md).

## Build from source (contributors)

Working on Refactron itself? Build the checkout instead of installing the published package:

```bash theme={null}
git clone https://github.com/Refactron-ai/refactron
cd refactron
npm install
npm run build
```

The CLI is then `node dist/cli/index.js <command>` and the MCP server is `node dist/mcp/server.js`. Every command on this page works the same way; substitute that invocation for `refactron`.

## Next steps

> [card] [Verify a diff](https://docs.refactron.dev/verification/verify-diff.md)
>
> Every `verify-diff` flag, exit code, and the JSON report shape.

> [card] [Safety model](https://docs.refactron.dev/concepts/safety-model.md)
>
> The shadow tree, the three gates, and the atomic-write contract.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.