Installation and your first project
Install Claude Code, run your first real task in your own project, and write a solid CLAUDE.md for it.
1. Install and start
# Requires Node.js 18+
npm install -g @anthropic-ai/claude-code
# Enter the project directory before starting: it uses the current directory as the workspace
cd ~/code/my-project
claude
The first time you start it, just log in as prompted. These are the startup commands you will use most often:
| Command | What it does |
|---|---|
claude |
Start a new session in the current directory |
claude --continue |
Continue the previous session |
claude --resume |
Pick a session from the history list to resume |
claude -p "question" |
One-off Q&A, no interactive interface (good for calling from scripts) |
Habit: always start from the project root directory. The files it can see and the
CLAUDE.mdit reads are both based on the directory you start from.
2. The first task: start small and specific
Don't open with "help me refactor the whole project". Pick a first task that is small, specific and verifiable:
The login API returns 500 when the password is wrong. It should return 401 with the message "Wrong username or password".
First find the relevant code and show it to me. Only change it after I confirm.
This prompt has three elements:
- Symptom (returns 500) and expected behavior (401 + message);
- Scope (the login API);
- Pace (show me the code first, and only change it after I confirm).
It will search, read files and explain the cause, and wait for your confirmation before making changes. After the change, it will tell you what it changed and where.
3. Write a good CLAUDE.md: the project's "onboarding manual"
CLAUDE.md lives in the project root and is read automatically every time you start. It is a long-term agreement between you and the AI, far more reliable than explaining things in each conversation.
The fastest way to start:
/init
It scans the project and generates a first draft. Then always edit it yourself and add the things it cannot see:
# CLAUDE.md
## Reply language
Default to Simplified Chinese.
## Build and run
- Build: mvn clean package -DskipTests
- Start: mvn spring-boot:run -pl app-start (port 8080)
- Single test: mvn test -pl <module> -Dtest=<class name>
## Code conventions
- Controllers always return Result<T>, never return entities directly
- Do not end new SQL statements with a semicolon (Oracle will throw an error)
- After changing front-end static assets, bump the version number referenced in the page template by 1
## Things not to do
- Do not commit or push code automatically; wait until I say "commit"
- Do not modify application-prod.yml
A few lessons:
- Write down the "why": "Do not end with a semicolon (Oracle will throw an error)" is followed correctly more reliably than "do not end with a semicolon".
- Write down the counter-intuitive things: conventions that differ from the framework's default approach are the most worth recording.
- Subdirectories can have a CLAUDE.md too: in a large repo, put the special rules for each module in that module's own
CLAUDE.md. - Keep it up to date: each time it makes the same kind of mistake, add the rule.
4. Permissions: what it can change, and when it asks you
By default, Claude Code asks for your consent before editing files or running commands. You can switch modes as needed (Shift+Tab cycles through them):
| Mode | Best for |
|---|---|
| Default | Just starting out, not familiar with the project, sensitive to changes |
| Auto-accept edits | You trust it to edit code, but commands still need confirmation |
| Plan mode | Read-only, only proposes a plan, changes nothing (covered in detail in Part 03) |
Common read-only commands (git status, ls, grep and similar) can be added to an allowlist in settings to reduce repeated confirmations.
5. A few small tricks you can use right away
@file path: reference a file directly in the conversation.! command: run a shell command yourself; the output goes into the conversation (for example! git diff).Esc: interrupt the current operation. PressEsctwice to go back to an earlier message and try again.- You can paste screenshots straight into the conversation. For error popups and page style issues, a screenshot is far more accurate than a description.
Summary
After installing, do three things first: start from the project root, run /init and then edit CLAUDE.md by hand, and push one small bug through the full cycle of "find code → confirm → modify → verify".