Claude Prompting Guide

A practical reference for crafting effective prompts with Claude (Anthropic). Focused on sysadmin, IT ops, and scripting use cases.

Overview

Claude excels at sustained reasoning, code generation, structured output, and following multi-step instructions precisely. Key differentiators: large context window (up to 200K tokens), strong XML/markdown handling, and minimal tendency to hallucinate compared to smaller models.

Prompt Structure

Every Claude request has three components:

Role Purpose Example
System Sets behavior, persona, constraints You are a senior Linux sysadmin…
User The actual request or question Write a cron job that rotates logs…
Assistant Prefill to steer format “`bash\n#!/bin/bash

XML Tag Technique

Claude understands XML tags natively. Use them to separate context from instructions:

<context>
Server: Ubuntu 22.04 LTS, 16GB RAM, running Nginx 1.24 and PostgreSQL 15.
Issue: DB queries slowing down after 72h uptime — CPU stays under 40%.
</context>

<task>
Diagnose the likely cause and provide a step-by-step investigation plan
using only CLI tools available on the server.
</task>

Sysadmin Prompt Templates

Task Prompt Pattern
Bash script Write a bash script that [task]. Include error handling, set -euo pipefail, and comment each section. Target: Ubuntu 22.04.
Log analysis Analyze this /var/log/syslog excerpt and identify: (1) root cause, (2) affected services, (3) remediation steps. <log>[paste]</log>
Ansible playbook Write an Ansible playbook to [task] for hosts in group [group]. Use best practices: become: yes, tags, handlers for service restarts.
Cron expression Generate a cron expression for: [schedule description]. Explain each field. Include the line ready to paste into crontab.
Nginx config Generate an Nginx server block for [domain] that: [requirements]. Include security headers, HTTPS redirect, and rate limiting.

Chain-of-Thought Prompting

Add Think step by step before answering. or Before writing code, outline your approach. to get more reliable, auditable answers for complex tasks.

Best Practices

  • Be explicit about output format: “Return ONLY valid JSON, no prose.”
  • State constraints upfront: OS version, package versions, no root access, etc.
  • Use role priming: “You are a security-focused Linux engineer…”
  • Break large tasks: ask for an outline first, then expand each section.
  • For code review: paste the code inside <code> tags and ask for specific feedback.
  • Use extended thinking (claude.ai) for architecture decisions or complex debugging.