What is a system prompt? In AI, Claude and Claude Code, and how to write one

A system prompt sets an AI model's role and rules. System vs user prompts, how they work, system prompts in Claude and Claude Code, writing and caching them.

On the mic
On the mic

Key takeaways

  • A system prompt is the instruction block that sets an AI model's role, rules, context and output format for a whole conversation.
  • User prompts are the individual requests; the system prompt frames how the model handles all of them.
  • In the Claude API you pass it as the system parameter; in Claude Code you shape it with CLAUDE.md and settings.
  • System prompts can be cached to cut cost and latency when they are long and reused.
  • You do not strictly need one, but any real application benefits from a short, tested system prompt.

A system prompt is the set of instructions given to an AI model before the conversation that defines its role, rules, context and output style, such as "You are a tutor for first-year BCA students; explain with examples; never write assignments". User prompts are the individual messages that follow. This page explains system and user prompts, how system prompts work, how they apply in Claude and Claude Code, how to write and use one, whether they can be cached, whether you need one, and whether you can see an app's hidden system prompt.

What is a system prompt in AI?

A system prompt is a special instruction message that sets up how an AI model should behave for an entire conversation or application: who it is, what it should and should not do, what context it has, and how to format answers.

Also asked as: what is system prompt in ai · is system prompt cache

Applications use system prompts to turn a general model into a specific assistant: a support bot that only answers from the help centre, a code reviewer that lists issues by severity, or a tutor that asks questions instead of giving answers. Chat apps such as ChatGPT and Claude have their own system prompts written by the companies, and your custom instructions or project instructions add to them. In APIs, developers write system prompts themselves.

What is the difference between a system prompt and a user prompt?

The system prompt sets the rules and context for the whole interaction; the user prompt is the specific request in each turn. Models are trained to give system instructions higher priority and to apply them across all user messages.

Also asked as: what is system prompt and user prompt

For example, the system prompt says "Answer only from the provided handbook and cite section numbers; if the answer is not there, say so", and the user prompt asks "How many leaves can I take in a semester?". Put stable rules and context in the system prompt and task-specific details in user messages. Avoid repeating the same instructions in every user message; it wastes tokens and can confuse priorities.

How does a system prompt work?

The system prompt is placed at the start of the model's input, marked as system-level by the chat format. The model reads it with every turn, so its instructions shape each response, and training teaches models to follow system instructions over conflicting user requests.

Also asked as: how does system prompt work

It is not a separate program or hard rule; it is text the model conditions on. That is why clear, specific instructions work better than vague ones, why contradictory instructions cause inconsistent behaviour, and why applications still need code-level safeguards, such as validating outputs and restricting tools, for anything critical. Long conversations can dilute instructions, so important rules should be concise and prominent.

What is the system prompt in Claude?

In the Claude API, the system prompt is passed in a separate system parameter, not as a message, and Claude uses it to set role, tone, rules and context. In the Claude apps, Anthropic writes a system prompt and publishes it in its documentation's release notes.

Also asked as: what is system prompt in claude

Anthropic recommends using the system prompt to give Claude a role, such as "You are a senior data analyst", which improves performance in that domain, and putting task details in the user turn. With the API, you control the whole system prompt; in claude.ai you shape behaviour with profile preferences, project instructions and styles, which add to Anthropic's own prompt.

What is the system prompt in Claude Code?

Claude Code has its own built-in system prompt that sets it up as a coding agent with tools for reading files, editing and running commands. You customise its behaviour mainly through CLAUDE.md files in your project and home directory, plus settings and options that append instructions.

Also asked as: what is system prompt in claude code

A CLAUDE.md file holds project knowledge: build and test commands, coding conventions, architecture notes and rules such as "never commit directly to main". Claude Code reads it at the start of each session, so it works like a project-specific addition to the system prompt. For scripted use, command-line options let you append extra system instructions. Keep CLAUDE.md concise and current; outdated instructions mislead the agent.

How do I write a system prompt?

State the role, the goal, the rules, the context and the output format clearly, in that order, and keep it as short as possible while being complete. Then test it against real inputs and refine.

Also asked as: how to write system prompt

A template:

Role: You are a support assistant for a college's admissions office.
Goal: Answer applicants' questions accurately and briefly.
Rules: Use only the provided handbook passages. Cite section numbers.
If the answer is not in the passages, say so and suggest emailing admissions.
Never collect personal data such as phone numbers or ID numbers.
Format: 2 to 4 sentences, then "Source: section X".

