# list_threads

> **Function** in `deepagents_code`

📖 [View in docs](https://reference.langchain.com/python/deepagents-code/sessions/list_threads)

List threads from checkpoints table.

## Signature

```python
list_threads(
    agent_name: str | None = None,
    limit: int = 20,
    include_message_count: bool = False,
    sort_by: str = 'updated',
    branch: str | None = None,
    cwd: str | None = None,
) -> list[ThreadInfo]
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `agent_name` | `str \| None` | No | Optional filter by agent name. (default: `None`) |
| `limit` | `int` | No | Maximum number of threads to return. (default: `20`) |
| `include_message_count` | `bool` | No | Whether to include message counts. (default: `False`) |
| `sort_by` | `str` | No | Sort field — `"updated"` or `"created"`. (default: `'updated'`) |
| `branch` | `str \| None` | No | Optional filter by git branch name. (default: `None`) |
| `cwd` | `str \| None` | No | Optional filter by working directory. Only threads whose stored `cwd` metadata equals this path are returned. Matching is an exact string comparison — no path normalization, symlink resolution, or prefix matching. Threads without a stored `cwd` (older rows) are excluded. (default: `None`) |

## Returns

`list[ThreadInfo]`

List of `ThreadInfo` dicts with `thread_id`, `agent_name`,
`updated_at`, `created_at`, `latest_checkpoint_id`, `git_branch`,
`cwd`, and optionally `message_count`.

---

[View source on GitHub](https://github.com/langchain-ai/deepagents/blob/0412009c5441bef8d75a427e1da8909e33ab5b56/libs/code/deepagents_code/sessions.py#L312)