# Path lexical relative

`path-lexical-relative` · version 1.0.0 · File paths (lexical) · free, no key needed

Compute the lexical relative path from one path to another without filesystem access.

**Use when you need to: path relative · relative path · compute relative path from to.**

## Supported

- path relative
- relative path
- compute relative path from to

## Not supported

- stat file
- resolve symlinks
- filesystem access
- cross-drive relative path

## Behavior

- Compute relative path from "from" to "to" using lexicalRelative.
- same: true if from and to normalize to the same path.
- Cross-drive Windows paths and absolute/relative mismatches throw badInput.
- relative is empty string "" when from and to are same (same:true).

## Input

- `from` (string, required): min length 1; max length 4096
- `to` (string, required): min length 1; max length 4096
- `format` (one of "posix", "windows", "auto", optional)

## Output

- `relative` (string, required)
- `format` (one of "posix", "windows", required)
- `same` (boolean, required)

## Limits

- max path bytes: 4096

## Example

Request input:

```json
{
  "from": "/a/b",
  "to": "/a/c/d"
}
```

Response:

```json
{
  "result": {
    "relative": "../c/d",
    "format": "posix",
    "same": false
  }
}
```

## How to call it

### MCP

Connect `https://computefirst.net/mcp` ([setup](/docs#connect)), then call `execute` with:

```json
{
  "id": "path-lexical-relative",
  "version": "1.0.0",
  "input": {
    "from": "/a/b",
    "to": "/a/c/d"
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/path-lexical-relative/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"from":"/a/b","to":"/a/c/d"}'
```

The machine-readable contract is at [/v1/tools/path-lexical-relative/versions/1.0.0](/v1/tools/path-lexical-relative/versions/1.0.0).

### CLI

```sh
node cli.mjs run path-lexical-relative 1.0.0 --input input.json --base-url https://computefirst.net
```

Get the client at [/clients/cli/](/clients/cli/).

## Related tools

- [Path lexical sanitize](/tools/path-lexical-sanitize): Sanitize an untrusted path to produce a safe relative path, stripping roots, drive letters, traversal segments, and illegal characters.
- [Path set hierarchy tree](/tools/path-set-hierarchy-tree): Transform a flat array of file paths into a nested deterministic directory tree structure.
- [Path format convert](/tools/path-format-convert): Convert file paths between POSIX and Windows formats, handling slashes, drive letters, and roots lexically.
- [Path lexical common ancestor](/tools/path-lexical-common-ancestor): Compute the deepest common ancestor directory of a set of paths.
- [Path lexical contains](/tools/path-lexical-contains): Check whether a child path is lexically inside a parent directory.
- [Path lexical join](/tools/path-lexical-join): Join an array of path segments lexically, resolving absolute reset boundaries and normalizing separators.