Test with normal, tricky and adversarial questions, and change one instruction at a time.

How do I use a system prompt?

In APIs, pass it in the system field or as the first system or developer message; in chat apps, use custom instructions, project instructions or a custom assistant's instructions. Keep it in version control for applications.

Also asked as: how to use system prompt

Examples:

  • Claude API: client.messages.create(model=..., system="...", messages=[...]).
  • OpenAI API: instructions or a system or developer message, depending on the endpoint.
  • ChatGPT and Claude apps: custom instructions, Projects, custom GPTs or styles.
  • Agents: system prompt plus tool descriptions, which act as instructions too.

Pair the system prompt with retrieval for facts, so the prompt holds rules while documents hold knowledge.

Can a system prompt be cached?

Yes. Prompt caching lets providers reuse the processed form of a long, unchanging prompt prefix, such as a system prompt with reference material, which cuts cost and latency on later requests. Anthropic's API supports explicit cache markers, and OpenAI applies automatic caching for long repeated prefixes.

Caching works only for an identical prefix, so put stable content, such as system instructions, tool definitions and reference documents, at the start, and variable content, such as the user's question, at the end. Cached content expires after a period of inactivity. For applications that send the same long instructions with every request, caching can substantially reduce costs; check each provider's documentation for current rules and pricing.

Is a system prompt necessary?

Not strictly: models respond without one. But any real application benefits from a short system prompt that sets role, boundaries and format, because it makes behaviour more consistent and safer across users.

Also asked as: is system prompt necessary

For quick personal chats, the app's default plus clear user prompts is enough. For products, a tested system prompt is essential, along with code-level checks, because users will ask things you did not expect. Keep it focused: long, unfocused system prompts can make behaviour worse. If you find yourself writing pages of facts into it, move those facts into retrieval instead.

How do I get a system prompt?

For your own applications, the system prompt is whatever you write. For commercial chat apps, the companies decide whether to publish them; Anthropic publishes its Claude app system prompts in its documentation, which is the legitimate way to read them.

Also asked as: how to get system prompt

Attempts to trick an app into revealing hidden system prompts, known as prompt extraction, may break its terms of use, and the output may be partial or fabricated anyway. If you are building an app, assume your system prompt could be extracted: do not put secrets, API keys or private data in it, and enforce important rules in code, not only in text.

Sources

  1. Anthropic, Giving Claude a role with a system promptdocs.anthropic.com
  2. Anthropic, Prompt cachingdocs.anthropic.com
  3. Anthropic, Claude Code overviewdocs.anthropic.com
  4. Anthropic, System prompts release notesdocs.anthropic.com
  5. OpenAI, Prompt engineering guideplatform.openai.com
Pranjul Rathour
Pranjul Rathour
GenAI Engineer · India

GenAI engineer and AI product builder with 2+ years shipping production-grade AI systems: RAG pipelines, fine-tuned LLMs, hybrid retrieval and multi-modal apps across vision, speech and OCR, architected end to end from ingestion to deployment. Leads engineering for SCULT INDIA's 14-member team, founded the 500+ member TechVerse Enclave community and has mentored 200+ students. Three hackathon first prizes: Changethon 2025 (IIT Roorkee), Product Genesis at Vividhotsava 2025 (CSJMU) and BYTEBATTLE (MeetKats).

Open to GenAI roles, hackathon judging, mentorship sessions and guest talks at colleges. For campus sessions the inviting institution covers the visit end to end: travel (a First AC train ticket for journeys up to five hours, a flight for anything longer), accommodation, meals, and pickup and drop; the honorarium and workshop fees are negotiable on WhatsApp or on the call, and requests are welcome from institutions that can cover the visit this way. Email pranjulrathour41@gmail.com.

Keep reading

More on Shipping AI apps

All Shipping AI apps guides →
Campus talks · hackathon judging · mentoring

Want this as a live session at your college?

Open to GenAI roles, hackathon judging, mentorship sessions and guest talks at colleges. For campus sessions the inviting institution covers the visit end to end: travel (a First AC train ticket for journeys up to five hours, a flight for anything longer), accommodation, meals, and pickup and drop; the honorarium and workshop fees are negotiable on WhatsApp or on the call, and requests are welcome from institutions that can cover the visit this way.

Pranjul Rathour, GenAI engineer in India