# prewarm_thread_message_counts

> **Function** in `deepagents_code`

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

Prewarm thread selector cache for faster `/threads` open.

Fetches a bounded list of recent threads and populates checkpoint-derived
fields for currently visible columns into the in-memory cache. Intended to
run in a background worker during app startup and again whenever the
session database has changed (e.g. after a turn writes new checkpoints), so
the selector's first paint is never missing a thread the user just created.

Re-running this is cheap: the per-thread message-count and initial-prompt
caches are keyed on checkpoint freshness, so only threads whose latest
checkpoint changed are read back from disk.

## Signature

```python
prewarm_thread_message_counts(
    limit: int | None = None,
) -> None
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `limit` | `int \| None` | No | Maximum threads to prewarm. Uses `get_thread_limit()` when `None`. (default: `None`) |

---

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