env.dev

System Prompts for Agentic Coding

Effective system prompts for LLM coding agents. Structure, constraints, and output formatting for reliable code generation.

Why System Prompts Matter

System prompts define how an LLM coding agent behaves across an entire session. They set the role, establish constraints, define output formats, and prevent common failure modes. A well-crafted system prompt is the difference between useful code and generic slop.

Core Components

  • Role definition — e.g. "You are a senior TypeScript developer"
  • Tech stack constraints — e.g. "Use React 19, Tailwind v4"
  • Output format rules — e.g. "No default exports, use named exports"
  • Error handling patterns — e.g. "Return Result types, no exceptions"
  • Code style examples — show the LLM what good code looks like
  • Forbidden patterns — explicitly list what NOT to do

Example System Prompt

System Prompt
You are a senior TypeScript developer. Follow these rules strictly:

TECH STACK: React 19, TypeScript strict, Tailwind CSS v4, Vitest
EXPORTS: Always named exports, never default exports
TYPES: No `any` — use `unknown` and type guards
ERRORS: Return Result<T, E> types, never throw from library code
TESTING: Write tests for all exported functions
IMPORTS: Use explicit file extensions (.ts, .tsx)
FORBIDDEN: No barrel files, no class components, no enums (use const objects)

When asked to implement something:
1. List assumptions and clarify if needed
2. Write the types first
3. Implement with tests
4. Note any edge cases not covered

Anti-Patterns to Avoid

Vague Instructions

"Write good code" tells the LLM nothing. Be specific: "Use early returns, max 20 lines per function, no nested ternaries."

Missing Constraints

Without import/dependency constraints, the LLM will import whatever it wants. Specify what's allowed.

No Examples

A single code example is worth 100 words of description. Show the LLM your preferred style.

Frequently Asked Questions

What makes a good system prompt for coding?

A good coding system prompt defines the role, specifies the tech stack, sets output format constraints, and includes rules about error handling, naming conventions, and code style.

How long should a system prompt be?

As long as needed. Effective coding system prompts for LLMs are often 500-2000 words. The key is specificity — vague prompts produce vague code.