The model sees a constructed input pipeline, not one giant static string
What You’ll Learn
- Why a single static system prompt doesn’t scale
- How to build a system prompt pipeline with multiple stages
- How to inject dynamic context based on current state
The Problem
A single monolithic system prompt tries to cover everything: role, tools, conventions, memory, skills. It gets big, stale, and hard to maintain. Adding one more rule means scrolling through 2000 lines.
The Solution
A system prompt pipeline that assembles the prompt from composable stages:
Pipeline stages:
+------------------+
| 1. Identity | "You are a coding agent"
+------------------+
| 2. Environment | "Working directory: /project"
+------------------+
| 3. Tools | "Available: bash, read, write..."
+------------------+
| 4. Memory | "User prefers pytest"
+------------------+
| 5. Skills (names)| "Skills: git, test, code-review"
+------------------+
| 6. Rules | "Always commit after changes"
+------------------+
How It Works
-
Each stage is a function that returns a string (or nothing).
-
A
SystemPromptBuilderchains stages together.
class SystemPromptBuilder:
def __init__(self):
self.stages = []
def add(self, stage_fn):
self.stages.append(stage_fn)
def build(self, context: dict) -> str:
parts = []
for stage in self.stages:
result = stage(context)
if result:
parts.append(result)
return "\n\n".join(parts)
- Context (current file, git branch, memory) flows through the pipeline and each stage can use it.
What Changed From s09
| Component | Before (s09) | After (s10) |
|---|---|---|
| System prompt | Static string | Composable pipeline |
| Maintenance | Edit giant block | Add/remove stages |
| Context | Fixed at start | Dynamic per turn |
Try It
cd learn-claude-code
python agents/s10_system_prompt.py
What do you know about this project?(check system prompt assembly)- Add a new rule stage and verify it appears in the prompt
Load a skill and verify the system prompt updated
Key Takeaway
The model sees a constructed input pipeline, not one giant static string. Compose your system prompt from independent, context-aware stages.