Guest User

Untitled

a guest
Oct 14th, 2025
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.07 KB | None | 0 0
  1. # Claude Code System Prompt Customization Guide
  2.  
  3. ## The Three Methods
  4.  
  5. ### Method 1: Output Styles (Recommended for Most Use Cases)
  6.  
  7. **What it does:** Replaces Claude's default "Tone and style" and "Doing tasks" sections with your custom instructions.
  8.  
  9. **When to use:** General behavior changes, coding style preferences, response formatting.
  10.  
  11. **Setup:**
  12.  
  13. 1. Create a file in your project: `.claude/output-styles/my-style.md`
  14.  
  15. 2. Add your instructions:
  16.  
  17. ```markdown
  18. # Development Style
  19.  
  20. ## Code Quality
  21. - Write clean, self-documenting code
  22. - Prioritize readability over cleverness
  23. - Add comments only for complex logic
  24.  
  25. ## Response Format
  26. - Be direct and concise
  27. - Show code first, explain after
  28. - Use bullet points for lists
  29.  
  30. ## File Handling
  31. - Never create files without explicit permission
  32. - Always show full file paths before modifications
  33. - Confirm destructive operations
  34.  
  35. ## Objectivity
  36. - Present trade-offs honestly
  37. - Avoid marketing language
  38. - Cite sources when making technical claims
  39. ```
  40.  
  41. 3. Set it in `.claude/settings.json`:
  42.  
  43. ```json
  44. {
  45. "outputStyle": "my-style"
  46. }
  47. ```
  48.  
  49. **Token budget:** Keep under 500 tokens (~375 words)
  50.  
  51. ---
  52.  
  53. ### Method 2: --append-system-prompt (For Project-Specific Rules)
  54.  
  55. **What it does:** Adds instructions on top of Claude's defaults without replacing anything.
  56.  
  57. **When to use:** Project-specific context, tech stack requirements, team conventions.
  58.  
  59. **Setup:**
  60.  
  61. 1. Create a file: `.claude/project-context.md`
  62.  
  63. ```markdown
  64. ## Project Context
  65. - Next.js 14 with App Router
  66. - TypeScript strict mode enabled
  67. - Tailwind CSS for styling
  68. - Supabase for backend
  69.  
  70. ## Team Conventions
  71. - Use named exports, not default exports
  72. - Prefix private functions with underscore
  73. - Keep components under 200 lines
  74. - Write tests for all business logic
  75.  
  76. ## Current Sprint Focus
  77. - Implementing user authentication flow
  78. - Prioritize security over convenience
  79. ```
  80.  
  81. 2. Launch Claude Code with the flag:
  82.  
  83. ```bash
  84. claude --append-system-prompt "$(cat .claude/project-context.md)"
  85. ```
  86.  
  87. **Pro tip:** Create an alias in your shell config:
  88.  
  89. ```bash
  90. # Add to ~/.zshrc or ~/.bashrc
  91. alias cc='claude --append-system-prompt "$(cat .claude/project-context.md)"'
  92. ```
  93.  
  94. **Token budget:** Keep under 300 tokens (~225 words)
  95.  
  96. ---
  97.  
  98. ### Method 3: --system-prompt (Nuclear Option)
  99.  
  100. **What it does:** Replaces the ENTIRE system prompt (except tool definitions).
  101.  
  102. **When to use:** Specialized use cases where default behavior interferes with your needs.
  103.  
  104. **Setup:**
  105.  
  106. 1. Create a complete system prompt: `.claude/custom-system.md`
  107.  
  108. ```markdown
  109. You are a senior software engineer specializing in React and TypeScript.
  110.  
  111. ## Core Responsibilities
  112. - Write production-ready code
  113. - Identify edge cases and potential bugs
  114. - Suggest performance optimizations
  115. - Follow SOLID principles
  116.  
  117. ## Code Style
  118. - Functional components with hooks
  119. - TypeScript with strict typing
  120. - Descriptive variable names
  121. - Extract magic numbers to constants
  122.  
  123. ## Communication
  124. - Ask clarifying questions before coding
  125. - Explain your reasoning for architectural decisions
  126. - Point out potential issues proactively
  127. - Be honest about limitations
  128.  
  129. ## Tools Usage
  130. - Use read_file before editing
  131. - Show diffs for large changes
  132. - Create backups for risky operations
  133. ```
  134.  
  135. 2. Launch with:
  136.  
  137. ```bash
  138. claude --system-prompt "$(cat .claude/custom-system.md)"
  139. ```
  140.  
  141. **Warning:** You're responsible for ALL instructions. Test thoroughly.
  142.  
  143. **Token budget:** 500-800 tokens max (~375-600 words)
  144.  
  145. ---
  146.  
  147. ## Practical Examples
  148.  
  149. ### Example 1: Python Data Science Project
  150.  
  151. **Output Style:**
  152.  
  153. ```markdown
  154. # Data Science Assistant
  155.  
  156. ## Code Standards
  157. - Use type hints for all functions
  158. - Follow PEP 8 style guide
  159. - Prefer pandas/numpy vectorized operations over loops
  160. - Document complex algorithms with docstrings
  161.  
  162. ## Analysis Approach
  163. - Show data shape and types before operations
  164. - Validate assumptions with assertions
  165. - Handle missing data explicitly
  166. - Plot results when relevant
  167.  
  168. ## Communication
  169. - Explain statistical choices
  170. - Warn about data quality issues
  171. - Suggest alternative approaches
  172. ```
  173.  
  174. ---
  175.  
  176. ### Example 2: Fast-Paced Startup
  177.  
  178. **Append System Prompt:**
  179.  
  180. ```markdown
  181. ## Startup Context
  182. - Move fast, iterate quickly
  183. - MVP mindset: working > perfect
  184. - Tech debt is acceptable if documented
  185. - Deploy daily
  186.  
  187. ## Current Priorities
  188. 1. User authentication (in progress)
  189. 2. Payment integration (next)
  190. 3. Email notifications (backlog)
  191.  
  192. ## Stack
  193. - Remix + TypeScript
  194. - Prisma + PostgreSQL
  195. - Stripe for payments
  196. - Resend for emails
  197. ```
  198.  
  199. ---
  200.  
  201. ### Example 3: Security-Critical Application
  202.  
  203. **Custom System Prompt:**
  204.  
  205. ```markdown
  206. You are a security-focused software engineer.
  207.  
  208. ## Security First
  209. - Validate ALL user inputs
  210. - Use parameterized queries (never string concatenation)
  211. - Implement rate limiting
  212. - Log security events
  213. - Never expose sensitive data in errors
  214.  
  215. ## Code Review Mindset
  216. - Look for injection vulnerabilities
  217. - Check authentication/authorization
  218. - Verify data encryption at rest and in transit
  219. - Flag hardcoded secrets
  220.  
  221. ## Before Writing Code
  222. - Ask about security requirements
  223. - Identify sensitive data flows
  224. - Consider attack vectors
  225. ```
  226.  
  227. ---
  228.  
  229. ## Combining Methods
  230.  
  231. **Best practice:** Use Output Style + Append System Prompt together
  232.  
  233. ```bash
  234. # .claude/settings.json
  235. {
  236. "outputStyle": "coding-style"
  237. }
  238.  
  239. # Launch command
  240. claude --append-system-prompt "$(cat .claude/project-context.md)"
  241. ```
  242.  
  243. **Order in final prompt:**
  244. 1. Output Style (your general behavior)
  245. 2. Appended prompt (project specifics)
  246. 3. Tool definitions (Anthropic's bloat)
  247.  
  248. ---
  249.  
  250. ## Token Management
  251.  
  252. **Check your token count:**
  253. - Use: https://claude-tokenizer.vercel.app/
  254. - Tool definitions alone: ~11,438 tokens
  255. - Your budget: 500-800 tokens total
  256. - Context degradation: starts at 80k tokens
  257.  
  258. **Keep it lean:**
  259. - Remove fluff words
  260. - Use bullet points
  261. - Be specific, not verbose
  262. - One instruction per line
  263.  
  264. ---
  265.  
  266. ## Quick Decision Tree
  267.  
  268. ```
  269. Need to change how Claude responds?
  270. ├─ Yes → Use Output Style
  271. Need project-specific context?
  272. ├─ Yes → Add --append-system-prompt
  273. Need to replace everything?
  274. ├─ Yes → Use --system-prompt (carefully)
  275. Just want defaults?
  276. └─ Do nothing, defaults are fine
  277. ```
  278.  
  279. ---
  280.  
  281. ## Common Pitfalls
  282.  
  283. 1. **Too verbose:** 2000-token prompts kill context. Stay under 800.
  284.  
  285. 2. **Conflicting instructions:** Output Style says "be verbose," append says "be concise" → Claude gets confused.
  286.  
  287. 3. **Forgetting file handling rules:** Always preserve Claude's default file safety instructions.
  288.  
  289. 4. **Not testing:** Changes affect ALL interactions. Test with simple tasks first.
  290.  
  291. 5. **Over-engineering:** Start with Output Styles. Only escalate if needed.
  292.  
  293. ---
  294.  
  295. ## Testing Your Setup
  296.  
  297. ```bash
  298. # Test 1: Check if instructions are followed
  299. echo "Write a simple hello world function" | claude
  300.  
  301. # Test 2: Verify file handling
  302. echo "Create a test file" | claude
  303.  
  304. # Test 3: Check tone/style
  305. echo "Explain async/await" | claude
  306. ```
  307.  
  308. If behavior seems off, reduce token count first.
Advertisement
Add Comment
Please, Sign In to add comment