Tips of Using Claude Code

Prompt Structure

A well-structured prompt dramatically improves output quality. Use this ordering as a template:

  1. Role + high-level task (1–2 sentences) — Establish who Claude is and what it’s doing
  2. Dynamic / retrieved content — Paste in the data, documents, or context Claude needs
  3. Detailed task instructions — Specific rules, constraints, and goals
  4. Examples / n-shot (optional) — Show Claude what good output looks like
  5. Repeat critical instructions — Restate the most important rules at the end; Claude weighs recent tokens more
  6. Thinking step — Ask Claude to reason before answering (e.g. “Think step by step”)
  7. Output format — Specify exactly how the response should be structured

Why this order? Claude reads the full prompt before responding. Putting role and context first primes the model; repeating critical instructions last ensures they’re fresh. This structure also helps keep prompts lean, reducing wasted context

Clarity & Specificity

Use XML Tags to Separate Content

Wrap distinct sections of your prompt in XML tags to give Claude clear structural boundaries.

<document>
  [paste your content here]
</document>
<instructions>
  Summarize the document above in 3 bullet points.
</instructions>

Why: XML tags eliminate ambiguity about where one section ends and another begins. Claude is explicitly trained to recognize them, making parsing more reliable than using plain text separators like “—”. This is especially important when mixing retrieved/dynamic content with instructions.


Use Examples (N-Shot Prompting)

Provide 1–3 examples of the input/output pattern you want, wrapped in XML tags.

<examples>
  <example>
    <input>Rephrase: "The meeting was bad."</input>
    <output>The meeting did not go as expected.</output>
  </example>
</examples>

Why: Examples are the fastest way to communicate format, tone, and style constraints. Even one example (“one-shot”) significantly narrows Claude’s output distribution toward what you actually want.


Use Positive Instructions

Tell Claude what to do rather than only what not to do.

  • ❌ “Don’t be vague.”
  • ✅ “Be specific — include concrete examples and exact values.”

Why: Claude responds better to affirmative guidance. Negative-only constraints leave too much ambiguity about what the desired behavior actually is.


Specify Output Format Explicitly

Tell Claude the exact format you want: JSON, markdown table, numbered list, plain prose, code block, etc.

Respond only with a JSON object. No preamble, no markdown fences.

Why: Without format instructions, Claude defaults to whatever feels natural — which may not match your downstream use case. Being explicit prevents wasted tokens on conversational wrap-up text.


Reasoning & Chain-of-Thought

Ask Claude to Think Step by Step

Add a thinking instruction before your output format.

Before answering, reason through the problem step by step inside <thinking> tags, then give your final answer.

Why: Chain-of-thought prompting significantly improves accuracy on complex or multi-step tasks. The reasoning trace also makes it easier to spot where Claude went wrong if the output is off.


Context Management

Clear Context Often

Start a new conversation when the task changes significantly. Don’t let unrelated prior exchanges accumulate in the context window.

Why: Every message in the conversation counts against your context limit. Stale or irrelevant earlier messages can dilute attention and degrade output quality on the current task. Clearing context is one of the highest-leverage ways to reduce token usage.


Use Projects for Persistent Instructions

Projects act as a container for custom system instructions and reference documents that persist across conversations.

Caveats:

  • Project documents and instructions still count against your context window on every turn.
  • Keep project instructions concise — every token in the system prompt is a token not available for your actual task.

Why: Projects are useful for team-shared context (style guides, codebases, personas) that would otherwise be tedious to re-paste each session.


Put Long Documents Before Instructions

When working with large reference material, place it near the top of the prompt, before your detailed instructions.

<reference_doc>
  [long document here]
</reference_doc>
<task>
  Based on the document above, answer the following question...
</task>

Why: Claude’s attention to content near the end of a long prompt is stronger than to content buried in the middle. Putting instructions last (after the data) keeps them “fresh.” This also helps reduce wasted context by preventing Claude from re-summarizing the document unnecessarily.


Use <cache_control> for Repeated Large Documents (API)

If you’re making repeated API calls with the same large document or system prompt, use prompt caching with the cache_control parameter.

Why: Cached prompt prefixes are not re-processed on every call, dramatically reducing both latency and token costs. This is the most direct way to reduce context/cost when reusing static content across many requests.


Artifacts

Artifacts are self-contained outputs — apps, documents, code — that render in a side pane alongside the conversation.

Use an Artifact when:

  • The content is complex enough to stand on its own (a full React component, a report, a chart)
  • The user will interact with or iterate on the output separately from the chat
  • The content doesn’t need conversational context to be understood

Don’t use an Artifact for:

  • Short answers, quick summaries, or inline code snippets
  • Content that is part of the natural conversational flow

Why: Artifacts reduce clutter in the chat thread and give the output a stable, shareable surface. They also help keep the conversation context lighter by separating the deliverable from the dialogue.


Skills (Claude Code / Custom Setups)

Skills are bundled instruction sets — typically a SKILL.md file — that tell Claude how to perform a specific class of task (e.g., creating .docx files, building Epic-branded slides).

How they’re used: A skill file is read by Claude at the start of a relevant task, providing step-by-step guidance, tool usage patterns, and quality standards.

Why: Skills encode hard-won, task-specific knowledge that would otherwise need to be re-explained in every prompt. They keep individual prompts short while ensuring consistent, high-quality outputs. Using a skill file reduces per-prompt context significantly compared to inlining all the same instructions.


Meta Tips

Tip Summary Reduces Context?
XML tags Clearly separate prompt sections ✅ Slightly (less parsing ambiguity)
N-shot examples Show desired input/output ➖ Adds tokens but improves quality
Positive instructions Say what to do, not just what to avoid ✅ Fewer follow-up clarifications
Step-by-step thinking Ask Claude to reason before answering ➖ Adds tokens, improves accuracy
Clear context often Start fresh when tasks change ✅✅ Major reduction
Prompt caching (API) Cache static content across calls ✅✅ Major reduction
Concise project instructions Keep system prompts lean ✅ Reduces per-turn cost
Output format specification Tell Claude exactly how to respond ✅ Eliminates filler output

Leave a Reply