opencode
opencode copied to clipboard
[FEATURE]: Add systemPrompt option to SDK like Claude Agent SDK
Feature hasn't been suggested before.
- [x] I have verified this feature I'm about to request hasn't been suggested before.
Describe the enhancement you want to request
Summary
Add a systemPrompt option to the OpenCode SDK (@opencode-ai/sdk) that allows developers to directly customize or replace the system prompt, similar to how the Claude Agent SDK (@anthropic-ai/claude-agent-sdk) implements this feature.
Background
The Claude Agent SDK provides flexible system prompt customization through the systemPrompt option:
// Option 1: Complete replacement with custom prompt
for await (const message of query({
prompt: "Help me write code",
options: {
systemPrompt: "You are a Python specialist...",
},
})) {
console.log(message);
}
// Option 2: Use preset with append
for await (const message of query({
prompt: "Help me write code",
options: {
systemPrompt: {
type: "preset",
preset: "claude_code",
append: "Always include docstrings and type hints.",
},
},
})) {
console.log(message);
}
Current OpenCode SDK Limitation
Currently, the OpenCode SDK does not provide a direct way to modify the system prompt. Available workarounds include:
-
Agent configuration with
promptoption - Requires file-based configuration -
AGENTS.mdfiles - Project-level only, not programmatic -
noReply: truecontext injection - Only appends to conversation, doesn't modify system prompt
None of these provide the flexibility of directly setting systemPrompt in SDK calls.
Proposed API
import { createOpencode } from "@opencode-ai/sdk";
const { client } = await createOpencode();
// Option 1: Direct system prompt replacement
const session = await client.session.create({
body: {
title: "My session",
systemPrompt: "You are a specialized assistant for..."
},
});
// Option 2: Append to default system prompt
const session = await client.session.create({
body: {
title: "My session",
systemPrompt: {
type: "preset",
preset: "default",
append: "Additional instructions here..."
}
},
});
// Option 3: Per-prompt system prompt override
await client.session.prompt({
path: { id: session.id },
body: {
systemPrompt: "Custom system prompt for this interaction",
parts: [{ type: "text", text: "Hello!" }],
},
});
Benefits
- Programmatic control - Dynamically generate system prompts based on runtime conditions
- SDK parity with Claude Agent SDK - Easier migration and consistent developer experience
- Flexibility - No need for file-based configuration for simple customizations
-
Use cases:
- Building custom agents with specialized behaviors
- A/B testing different system prompts
- Multi-tenant applications with different prompts per user/org
- Reducing token usage by removing unnecessary default instructions
Related Issues
- #3195 - Dynamic system prompts for custom agents
- #7101 - Allow custom prompts in global, project or custom directories
- #1894 - Add optional system prompt environment injection
- #6105 - Allow for system prompts for models hosted elsewhere
This feature would address many of the concerns raised in these issues from an SDK perspective.