anthropics / anthropics/claude-agent-sdk-typescript

V2 API: How to interrupt an agent without closing the session?

Aperta
#120 0 commenti 4 reazioni 0 assegnatari Vedi su GitHub
documentation enhancement question
Lingua principale
Shell
Stelle
1.8k
Fork
226
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

## Question

With the V1 API, we have `query.interrupt()` to gracefully interrupt an ongoing operation while keeping the session alive for subsequent prompts.

In the V2 API (`unstable_v2_createSession`), the `SDKSession` interface only exposes:
- `send()` - send a message
- `stream()` - stream messages
- `close()` - close the session

**How can we interrupt an ongoing operation in V2 without closing the entire session?**

Our use case: We're building an agent wrapper that needs to support user-initiated interrupts (like Ctrl+C in CLI) while keeping the session alive for follow-up prompts.

## Current Workaround

We're currently calling `session.close()` on interrupt, but this forces the user to resume the session manually, which creates a new session ID and loses the in-progress context.

## Suggestion

Could V2 add an `interrupt()` method similar to V1's `Query.interrupt()`?

```typescript
interface SDKSession {
// ... existing methods
interrupt(): Promise; // Gracefully stop current operation
}
```

---

## Documentation Issue

The V2 preview docs at https://platform.claude.com/docs/en/agent-sdk/typescript-v2-preview say:

> **Feedback**
> Share your feedback on the V2 interface before it becomes stable. Report issues and suggestions through [GitHub Issues](https://github.com/anthropics/claude-code/issues).

This links to `claude-code` issues instead of `claude-agent-sdk-typescript`. Should probably be updated to point here.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.