Skip to content

Chapter 5: Interactive Mode


What is Interactive Mode?

Interactive Mode is one of Claude Code's core features, providing a continuous dialogue environment where you can have multi-turn interactions with Claude without restarting the command each time.

Main Advantages:

  • 🔄 Context Preservation: Claude remembers previous conversation
  • Rapid Iteration: No need to repeat environment information
  • 🎯 Precise Control: Guide Claude step-by-step through tasks
  • 💬 Natural Conversation: Program like chatting with a colleague

Starting Interactive Mode

5.1 什么是交互模式?

bash
# Method 1: Direct start
$ claude

# Method 2: Start in specific directory
$ cd /path/to/project
$ claude

# Method 3: Start with specific profile
$ claude --profile dev

Interactive Mode Interface:

5.3 会话管理

╭─────────────────────────────────────────╮
│   Claude Code - Interactive Mode       │
│   Model: Claude Sonnet 4.5             │
│   Project: /home/user/my-project       │
╰─────────────────────────────────────────╯

You: _

Basic Operations

Sending Messages

Simply type your request and press Enter:

You: create a calculator.js file

Claude: I'll create a calculator.js file with basic arithmetic operations.

✓ File created: calculator.js

You: add unit tests for it

Claude: I'll create tests for the calculator...

✓ File created: calculator.test.js

Multi-line Input

Use \ at line end to continue:

You: create an API server,\
with following endpoints:\
- GET /users\
- POST /users\
- DELETE /users/:id

Claude: I'll create an API server with those endpoints...

Or use triple quotes:

You: """
Create a React component:
- Name: UserCard
- Props: name, email, avatar
- Display user info card
"""

Claude: I'll create the UserCard component...

View History

You: /history

Recent conversation:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1. You: create calculator.js
   Claude: Created calculator.js
2. You: add unit tests
   Claude: Created calculator.test.js
3. You: run tests
   Claude: Tests passed ✓
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Session Management

Save Session

You: /save my-feature-session

✓ Session saved as: my-feature-session
  Location: ~/.claude-code/sessions/my-feature-session.json

Load Session

bash
# Load on start
$ claude --session my-feature-session

# Or in interactive mode
You: /load my-feature-session

 Session loaded: my-feature-session
  Messages: 15
  Last activity: 2026-01-20 15:30

List All Sessions

You: /sessions

Saved sessions:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
📁 my-feature-session
   15 messages | 2026-01-20 15:30

📁 bugfix-auth
   8 messages | 2026-01-19 10:00

📁 refactor-api
   23 messages | 2026-01-18 14:15
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Delete Session

You: /delete-session bugfix-auth

⚠  Are you sure you want to delete 'bugfix-auth'? (yes/no)
You: yes

✓ Session deleted: bugfix-auth

Context Management

View Current Context

You: /context

Current context:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Working directory: /home/user/my-project
Files in context: 3
  - src/app.js (120 lines)
  - src/utils.js (45 lines)
  - package.json (25 lines)

Recent operations: 5
Tokens used: 2,340 / 200,000
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Add Files to Context

You: /add src/config.js src/database.js

✓ Added to context:
  - src/config.js
  - src/database.js

Now tracking 5 files in context

Remove Files

You: /remove src/database.js

✓ Removed from context: src/database.js

Clear Context

You: /clear

⚠  This will clear all context. Continue? (yes/no)
You: yes

✓ Context cleared
  Starting fresh conversation

Auto Context Management

Claude Code intelligently manages context:

You: modify routes in src/app.js

Claude: [Automatically adds src/app.js to context]
I'll modify the routes in src/app.js...

You: ensure consistency with config.js

Claude: [Automatically adds src/config.js to context]
I'll check the configuration and ensure consistency...

Keyboard Shortcuts

Interactive mode supports various shortcuts for efficiency:

ShortcutFunctionDescription
Ctrl + CInterrupt operationStop Claude's current task
Ctrl + DExit interactive modeSafe exit (prompts to save)
Ctrl + LClear screenClear terminal display
Ctrl + RSearch historySearch previous commands
/ Browse historyView previous input
TabAuto-completeComplete commands and filenames
Ctrl + UClear input lineDelete current input
Ctrl + WDelete wordDelete word before cursor
Ctrl + ALine startMove to line start
Ctrl + ELine endMove to line end

Practical Examples

# Interrupt execution
You: analyze performance issues across entire codebase
Claude: [Starts analysis, taking too long]
[Press Ctrl + C]
⚠ Operation interrupted by user

# Search history
[Press Ctrl + R]
(reverse-i-search)`test': run all unit tests

Practical Scenarios

Scenario 1: Iterative Feature Development

You: create a user registration feature

Claude: I'll create a user registration feature with:
- Registration form
- Validation
- Database storage
✓ Created files: register.js, register.html

You: add email verification

Claude: I'll add email verification...
✓ Updated register.js
✓ Created email-service.js

You: add password strength check

Claude: I'll add password strength validation...
✓ Updated register.js with password requirements

You: write test cases

Claude: I'll create comprehensive tests...
✓ Created register.test.js

You: run tests

Claude: Running tests...
✓ All 15 tests passed

Scenario 2: Debugging

You: user login failing, returning 401 error

Claude: Let me investigate the authentication issue.
Reading auth.js... Found potential issue in JWT validation.

You: what's the specific problem?

Claude: The JWT secret key doesn't match between:
- auth.js: uses process.env.JWT_SECRET
- config.js: defines jwtSecret (different name)

You: fix this issue

Claude: I'll align the JWT secret configuration...
✓ Updated config.js
✓ Updated auth.js
Issue should be resolved now.

You: test it

Claude: Testing authentication...
✓ Login successful
✓ Token validation working

Scenario 3: Code Refactoring

You: src/api.js is too long, needs refactoring

Claude: Let me analyze src/api.js...
File has 850 lines. I suggest splitting into:
- routes/users.js
- routes/products.js
- middleware/auth.js
- middleware/validation.js

You: ok, start refactoring

Claude: Refactoring src/api.js...
✓ Created routes/users.js (180 lines)
✓ Created routes/products.js (220 lines)
✓ Created middleware/auth.js (95 lines)
✓ Created middleware/validation.js (120 lines)
✓ Updated src/api.js (now 125 lines)

You: ensure tests still pass

Claude: Running tests...
✓ All 42 tests passed
Refactoring complete!

Summary

In this chapter, we learned:

  • ✅ Interactive mode concept and advantages
  • ✅ Basic operations (send messages, multi-line input, view history)
  • ✅ Session management (save, load, delete sessions)
  • ✅ Context management (add, remove, view context)
  • ✅ Keyboard shortcuts for efficiency
  • ✅ Practical scenario demonstrations

Key Takeaways:

  • Interactive mode maintains context, suitable for complex tasks
  • Utilize session save features
  • Manage context to control costs
  • Master shortcuts for efficiency

Next Step: Chapter 6 will dive deep into Claude Code's basic usage and toolset!


Content is for learning and research only.