Assign Claude a Role for Better Specialised Output
Framing your prompt with a specific role can significantly sharpen the quality of Claude's output. It's not magic — it tells Claude which angle to take and which expertise to emphasise.
You are a senior security engineer doing a code audit. Review
`app/Http/Controllers/AuthController.php` for authentication
vulnerabilities, focusing on token handling and session fixation.
Role prompts work especially well for reviews, rewrites, and design decisions where the perspective matters as much as the task. Be specific — "senior PHP developer who cares about readability" beats "expert developer" every time.
Some roles that work particularly well:
# For documentation
You are a technical writer. Rewrite this function's docblock so a
junior developer can understand it without reading the implementation.
# For infrastructure
You are a DevOps engineer. Audit this Dockerfile for security issues
and unnecessary build steps that slow down CI.
# For architecture
You are a staff engineer reviewing a pull request. Give direct,
actionable feedback — don't soften it.
The role doesn't need to go at the very start of your prompt, but putting it first helps. Think of it as setting the lens before asking Claude to look through it.
The role you assign shapes the perspective Claude brings — choose it deliberately.
Log in to leave a comment.
Before asking Claude to scaffold a new feature, point it at your existing code first — it will match your naming, structure, error handling, and test patterns exactly rather than defaulting to framework boilerplate.
Give Claude the full picture upfront before it writes any code, so it builds the right thing the first time with fewer correction rounds.
Complex prompts are unreadable as escaped single-liners. Use shell HEREDOCs to write clean, structured prompts directly in your scripts.