Claude API Custom Instructions for Agents
When you're building an agent on top of the Claude API, "custom instructions" means the persistent guidance you give the model about its role, constraints, and behavior — separate from the per-turn user messages. This is handled through the system parameter in the Messages API, not through chat-style "personalization" settings like you'd find in a consumer app. If you're building an agent that needs to follow consistent rules across every call — tone, output format, tool-use policy, safety boundaries — the system prompt is where that logic lives.
The short answer: you set custom instructions once per request (or once per session, if you're managing conversation state) by passing a system field alongside your messages array. Claude treats this as the highest-priority context for the entire interaction, and it doesn't count against the conversation history the way user/assistant turns do. For agents specifically, this is also where you define tool-calling behavior, multi-step task structure, and guardrails that shouldn't drift as the conversation grows.
Where custom instructions live in the API
The Claude Messages API has three relevant pieces for agent behavior:
system— the instruction layer. Role, constraints, formatting rules, tool policy.messages— the actual conversation turns (user/assistant).tools— structured definitions of functions the agent can call.
Custom instructions for an agent almost always belong in system, not buried inside the first user message. Mixing them into user turns works for quick tests but breaks down once you have multi-turn conversations, since the model has to re-infer intent from conversation history instead of reading it from a stable, authoritative block.
curl https://api.anthropic.com/v1/messages \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{
"model": "claude-opus-4",
"max_tokens": 1024,
"system": "You are a deployment agent for a CI/CD pipeline. You only take actions through the provided tools. Never guess at file paths — always check with the list_files tool first. Respond in plain text, no markdown, unless asked for code.",
"messages": [
{"role": "user", "content": "Deploy the latest build to staging."}
]
}'
That system string is your custom instruction set. It's reused on every request to this agent, regardless of what the user asks.
Structuring instructions for agentic behavior
Generic "be helpful and concise" instructions work for chatbots. Agents need more specific operational rules because they're taking actions, not just generating text. A few patterns that hold up well in production:
Define the decision boundary. Tell the agent explicitly when to act versus when to ask for confirmation:
You manage customer refunds. For refunds under €50, use the issue_refund tool directly.
For refunds €50 and above, respond with a confirmation request instead of calling the tool.
Pin the output contract. If downstream code parses the response, say so:
Always respond with a single JSON object matching this shape: {"action": string, "params": object, "reasoning": string}.
Do not include any text outside the JSON object.
State tool-use priority. When an agent has multiple tools, ambiguity about which to use first causes most of the weird behavior you'll see in testing:
Check the cache_lookup tool before calling any external API. Only call fetch_live_data if cache_lookup returns null.
Set the failure mode. Agents left without instructions for failure cases tend to either hallucinate success or hang indefinitely:
If a tool call fails, report the error to the user in one sentence and stop. Do not retry more than once.
These aren't exotic prompt-engineering tricks — they're just explicit rules written where the model will consistently see them, on every single call.
Keeping instructions consistent across sessions
One practical issue teams run into: custom instructions that live in application code (hardcoded strings) drift out of sync across environments, or get forgotten when someone rotates a key or spins up a new service. If multiple services or team members are calling Claude on behalf of the same product, it helps to centralize the system prompt and treat it like configuration, not a magic string buried in a function.
This is one of the areas where routing calls through SubToAPI helps if you're already using your Claude subscription to power internal tools or agents. SubToAPI exposes your Claude access as a standard HTTPS API with sub_live_... application keys, so you can centralize the system prompt per application key and give every team member or service a consistent instruction set without copy-pasting prompt strings between codebases. See the quickstart for setup and the messages docs for the full request shape.
const res = await fetch("https://api.subtoapi.app/v1/messages", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.SUBTOAPI_KEY}`,
"content-type": "application/json",
},
body: JSON.stringify({
model: "claude-opus-4",
max_tokens: 1024,
system: "You are a support triage agent. Classify each ticket as billing, technical, or account. Call the create_ticket tool with the classification. Never respond to the customer directly.",
messages: [{ role: "user", content: ticketText }],
}),
});
If your agent streams output or uses tools, the same system instructions apply unchanged — check the streaming guide and tools guide for the request-level details.
Testing instructions like code
Treat your system prompt as a versioned artifact, not a one-off string. Keep it in a config file or database row, log which version was used for each request (alongside usage metadata, if your provider gives you that), and run a small regression suite of representative inputs whenever you change it. Agent instructions tend to fail silently — the model doesn't error out, it just picks a slightly different path — so you won't catch regressions without deliberately testing edge cases: ambiguous user requests, tool failures, and multi-step tasks where the agent has to decide whether it's done.
Questions
Do custom instructions count against the context window? Yes. The system field is tokenized and counted like any other input, so keep it focused — long, sprawling instructions eat into the budget available for conversation history and tool results.
Can I change instructions mid-conversation? Yes, you can send a different system value on a later request in the same conversation, but it's rarely a good idea for agents — inconsistent instructions across turns cause unpredictable behavior. If instructions genuinely need to change, it's usually a sign you should split the task into separate agents.
Should tool definitions go in the system prompt or the tools field? The tools field, not system. Use tools for the structured function schema and system for policy about when and how to use those tools — the model handles both together, but mixing schema definitions into free text makes them harder to validate and update.