Claude Cheat Sheet - 快速参考指南,收录常用语法、命令与实践。
| Model | Features | Best For |
|---|---|---|
| Claude Sonnet 4 | Fast, cost-effective | Daily tasks, coding |
| Claude Haiku | Fastest response | Simple tasks, real-time |
| Claude Opus 4 | Strongest reasoning | Complex analysis, research |
[Role] [Task] [Context] [Format] [Constraints]
You are a senior Python developer.
Review the following code for bugs and security issues.
The code is part of a payment processing system.
Provide feedback in bullet points.
Focus only on critical issues.
Expert Developer
You are a senior software engineer with 15 years
of experience in distributed systems. Review code
with focus on scalability and performance.
Technical Writer
You are a technical documentation specialist.
Explain complex concepts in simple, clear language
suitable for beginners.
Code Reviewer
You are a code reviewer at a Fortune 500 company.
Review code for best practices, security issues,
and maintainability.
Data Scientist
You are a data scientist specializing in machine
learning. Analyze datasets and suggest appropriate
ML models with their tradeoffs.
DevOps Engineer
You are a DevOps engineer with expertise in CI/CD,
containerization, and cloud infrastructure.
Provide production-ready solutions.
Security Expert
You are a cybersecurity specialist. Analyze code
and systems for vulnerabilities following OWASP
guidelines.
<document>
Your document content here
</document>
Summarize the key points from the above document.
<code language="python">
def calculate_total(items):
return sum(item.price for item in items)
</code>
Explain what this function does and suggest improvements.
<context>
We're building an e-commerce platform
</context>
<requirements>
- User authentication
- Shopping cart
- Payment processing
</requirements>
<constraints>
- Must use Python/Django
- Deploy on AWS
</constraints>
Design the system architecture.
<input>
Raw sales data from Q1 2024
</input>
<expected_output>
- Monthly breakdown
- Top performing products
- Growth trends
</expected_output>
Analyze the sales data accordingly.
Step-by-step reasoning
Solve this problem step by step:
1. First, identify the key variables
2. Then, establish relationships
3. Apply relevant formulas
4. Calculate the result
5. Verify your answer
Problem: [Your problem here]
Convert temperatures:
Input: 32°F
Output: 0°C
Input: 212°F
Output: 100°C
Input: 98.6°F
Output:
Solve this problem using three different approaches,
then compare the results to find the most reliable answer.
Problem: [Your problem here]
Analyze this text and respond in JSON format:
{
"sentiment": "positive/negative/neutral",
"confidence": 0.0-1.0,
"key_topics": ["topic1", "topic2"],
"summary": "brief summary"
}
Text: [Your text here]
Basic Function
Write a Python function that:
- Takes a list of integers
- Returns the two numbers that sum to a target
- Handle edge cases (empty list, no solution)
- Include type hints and docstring
- Time complexity should be O(n)
Full Implementation
Create a REST API endpoint in Node.js/Express that:
- Accepts POST requests to /api/users
- Validates email and password fields
- Hashes password using bcrypt
- Saves user to MongoDB
- Returns appropriate status codes
- Includes error handling
Review this code for:
1. Bugs and logic errors
2. Security vulnerabilities
3. Performance issues
4. Code style and readability
5. Missing error handling
Provide specific line-by-line feedback.
<code>
[Your code here]
</code>
Debug this code:
<code>
[Your buggy code]
</code>
Error message:
<error>
[Error output]
</error>
Expected behavior: [What should happen]
Actual behavior: [What's happening]
Refactor this code following these principles:
- Single Responsibility Principle
- DRY (Don't Repeat Yourself)
- Descriptive naming
- Proper error handling
<code>
[Your code here]
</code>
Generate comprehensive unit tests for this function:
- Happy path scenarios
- Edge cases
- Error conditions
- Use pytest/jest framework
- Include setup and teardown
<code>
[Your function here]
</code>
Explain this code to a junior developer:
- What does each section do?
- Why were these design choices made?
- What are potential gotchas?
- How could it be improved?
<code>
[Complex code here]
</code>
Blog Post
Write a blog post about [topic]:
- Target audience: [audience]
- Tone: [professional/casual/technical]
- Length: ~1000 words
- Include: introduction, 3-5 main points, conclusion
- Add relevant examples
- SEO keywords: [keywords]
Technical Documentation
Write documentation for this API endpoint:
- Overview and purpose
- Authentication requirements
- Request parameters (with types)
- Response format (with examples)
- Error codes and handling
- Code examples in Python and JavaScript
Rewrite this text to be:
- More concise (reduce by 50%)
- Professional tone
- Active voice
- Clear and direct
Original:
[Your text here]
Translate this text to [language]:
- Maintain technical accuracy
- Keep formatting intact
- Preserve code snippets unchanged
- Note any terms that don't translate well
<text>
[Your text here]
</text>
Analyze this dataset:
<data>
[Your data here]
</data>
Provide:
1. Summary statistics
2. Key patterns and trends
3. Outliers and anomalies
4. Actionable insights
5. Visualization recommendations
Compare these two approaches:
Option A: [Description]
Option B: [Description]
Evaluate based on:
- Performance
- Scalability
- Maintainability
- Cost
- Implementation complexity
Provide a recommendation with justification.
Analyze this incident:
<incident>
[Description of the problem]
</incident>
<symptoms>
[Observable symptoms]
</symptoms>
Perform root cause analysis:
1. Identify potential causes
2. Evaluate likelihood of each
3. Recommend investigation steps
4. Suggest preventive measures
Review this system architecture:
<architecture>
[Architecture description or diagram]
</architecture>
Evaluate:
- Scalability bottlenecks
- Single points of failure
- Security concerns
- Performance implications
- Suggested improvements
import anthropic
client = anthropic.Anthropic(api_key="your-key")
message = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
messages=[
{"role": "user", "content": "Hello!"}
]
)
print(message.content)
message = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
system="You are a helpful coding assistant.",
messages=[
{"role": "user", "content": "Review my code"}
]
)
messages = [
{"role": "user", "content": "What is Python?"},
{"role": "assistant", "content": "Python is..."},
{"role": "user", "content": "Show me an example"}
]
message = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
messages=messages
)
with client.messages.stream(
model="claude-sonnet-4-20250514",
max_tokens=1024,
messages=[{"role": "user", "content": "Tell me a story"}]
) as stream:
for text in stream.text_stream:
print(text, end="", flush=True)
import base64
with open("image.png", "rb") as f:
image_data = base64.standard_b64encode(f.read()).decode()
message = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
messages=[{
"role": "user",
"content": [
{
"type": "image",
"source": {
"type": "base64",
"media_type": "image/png",
"data": image_data
}
},
{"type": "text", "text": "Describe this image"}
]
}]
)
Professional Email
Write a professional email to a client:
- Purpose: Project delay notification
- Delay: 2 weeks
- Reason: Supply chain issues
- Tone: Apologetic but confident
- Include: New timeline, mitigation steps
- Length: 150-200 words
Follow-up Email
Write a follow-up email:
- Context: Sent proposal 1 week ago
- Goal: Schedule a meeting
- Tone: Friendly, not pushy
- Include: Value proposition reminder
- Call to action: Suggest 3 time slots
Meeting Summary
Summarize this meeting transcript:
<transcript>
[Meeting transcript]
</transcript>
Include:
- Key discussion points
- Decisions made
- Action items with owners
- Next steps and deadlines
- Open questions
Project Plan
Create a project plan for:
Project: [Description]
Timeline: [Duration]
Team size: [Number]
Include:
- Phase breakdown
- Key milestones
- Resource allocation
- Risk assessment
- Dependencies
Explain Concept
Explain [concept] to me:
- Assume I'm a beginner
- Use simple analogies
- Provide practical examples
- Include common misconceptions
- Suggest next topics to learn
Create Tutorial
Create a step-by-step tutorial for [topic]:
- Prerequisites needed
- Learning objectives
- Hands-on exercises
- Common mistakes to avoid
- Practice problems with solutions
If the first response isn't right:
1. Point out specific issues
2. Provide additional context
3. Give examples of desired output
4. Ask for specific modifications
5. Try rephrasing the request
| Shortcut | Action |
|---|---|
Cmd/Ctrl + K | New conversation |
Cmd/Ctrl + Shift + C | Copy last response |
Cmd/Ctrl + Shift + ; | Copy last code block |
Cmd/Ctrl + / | Show shortcuts |
| Shortcut | Action |
|---|---|
Shift + Enter | New line |
Enter | Send message |
Cmd/Ctrl + Shift + 1 | Switch model |
地址
Level 10b, 144 Edward Street, Brisbane CBD(Headquarter)Level 2, 171 La Trobe St, Melbourne VIC 3000四川省成都市武侯区桂溪街道天府大道中段500号D5东方希望天祥广场B座45A13号Business Hub, 155 Waymouth St, Adelaide SA 5000Disclaimer
JR Academy acknowledges Traditional Owners of Country throughout Australia and recognises the continuing connection to lands, waters and communities. We pay our respect to Aboriginal and Torres Strait Islander cultures; and to Elders past and present. Aboriginal and Torres Strait Islander peoples should be aware that this website may contain images or names of people who have since passed away.
匠人学院网站上的所有内容,包括课程材料、徽标和匠人学院网站上提供的信息,均受澳大利亚政府知识产权法的保护。严禁未经授权使用、销售、分发、复制或修改。违规行为可能会导致法律诉讼。通过访问我们的网站,您同意尊重我们的知识产权。 JR Academy Pty Ltd 保留所有权利,包括专利、商标和版权。任何侵权行为都将受到法律追究。查看用户协议
© 2017-2025 JR Academy Pty Ltd. All rights reserved.
ABN 26621887572