Claude Code Cheatsheet: Commands, Slash Commands, CLAUDE.md and MCP
What You Will Master in This Tutorial
- Set up Python 3.12+ and write clean, readable, PEP 8-compliant code.
- Work with fundamental data structures: Lists, Dictionaries, Sets, and Tuples.
- Control program execution flow with conditionals, loops, and list comprehensions.
- Encapsulate logic into reusable functions with type hints and default arguments.
- Understand Object-Oriented Programming (OOP) in Python: Classes, Methods, and Inheritance.
- Test and execute your scripts interactively using the Online Code Playground.
Print it, pin it, or keep it in a second tab. This is the dense reference for Claude Code, Anthropic's terminal-based coding agent: the commands you will use daily, the slash commands worth memorizing, a production-ready CLAUDE.md template, and MCP wiring. For the guided walkthrough, read our Claude Code mastery tutorial afterwards.
Install and start
| Command | What it does |
|---|---|
npm install -g @anthropic-ai/claude-code | Install Claude Code globally (Node.js 18+) |
claude | Start an interactive session in the current folder |
claude "fix the failing test in auth.py" | Start with an initial prompt |
claude -p "explain this codebase" | Print mode: one-shot answer, no session (great for scripts) |
cat error.log | claude -p "what caused this?" | Pipe input into a one-shot query |
claude -c | Continue the most recent conversation in this folder |
claude --resume | Pick a previous session to resume |
claude update | Update to the latest version |
claude doctor | Diagnose installation and environment problems |
claude mcp list | List configured MCP servers (see below) |
Essential slash commands (inside a session)
| Command | Use it to |
|---|---|
/init | Generate a starter CLAUDE.md from your codebase |
/clear | Wipe context and start fresh β the most underrated command; use between unrelated tasks |
/compact | Summarize the conversation to free context while keeping the thread |
/context | See what is filling the context window |
/cost | Show token usage and cost of the session |
/model | Switch model (for example to a faster/cheaper one for grunt work) |
/permissions | Review and adjust which tools/commands need approval |
/review | Review a pull request |
/agents | Create and manage subagents for specialized tasks |
/memory | Edit memory files (CLAUDE.md and auto-memory) |
/mcp | Check MCP server status and authenticate |
/vim | Toggle Vim editing mode in the prompt |
/help | Full list of commands for your version |
Keyboard and prompt tricks
Escβ stop Claude mid-action.Esctwice β edit a previous message.Shift+Tabβ cycle permission modes, including Plan mode (proposes, does not execute) and auto-accept edits.@path/to/fileβ reference a file so Claude reads it directly.# your noteat the start of a prompt β save the note to project memory (CLAUDE.md).!prefix β run a shell command yourself inside the session (for example!npm test) and keep its output in context.- "think" / "think hard" / "ultrathink" in a prompt β ask for progressively deeper reasoning on hard problems (and accept the extra cost).
Ctrl+Rβ search prompt history.Ctrl+Cβ interrupt/exit.
CLAUDE.md template (copy, adapt, commit it)
# Project: [Name]
## What this is
One paragraph: what the project does, who uses it, the stack.
## Commands
- Install: `npm install`
- Dev: `npm run dev`
- Test: `npm test` (single file: `npm test -- path/to/file.test.ts`)
- Lint/typecheck: `npm run lint && npm run typecheck`
- Build: `npm run build`
## Architecture
- Entry point: src/main.ts β keep it thin.
- Business logic lives in src/services/, never in route handlers.
- Data access only through src/db/ (no raw SQL in services).
## Rules
- TypeScript strict. No `any` without a comment explaining why.
- All new endpoints need a test. Run the full test suite before saying "done".
- Never edit migrations that are already merged; create a new one.
- Match the style of the file you are editing; do not reformat unrelated code.
## Gotchas
- The payments webhook is fragile: read docs/payments.md before touching it.
- Local .env uses staging keys. Never print secrets in output or logs.
Keep it short β Claude reads this every session, so every line costs context. Put long runbooks in separate docs and link them.
Connect MCP servers
# Project-scoped (shared via .mcp.json in the repo)
claude mcp add github -- npx -y @modelcontextprotocol/server-github
# From a JSON config (remote server with headers)
claude mcp add --transport http sentry https://mcp.sentry.dev/mcp
# Inspect and remove
claude mcp list
claude mcp remove github
Equivalent .mcp.json at your repo root:
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/project"]
},
"postgres": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-postgres",
"postgresql://user:pass@localhost:5432/app"]
}
}
}
New to MCP itself? Start with our MCP guide and the companion MCP servers cheatsheet.
Daily workflow that works
- Plan first: for anything non-trivial, use Plan mode (
Shift+Tab) and approve the approach before code changes. - Small loops: one task, run tests, review the diff, commit. Then
/clearbefore the next unrelated task. - Show, do not tell: paste the error, the log, the failing test β do not describe them from memory.
- Verify like a skeptic: ask Claude to run the test suite and the linter, and read the diff yourself. "It should work" is not verification.
- Feed the memory: when Claude makes the same mistake twice, add one line to
CLAUDE.md.
Troubleshooting quick hits
- It keeps asking permission for everything: tune
/permissionsor allowlist safe commands in.claude/settings.json. - Answers feel generic: your
CLAUDE.mdis thin or missing; run/initand add commands and gotchas. - Context fills instantly: stop pasting whole repos β reference files with
@, use/compact, and split work across subagents. - MCP server will not connect:
claude mcp listfor status, test the server's command manually in a terminal, and check that required API keys are in your environment.
More references in our cheatsheets library.
Knowledge Check: Test Your Understanding
1. Which Python data structure provides constant-time O(1) key lookups?
Frequently Asked Questions
How long does it take to learn Python for beginners?
With daily practice of 1-2 hours, most beginners grasp core syntax, data structures, and functions within 3 to 4 weeks, and can build basic automation scripts and data projects in 6 to 8 weeks.
Can I run Python directly in my browser?
Yes! You can use our built-in Online Code Playground (/tools/online-code-playground/) to run Python code instantly without setting up any local environment.