# Path lexical common ancestor

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

Compute the deepest common ancestor directory of a set of paths.

**Use when you need to: common ancestor · longest common path prefix · shared ancestor directory.**

## Supported

- common ancestor
- longest common path prefix
- shared ancestor directory

## Not supported

- stat file
- resolve symlinks
- filesystem access

## Behavior

- Compute deepest common ancestor directory by comparing normalized segments.
- ancestor is common prefix directory path, or null if no common prefix.
- depth is number of common directory segments (0 if no common prefix).
- Windows: case-insensitive segment comparison. POSIX: case-sensitive.
- Paths on different drives return {ancestor:null,format:"windows",depth:0}.
- Single path input: ancestor is the parent directory of that path.

## Input

- `paths` (array of string, required): min items 1; max items 500; each min length 1; each max length 4096
- `format` (one of "posix", "windows", "auto", optional)

## Output

- `ancestor` (string or null, required)
- `format` (one of "posix", "windows", required)
- `depth` (integer, required): min 0

## Limits

- max paths: 500
- max path bytes: 4096

## Example

Request input:

```json
{
  "paths": [
    "/a/b/c",
    "/a/b/d",
    "/a/b/e/f"
  ]
}
```

Response:

```json
{
  "result": {
    "ancestor": "/a/b",
    "format": "posix",
    "depth": 2
  }
}
```

## How to call it

### MCP

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

```json
{
  "id": "path-lexical-common-ancestor",
  "version": "1.0.0",
  "input": {
    "paths": [
      "/a/b/c",
      "/a/b/d",
      "/a/b/e/f"
    ]
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/path-lexical-common-ancestor/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"paths":["/a/b/c","/a/b/d","/a/b/e/f"]}'
```

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

### CLI

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

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

## Related tools

- [Path lexical contains](/tools/path-lexical-contains): Check whether a child path is lexically inside a parent directory.
- [Path set prefix strip](/tools/path-set-prefix-strip): Strip a common directory prefix or base path from an array of paths lexically.
- [Path lexical join](/tools/path-lexical-join): Join an array of path segments lexically, resolving absolute reset boundaries and normalizing separators.
- [Path lexical normalize](/tools/path-lexical-normalize): Normalize a path lexically: collapse redundant separators, resolve "." and ".." segments.
- [Path lexical parse](/tools/path-lexical-parse): Decompose a file path into its lexical components without accessing the filesystem.
- [Path lexical relative](/tools/path-lexical-relative): Compute the lexical relative path from one path to another without filesystem access.
