anthropics / anthropics/claude-agent-sdk-typescript
Feature Request: Hook API for intercepting and customizing built-in attachment reminders
- Lingua principale
- Shell
- Stelle
- 1.8k
- Fork
- 226
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
## Summary
The SDK injects several built-in attachment types (`plan_mode`, `auto_mode`, `todo_reminder`, `verify_plan_reminder`, etc.) into the conversation context at API call time. Currently there is no way for SDK consumers to intercept, suppress, replace, or customize the rendered text of these attachments before they reach the model.
## Current Behavior
Built-in attachments like `plan_mode` are recorded in the session JSONL as structured metadata only:
```json
{ "type": "plan_mode", "reminderType": "sparse", "planFilePath": "...", "planExists": false }
```
The actual rendered instruction text is generated internally at API call time with no observable hook point. Consumers cannot:
- Read what text was rendered (without intercepting `globalThis.fetch`)
- Suppress a specific attachment type
- Replace the rendered text with custom content
- Adjust the `full`/`sparse` cadence
## Use Cases
**1. Custom plan mode workflow** An extension embedding the SDK with its own planning UX wants to replace the SDK's 5-phase workflow instructions with domain-specific ones, while still using `permissionMode: 'plan'` for permission enforcement.
**2. Localization** The rendered reminder text is English-only. An application targeting non-English users has no way to translate or replace it.
**3. Reducing token noise** An embedding application already injects its own system prompt covering the same ground as `todo_reminder` or `context_efficiency`. The SDK still injects them redundantly, consuming tokens on every turn.
## Proposed API
### Option A — Per-type hooks (full control)
```ts
query({
attachmentHooks: {
// Return null to suppress, return modified attachment to replace rendered text
plan_mode: (attachment) => ({
...attachment,
customContent: `My custom plan mode instructions here`,
}),
todo_reminder: () => null, // suppress entirely
},
});
```
### Option B — Read-only observability hook (minimal footprint)
```ts
query({
onAttachmentRendered: (type, renderedText) => {
console.log(`[${type}]`, renderedText);
},
});
```
### Option C — Catch-all interceptor
```ts
query({
onAttachment: (attachment) => attachment | null,
});
```
## Full List of Attachment Types Affected
From SDK source (`cli.js`), the following attachment types currently render text with no hook point:
| Type | Rendered content |
| ---------------------- | ------------------------------------------------------------------ |
| `plan_mode` | Full 5-phase workflow (`reminderType: "full"`) or sparse one-liner |
| `auto_mode` | Auto-mode instructions (same full/sparse cadence) |
| `plan_mode_exit` | Exit notification + plan file path |
| `plan_mode_reentry` | Re-entry notification |
| `verify_plan_reminder` | Post-implementation plan verification prompt |
| `auto_mode_exit` | Auto mode exit notification |
| `todo_reminder` | Numbered TODO list with statuses |
| `date_change` | Date change notification |
| `output_token_usage` | Token usage stats |
| `team_context` | Team collaboration context |
| `reminder` | Generic content string |
| `deferred_tools_delta` | Deferred tool availability notification |
Types that currently render nothing (`[]`) and could be activated by consumer: `context_efficiency`, `autocheckpointing`, `background_task_status`, `compaction_reminder`
## Environment
- Package: `@anthropic-ai/claude-agent-sdk`
- Context: VS Code extension embedding the SDK via `require('@anthropic-ai/claude-agent-sdk')`
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Valutazione
Questa issue non è ancora stata valutata.