# Path lexical contains

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

Check whether a child path is lexically inside a parent directory.

**Use when you need to: path contains · directory containment · path traversal check.**

## Supported

- path contains
- directory containment
- path traversal check
- is path inside directory

## Not supported

- stat file
- resolve symlinks
- filesystem access

## Behavior

- Check whether child is lexically inside parent using lexicalContains.
- relative is the relative subpath from parent to child when contains:true, else null.
- A path is NOT contained if relative starts with "..".
- Paths on different drives or with mismatched absolute/relative status: contains:false.
- Default case_sensitive: true for posix, false for windows.

## Input

- `parent` (string, required): min length 1; max length 4096
- `child` (string, required): min length 1; max length 4096
- `format` (one of "posix", "windows", "auto", optional)
- `case_sensitive` (boolean, optional)

## Output

- `contains` (boolean, required)
- `relative` (string or null, required)
- `format` (one of "posix", "windows", required)

## Limits

- max path bytes: 4096

## Example

Request input:

```json
{
  "parent": "/app",
  "child": "/app/src/index.js"
}
```

Response:

```json
{
  "result": {
    "contains": true,
    "relative": "src/index.js",
    "format": "posix"
  }
}
```

## How to call it

### MCP

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

```json
{
  "id": "path-lexical-contains",
  "version": "1.0.0",
  "input": {
    "parent": "/app",
    "child": "/app/src/index.js"
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/path-lexical-contains/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"parent":"/app","child":"/app/src/index.js"}'
```

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

### CLI

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

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

## Related tools

- [Path lexical common ancestor](/tools/path-lexical-common-ancestor): Compute the deepest common ancestor directory of a set of paths.
- [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 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.
