anthropics / anthropics/claude-agent-sdk-python

get_session_info() returns no AI-generated title for sessions created via the Python SDK

Aberta
#854 0 comentários 2 reações 0 responsáveis Ver no GitHub
Linguagem predominante
Python
Estrelas
8.1k
Forks
1.3k
Merge médio
2d 31min
PRs com merge (30d)
1

Descrição

## Problem

Follow-up to #161, which was closed saying `get_session_info()` would return the AI-generated title via `SDKSessionInfo.summary` / `custom_title` (available since SDK `v0.1.50+`).

In practice it doesn't. For sessions driven by the Python SDK, `get_session_info()` never returns an AI-generated title — it falls back to the first prompt. The bundled CLI never writes the `{"type":"ai-title", ...}` line into the session JSONL during SDK-driven sessions, so there is nothing for `get_session_info()` to surface.

The read side (`_internal/sessions.py`) is fine — it does look for `aiTitle` and exposes it through `custom_title`. The bug is the write side: that line is never created.

## Reproduction

- SDK: `claude-agent-sdk` `0.1.60`
- Bundled CLI: `cli.js` `2.1.111`
- Python 3.11.13, Linux

```python
import asyncio
from pathlib import Path
from claude_agent_sdk import (
ClaudeAgentOptions,
ClaudeSDKClient,
ResultMessage,
get_session_info,
)

async def main():
cwd = Path.cwd()
async with ClaudeSDKClient(options=ClaudeAgentOptions(cwd=str(cwd))) as client:
await client.query("Tell me about Python and its history")
session_id = None
async for msg in client.receive_response():
if isinstance(msg, ResultMessage):
session_id = msg.session_id

info = get_session_info(session_id, directory=str(cwd))
print(repr(info.summary)) # -> "Tell me about Python and its history"
print(repr(info.custom_title)) # -> None

asyncio.run(main())
```

`grep ai-title .jsonl` returns nothing — even after long sessions, even after `await asyncio.sleep(100)` before exit.

## Workaround

The CLI does support an explicit control request that generates and persists the title. We can fire it right after `client.query()` so the title is fetched in parallel with the assistant response:

```python
async with ClaudeSDKClient(options=options) as client:
await client.query(prompt)

# Fire title generation now; runs concurrently with the assistant turn.
title_task = asyncio.create_task(
client._query._send_control_request(
{
"subtype": "generate_session_title",
"description": prompt,
"persist": True,
}
)
)

async for msg in client.receive_response():
if isinstance(msg, ResultMessage):
session_id = msg.session_id

result = await title_task
print(result["title"])

# Now get_session_info() returns the AI title:
info = get_session_info(session_id, directory=str(cwd))
assert info.custom_title == result["title"]
```

This works reliably and the `ai-title` line is on disk by the time the call returns. But `_query._send_control_request` is private and the `generate_session_title` subtype isn't in the `SDKControlRequest` union, so we'd rather not depend on it.

## What we'd like

1. Confirm whether there's a public API we missed for getting the AI-generated title from the SDK. We checked the public exports (`get_session_info`, `list_sessions`, `rename_session`, and the methods on `ClaudeSDKClient`) and didn't find one.

2. If not, please add a public `client.get_session_title()` method that generates the title in parallel with the assistant response — the way the CLI's interactive UI already does it (it just doesn't persist the result to the JSONL).

3. With that in place, please make `get_session_info()` actually return the AI title for SDK-driven sessions, so the resolution from #161 holds.

Guia de contribuição

Nenhum guia de contribuição indexado para este repositório

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.