# condense_path

> **Function** in `deepagents_code`

📖 [View in docs](https://reference.langchain.com/python/deepagents-code/tui/widgets/_condense_path/condense_path)

Condense `path` so it renders within `width` terminal cells.

Directory components are replaced by a single ellipsis, growing outward
from the middle of the component list, because the tail of a path — the
directory or file the user is actually looking at — is the part worth
keeping. The last component is only end-truncated once every directory
component has already been dropped.

## Signature

```python
condense_path(
    path: str,
    width: int,
    prefix: str = '',
) -> str
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `path` | `str` | Yes | Path to display, already home-substituted where wanted. |
| `width` | `int` | Yes | Cells available for `prefix` and the path together. |
| `prefix` | `str` | No | Text rendered immediately before the path; it is returned as part of the result and counted against `width`. (default: `''`) |

## Returns

`str`

`prefix` followed by as much of the path as fits in `width`.

---

[View source on GitHub](https://github.com/langchain-ai/deepagents/blob/4bfa52000ef65ac623d8ada0cb67f67cbdd663ea/libs/code/deepagents_code/tui/widgets/_condense_path.py#L17)