Learning Objectives
- Navigate the Claude Code REPL efficiently with keyboard shortcuts
- Use multiline input for complex prompts and code blocks
- Execute quick commands with
/,!, and@prefixes - Master essential slash commands for session management
- Enable and use vim mode for power-user editing
- Run Claude Code non-interactively for scripting and automation
- Manage multiple sessions with naming and resumption
The Claude Code CLI is far more than a simple prompt-response interface. It's a powerful REPL (Read-Eval-Print Loop) environment with rich keyboard shortcuts, inline commands, and multiple input modes designed for productivity. Understanding these navigation patterns transforms Claude Code from a chatbot into a professional development tool.
The Interactive REPL
Start Claude Code with a simple claude command to enter the interactive REPL:
claudeThis launches the main interface where you'll spend most of your time. The REPL maintains conversation context, tracks file changes, and remembers your working directory across commands.
For quick single-shot queries, pass your prompt directly:
claude "Explain the difference between map and filter in JavaScript"This executes immediately and returns you to your shell. Use this for quick lookups when you don't need ongoing conversation.
The REPL prompt shows your current model and permission mode:
claude-sonnet-4-5 (Normal) >
This persistent indicator helps you understand what model is processing your requests and whether tools require manual approval.
Essential Keyboard Shortcuts
Mastering keyboard shortcuts separates casual users from power users. These shortcuts work across all supported terminals.
Generation Control
Ctrl+C cancels the current generation entirely. Use this when Claude starts down the wrong path and you want to stop immediately without preserving any output.
Esc stops generation mid-action but preserves the context up to that point. This is crucial when you realize partway through a response that you need to redirect the approach. The partial output remains in context, and you can guide Claude differently without starting over.
Esc+Esc rewinds to the previous checkpoint, effectively undoing the last response. This is your emergency undo button when Claude makes unwanted changes or takes an incorrect approach.
Session Management
Ctrl+D exits the current session cleanly. This is the standard Unix EOF signal and the proper way to end a session.
Ctrl+L clears your screen while keeping conversation history intact. Use this when your terminal gets cluttered but you want to maintain context.
Ctrl+R activates reverse search through your command history. Type a few characters to find previous prompts quickly. This works like bash history search and is invaluable for repeating complex queries.
Visibility and Input
Ctrl+O toggles verbose output mode. When enabled, you see detailed information about tool usage, token counts, and internal reasoning. Enable this when debugging unexpected behavior or learning how Claude approaches problems.
Shift+Tab cycles through permission modes without using slash commands. Press once to switch from Normal to Auto-Accept, again for Plan Mode, and once more to return to Normal. This rapid toggling is essential when alternating between exploratory work (Normal) and batch operations (Auto-Accept).
Ctrl+G opens your prompt in your system's default text editor. Use this for crafting complex multi-paragraph prompts or when you need proper syntax highlighting for code examples you're providing.
Ctrl+V pastes an image from your clipboard directly into the conversation. Screenshot documentation, UI mockups, or error messages and paste them inline without saving to files first.
Up/Down arrows navigate your command history. Press up to cycle through previous prompts, edit them, and resubmit. This is faster than retyping similar queries.
Multiline Input Strategies
Complex prompts often require multiple lines. Claude Code supports several methods for multiline input, depending on your terminal.
Universal Method: Backslash Continuation
The backslash \ followed by Enter works in all terminals:
claude-sonnet-4-5 (Normal) > Write a function that: \
... - Accepts a list of user objects \
... - Filters by active status \
... - Sorts by registration date \
... - Returns only the top 10
Each line ends with \ to continue. The prompt changes to ... indicating continuation mode. Press Enter twice or end a line without \ to submit.
macOS Default: Option+Enter
On macOS terminals, Option+Enter creates a new line within your prompt:
claude-sonnet-4-5 (Normal) > Write a function that:
... - Accepts a list of user objects
... - Filters by active status
... - Sorts by registration date
... - Returns only the top 10
This is more natural than backslash continuation but only works in macOS Terminal.app by default.
Modern Terminals: Shift+Enter
Modern terminals like iTerm2, WezTerm, Ghostty, and Kitty support Shift+Enter natively:
claude-sonnet-4-5 (Normal) > Write a function that:
... - Accepts a list of user objects
... - Filters by active status
... - Sorts by registration date
... - Returns only the top 10
This matches the behavior of most web interfaces and feels most intuitive for users coming from browser-based tools.
Universal Alternative: Ctrl+J
Ctrl+J sends a line feed character, creating a new line in any terminal:
claude-sonnet-4-5 (Normal) > Write a function that:
... - Accepts a list of user objects
This is the most portable option after backslash continuation.
Paste Mode for Code Blocks
When pasting multi-line code, most terminals enter "paste mode" automatically, preserving formatting and line breaks. Simply copy code from your editor and paste it into the Claude Code prompt:
claude-sonnet-4-5 (Normal) > Review this function:
function processUsers(users) {
return users
.filter(u => u.active)
.sort((a, b) => new Date(a.registered) - new Date(b.registered))
.slice(0, 10);
}
The entire code block pastes as one unit without triggering submission until you press Enter.
Quick Command Prefixes
Claude Code recognizes special prefixes that change how your input is processed.
Slash Commands: /
Starting your input with / invokes slash commands and skills:
/help
/context
/model opus-4-6
/permissions auto
Slash commands are built-in CLI features for configuration, session management, and metadata inspection. We'll cover the essential ones in detail shortly.
Bash Mode: !
Starting with ! runs a bash command directly and adds the output to conversation context:
!ls -la src/components
!git status
!npm test
This is faster than asking Claude to run commands for you. The command executes immediately, output appears in your terminal, and Claude sees the results as context for the next prompt.
Bash mode executes commands immediately without confirmation. Use carefully with destructive operations.
File Mentions: @
The @ symbol triggers file path autocomplete:
claude-sonnet-4-5 (Normal) > Refactor @src/components/Button.tsx
Start typing after @ and press Tab to see matching files. This is faster than typing full paths and prevents typos. File contents are automatically added to context.
Essential Slash Commands
Slash commands control the CLI environment and session behavior.
Session Control
/clear — Starts a new conversation while staying in the same session. Context resets, but session ID remains the same.
/resume — Lists all previous sessions and lets you pick one to continue. Use this to return to work from days or weeks ago.
/rename — Assigns a meaningful name to your current session instead of the default timestamp. Name sessions by project or task for easier identification.
/rename "Refactoring auth module"
/rewind — Steps backward through conversation checkpoints, undoing recent exchanges. Each rewind removes one turn of conversation.
Context and Visibility
/context — Shows what files, directories, and content are currently in Claude's context. Use this to verify Claude has access to the files you're discussing.
/status — Displays current model, permission mode, token usage, and session information. Check this regularly to monitor costs and understand your configuration.
/compact — Toggles compact mode, which reduces visual spacing in Claude's responses. Enable this on small terminals or when you prefer denser output.
Configuration
/model — Switches between available models (sonnet-4-5, opus-4-6, haiku-4). Specify the model name as an argument:
/model opus-4-6
/permissions — Changes permission mode without Shift+Tab. Accepts normal, auto, or plan:
/permissions auto
/theme — Switches color themes for syntax highlighting and UI elements. Options include dark, light, and several named themes.
/vim — Enables vim mode for input editing. Once enabled, the REPL prompt supports vim keybindings.
Diagnostics
/doctor — Runs system diagnostics to check API connectivity, authentication, token availability, and environment configuration. Run this if commands fail unexpectedly.
/cost — Shows cumulative API costs for the current session, broken down by model and token type. Use this to track spending on long-running projects.
Setup
/init — Generates a CLAUDE.md file in your current directory with project-specific instructions. This file persists preferences and context across sessions.
/memory — Opens your global memory file for editing. Use this to store preferences, patterns, and context that apply across all projects.
/help — Lists all available slash commands and skills with brief descriptions. Add a command name to see detailed help:
/help permissions
Vim Mode for Power Users
Vim mode transforms the Claude Code prompt into a vim-style editor, enabling rapid text manipulation with minimal keystrokes.
Enabling Vim Mode
Enable vim mode with the slash command:
/vim
Or make it permanent by adding to your configuration:
/config set vim true
Once enabled, the prompt starts in Normal mode. Press i to enter Insert mode and type normally.
Mode Switching
i — Enter Insert mode at the cursor position. This is your primary entry point for typing.
I — Enter Insert mode at the beginning of the line.
a — Enter Insert mode after the cursor (append).
A — Enter Insert mode at the end of the line.
o — Open a new line below and enter Insert mode.
O — Open a new line above and enter Insert mode.
Esc — Return to Normal mode from any other mode.
The mode indicator appears in your prompt:
claude-sonnet-4-5 (Normal) [INSERT] >
claude-sonnet-4-5 (Normal) [NORMAL] >
Navigation in Normal Mode
h/j/k/l — Move left/down/up/right (standard vim directions).
w — Jump forward to the start of the next word.
e — Jump forward to the end of the next word.
b — Jump backward to the start of the previous word.
0 — Move to the beginning of the line.
$ — Move to the end of the line.
gg — Jump to the first line (in multiline input).
G — Jump to the last line (in multiline input).
Editing in Normal Mode
x — Delete the character under the cursor.
dd — Delete the entire line.
dw — Delete from cursor to the start of the next word.
d$ — Delete from cursor to the end of the line.
cc — Delete the entire line and enter Insert mode.
cw — Change from cursor to the start of the next word (delete and enter Insert mode).
yy — Yank (copy) the entire line.
yw — Yank from cursor to the start of the next word.
p — Paste after the cursor.
P — Paste before the cursor.
u — Undo the last change.
Ctrl+R — Redo the last undone change.
Text Objects
Vim's text objects let you operate on semantic units:
iw — Inner word (the word under the cursor).
aw — A word (word plus surrounding whitespace).
i" — Inner double quotes (content inside quotes).
a" — A double quoted string (quotes included).
i( — Inner parentheses.
a( — A parenthesized expression (parentheses included).
Combine these with operators:
diw # Delete inner word
ci" # Change inner quoted string
ya( # Yank a parenthesized expression
Vim mode is optional but dramatically increases editing speed once you internalize the commands. If you already use vim or neovim, enabling this makes Claude Code feel like a natural extension of your editor.
Non-Interactive Mode for Scripting
Claude Code isn't limited to interactive sessions. The -p flag enables non-interactive mode, where Claude processes a query and returns results without entering the REPL.
Basic Non-Interactive Queries
Pass your prompt with the -p flag:
claude -p "Explain how async/await works in JavaScript"Claude processes the query, streams the response to stdout, and exits. This is perfect for one-off questions in shell scripts.
Output Formats
Control output format with the --format flag:
Text (default) — Standard human-readable output:
claude -p "List benefits of TypeScript" --format textJSON — Structured output with metadata:
claude -p "Analyze this code" --format jsonReturns a JSON object with response text, model used, token counts, and timing information. Parse this in scripts for programmatic processing.
Stream JSON — Newline-delimited JSON objects streamed as the response generates:
claude -p "Write a Python function" --format stream-jsonEach line is a valid JSON object representing a chunk of the response. Use this for real-time processing in event-driven systems.
Piping Input to Claude
Pipe file contents or command output directly to Claude:
cat src/utils/auth.ts | claude -p "Identify security vulnerabilities"The piped input becomes part of Claude's context automatically. Combine with bash utilities for powerful workflows:
# Analyze git diff before committing
git diff | claude -p "Review these changes for potential bugs"
# Summarize log files
tail -100 /var/log/app.log | claude -p "Summarize errors and warnings"
# Process JSON data
curl -s https://api.example.com/data | claude -p "Extract all email addresses"Scripting Examples
Generate commit messages:
#!/bin/bash
DIFF=$(git diff --staged)
MESSAGE=$(echo "$DIFF" | claude -p "Write a concise git commit message for these changes" --format text)
git commit -m "$MESSAGE"Automated code review:
#!/bin/bash
for file in $(git diff --name-only main); do
echo "Reviewing $file..."
git diff main -- "$file" | claude -p "Review this code change. List issues as bullet points." --format text
doneCI/CD integration:
# .github/workflows/code-review.yml
name: AI Code Review
on: [pull_request]
jobs:
review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Review Changes
run: |
git diff origin/main...HEAD | claude -p "Review these changes. Flag security issues, performance problems, and code smells." --format json > review.jsonNon-interactive mode transforms Claude Code from an assistant into an automation tool. Use it anywhere you'd use grep, sed, awk, or other text processing utilities, but with natural language understanding.
Session Management Patterns
Long-term projects benefit from organized session management.
Continuing Recent Work
Resume your most recent session:
claude --continueThis loads the last session you worked on, preserving all context and conversation history.
Resuming Named Sessions
List all sessions and choose one interactively:
claude --resumeThis displays a scrollable list with session names, timestamps, and message counts. Use arrow keys to select.
Naming Sessions for Organization
Immediately after starting important work, name the session:
/rename "Authentication refactor - OAuth2 migration"
Named sessions appear in /resume lists with descriptive titles instead of timestamps. Develop a naming convention like "Project - Feature - Task" for easy filtering.
Session Hygiene
Sessions accumulate over time. Periodically review with /resume and delete obsolete sessions manually from your session directory (location shown in /status). Keep active work sessions and archive completed ones by moving session files to a completed/ subdirectory.
Master the CLI Interface
beginner20 min- Start a new Claude Code session with
claude - Enable verbose mode with Ctrl+O and run a simple query to see detailed tool usage
- Toggle permission modes with Shift+Tab and observe the prompt indicator changes
- Create a multiline prompt using your preferred method (backslash, Option+Enter, or Shift+Enter)
- Run a bash command with
!git statusto see inline command execution - Use
/contextto inspect what's currently in Claude's context - Enable vim mode with
/vimand practice basic navigation (hjkl, w, e, b) - Exit vim mode Insert with Esc and try deleting a word with
dw - Exit the session with Ctrl+D
- Run a non-interactive query:
echo "const x = 5;" | claude -p "Is this valid JavaScript?" - Start a new session, name it with
/rename "CLI Navigation Practice", exit, and resume it withclaude --continue
Key Takeaway
The Claude Code CLI provides three distinct interaction modes: the interactive REPL for conversational development, quick commands (slash, bash, file mentions) for rapid context manipulation, and non-interactive mode for scripting and automation. Master keyboard shortcuts and vim mode to navigate the interface efficiently, and use session management to organize long-term projects. Understanding these patterns transforms Claude Code from a chatbot into a professional development environment integrated into your existing workflow.