Last updated

Claude Prompting Guide

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

▶ Watch the demo: Prompt Lab: the 4-part prompt formula (25 sec)Watch on YouTubeSubscribe

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

Last updated October 2026.

FAQ

How do I write better prompts for this AI?

Give context, a clear task and the output format. XML-style tags help separate instructions from data.

Can it read long documents?

Yes. It handles long inputs well; put the document first and your question at the end.