claude-agent-sdk-python icon indicating copy to clipboard operation
claude-agent-sdk-python copied to clipboard

How to use cache context?

Open amitok2 opened this issue 1 year ago • 1 comments

Hey, how to use cached prompts?I have a fixed long system prompt for all request, i want it to cache it and use it. how to pass this cache prompt to claude code sdk.

I used to make this system config when i used regualr claude api, but now in claude code i see the system prompt only get string type. Image

amitok2 avatar Jul 23 '25 09:07 amitok2

Prompt caching is handled automatically by the SDK and the underlying Claude Code CLI. The system prompt and tool definitions are automatically cached by the API — you don't need to configure cache breakpoints manually like with the direct Claude API.

When you use system_prompt in ClaudeAgentOptions, the SDK passes it to the CLI which handles caching transparently. You can verify caching is working by checking cache_read_input_tokens in the ResultMessage.usage field.

The SDK intentionally provides a simpler interface than the raw API — you pass a string system prompt and caching is handled for you. Closing as answered.

qing-ant avatar Mar 24 '26 12:03 qing-ant