How System Prompts Work
In the API, the system prompt is a separate message with role "system" (OpenAI) or the system parameter (Anthropic). It is processed before any user messages and establishes baseline behavior for the entire conversation. The model treats system instructions as higher priority than user messages.
A good system prompt covers: who the model is (role/persona), what it should do (core task), what it should not do (constraints/guardrails), how to format responses (output structure), and how to handle edge cases (error behavior, uncertainty).
Writing Effective System Prompts
Be specific and concrete. "You are a helpful assistant" is nearly useless — every model defaults to that behavior. Instead: "You are a senior TypeScript engineer reviewing pull requests. Point out bugs, security issues, and performance problems. Ignore style nitpicks. Use code blocks for suggested fixes."
Use negative constraints sparingly. "Do not hallucinate" is less effective than "If you are not confident in a fact, say 'I'm not sure about this' and explain what you do know." Give the model a constructive alternative to the behavior you want to prevent.
System Prompts in Production
Production system prompts are engineering artifacts, not casual instructions. Version control them. Test them against regression suites. A/B test significant changes. Track prompt performance metrics (accuracy, user satisfaction, cost) just like you would track code performance.
Claude Code uses CLAUDE.md files as project-level system prompts — they persist across sessions and define project-specific behavior rules. This pattern of durable, version-controlled system instructions is becoming the standard for AI-augmented development.