Back to Library
PromptingIntermediate

Elicit Chain-of-Thought Reasoning

Tell Claude to "think step by step" or use `<thinking>` tags to get more accurate answers for complex problems.

reasoningchain-of-thoughtanalysis

The Strategy

Complex analytical tasks benefit enormously from explicit reasoning chains. Forcing step-by-step output reduces hallucinations because each step is constrained by the previous one.

prompt.txt
<task>
Analyze the following algorithm and determine its time complexity.
Think through each step carefully before giving your final answer.
</task>

<code>
function findDuplicates(arr: number[]): number[] {
  const seen = new Set<number>();
  const duplicates: number[] = [];
  for (const n of arr) {
    if (seen.has(n)) duplicates.push(n);
    else seen.add(n);
  }
  return duplicates;
}
</code>

<output_format>
1. Step-by-step reasoning
2. Final complexity (Big-O)
3. Space complexity
</output_format>

You might also need