Skip to content

Chapter 4: Quick Start


Your First Command

Let's start with the simplest command to experience Claude Code's powerful features.

Single Command Mode

4.1 第一个命令

bash
# Basic syntax
claude "your task description"

# Example 1: Simple greeting
claude "Hello! How do you work?"

# Example 2: Get help
claude "list files in current directory"

Practical Demo:

bash
$ claude "create a hello.js file that outputs Hello World"

I'll create a hello.js file that outputs "Hello World".

✓ Creating hello.js...

File created at: /home/user/hello.js

```javascript
console.log('Hello World');

Task completed successfully!


#### Verify Result

```bash
$ ls -l hello.js
-rw-r--r-- 1 user user 28 Jan 21 10:00 hello.js

$ node hello.js
Hello World

Basic Workflow

Claude Code's typical workflow:

4.2 基本工作流程

1. Describe Task → 2. Claude Analyzes → 3. Plan Execution → 4. Complete Task → 5. Verify Result

Complete Example: Create a Web Server

bash
$ claude "create a simple Express.js web server listening on port 3000, returning JSON response"

Claude Code's Execution Process:

📋 Task: Create Express.js web server

[1/5] 📖 Reading project structure...
  ✓ No package.json found - will create new project

[2/5] 🔍 Checking if Express is installed...
  ⚠ Express not found

[3/5] 📦 Installing Express...
  $ npm init -y
  $ npm install express
  ✓ Express installed successfully

[4/5] ✍️  Creating server.js...
  ✓ File created: server.js

[5/5] ✅ Verification...
  ✓ Syntax check passed
  ✓ Dependencies resolved

Task completed! Run: node server.js

Generated server.js:

4.3 常用操作示例

javascript
const express = require('express');
const app = express();
const PORT = 3000;

app.get('/', (req, res) => {
  res.json({
    message: 'Hello World',
    timestamp: new Date().toISOString()
  });
});

app.listen(PORT, () => {
  console.log(`Server running on http://localhost:${PORT}`);
});

Test Server:

bash
$ node server.js
Server running on http://localhost:3000

# Test in another terminal
$ curl http://localhost:3000
{"message":"Hello World","timestamp":"2026-01-21T10:30:00.000Z"}

Common Operations

1. File Operations

Create File:

bash
claude "create a README.md file with project description"

Edit File:

bash
claude "add installation instructions section to README.md"

Refactor File:

bash
claude "refactor app.js to use ES6 module syntax"

2. Code Generation

Generate Function:

bash
claude "create a function to calculate Fibonacci sequence"

Generate Class:

bash
claude "create a User class with name, email, and validation methods"

Generate Tests:

bash
claude "generate unit tests for functions in utils.js"

3. Debugging and Fixes

Find Bugs:

bash
claude "check for errors in src/api.js"

Fix Errors:

bash
claude "fix validation issues in login functionality"

Performance Optimization:

bash
claude "optimize database query performance"

4. Documentation

Generate Comments:

bash
claude "add JSDoc comments to functions in src/utils.js"

Generate README:

4.4 小试牛刀项目

bash
claude "generate README.md documentation for project"

Generate API Docs:

bash
claude "generate OpenAPI documentation for API routes"

Starter Project

Let's practice with a complete mini-project: Create a Todo CLI App

Project Goals

  • Command-line Todo list management tool
  • Support add, delete, list, complete tasks
  • Persist data to JSON file

Implementation Steps

Step 1: Create Project

bash
mkdir todo-cli
cd todo-cli
claude "initialize a Node.js project, create package.json"

Step 2: Create Main File

bash
claude "create todo.js with following features:
1. Add task: add <task>
2. List tasks: list
3. Complete task: done <id>
4. Delete task: delete <id>
Use commander.js for CLI arguments, store data in todos.json"

Step 3: Test Features

bash
# Add tasks
node todo.js add "Learn Claude Code"
node todo.js add "Create first project"

# List tasks
node todo.js list

# Complete task
node todo.js done 1

# Delete task
node todo.js delete 2

Step 4: Optimize and Improve

4.5 提示词技巧

bash
claude "add these improvements:
1. Colored output (use chalk)
2. Task priority
3. Due dates
4. Export to CSV"

Final Result:

bash
$ node todo.js list

📋 Todo List
━━━━━━━━━━━━━━━━━━━━━━
 1. Learn Claude Code [HIGH] 📅 2026-01-25
 2. Create first project [MEDIUM]
 3. Write test cases [LOW] 📅 2026-01-30
━━━━━━━━━━━━━━━━━━━━━━
Total: 3 tasks (1 completed)

Prompt Tips

Good prompts significantly improve Claude Code's efficiency and accuracy:

✅ Good Prompts

Clear and Specific:

bash
# Good
claude "create an Express.js API with GET /users and POST /users endpoints, use MongoDB for storage"

# Bad
claude "create an API"

Provide Context:

bash
# Good
claude "in existing React project, add pagination to UserList component, 10 items per page"

# Bad
claude "add pagination"

Specify Tech Stack:

bash
# Good
claude "create unit tests for auth.ts using TypeScript and Jest"

# Bad
claude "create tests"

Prompt Templates

Feature Development Template:

"Implement [feature description] in [file/directory],
Requirements:
1. [specific requirement 1]
2. [specific requirement 2]
3. [specific requirement 3]
Using [tech stack/framework]"

Bug Fix Template:

"Fix [issue description] in [file],
Symptoms: [specific behavior]
Expected behavior: [expected result]"

Refactoring Template:

"Refactor [file/module],
Goal: [refactoring goal]
Keep: [features to maintain]
Optimize: [aspects to improve]"

Summary

In this chapter, we learned:

  • ✅ How to execute your first Claude Code command
  • ✅ Understand basic workflow
  • ✅ Master common operations (files, code, debugging, docs)
  • ✅ Complete a Todo CLI project
  • ✅ Tips for writing effective prompts

Key Takeaways:

  • Prompts should be clear and specific
  • Provide sufficient context
  • Specify tech stack and frameworks
  • Verify execution results

Next Step: In Chapter 5, we'll learn interactive mode for a smoother development experience!


Content is for learning and research only.