---
name: kimaai_chatbot_session_retention_days
type: filter
since: 1.4.9
tier: free
feature: chat-history
area: chatbot
summary: Changes how many days the chatbot's conversations are kept before the cleanup deletes them.
parameters:
  - name: days
    type: int
    description: The days of the setting, 0 when the custom number is 0.
  - name: chatbot_settings
    type: array
    description: The chatbot settings.
  - name: mode
    type: string
    description: The setting's choice, 6_months, 1_year, 2_years, 5_years or custom_days.
returns:
  type: int
  description: The days to keep; 0 or less keeps every conversation.
---

# kimaai_chatbot_session_retention_days

## When it fires

Whenever KimaAI works out the retention period from the settings: before each run of the daily cleanup, and on admin and cron requests while it keeps the cleanup scheduled. The cleanup runs only while "Delete old conversations" is on; this filter cannot switch it on.

A conversation counts as old when its last message is older than the days returned. The cleanup then deletes its messages, ratings, conversation facts, topic links and tool records, and unlinks it from the conversions it led to, which stay counted. 0 or less keeps every conversation.

## Example

```php
add_filter(
  'kimaai_chatbot_session_retention_days',
  function (int $days): int {
    // Company policy: no conversation older than 90 days, whatever the setting says.
    return min($days, 90);
  }
);
```

## Related

- `kimaai_chatbot_session_retention_should_run`: pauses a cleanup run.
- `kimaai_chatbot_session_retention_before_cleanup`: fires before a run deletes anything.
- `kimaai_chatbot_session_retention_after_cleanup`: fires after a run.
