iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
⌨️

The Complete Guide to Useful Features and Shortcuts for Claude Code

に公開

Introduction

Claude Code is a CLI-based AI coding assistant provided by Anthropic. It runs directly in your terminal, allowing the AI to autonomously handle file reading and writing, Git operations, code generation, debugging, and more.

However, with such a rich feature set, you might often find yourself thinking, "Wait, I could do that?" This article provides a comprehensive guide to mastering Claude Code, covering keyboard shortcuts, slash commands, CLI flags, as well as configuration and extension features.


Keyboard Shortcuts

Basic Operations

Shortcut Function
Ctrl+C Cancel current input or generation
Ctrl+D Exit session
Ctrl+L Clear terminal screen (preserves chat history)
Ctrl+O Toggle verbose output
Ctrl+R Reverse search command history
Ctrl+G Open input in default text editor
Ctrl+B Send current task to background
Ctrl+F Terminate all background agents
Ctrl+T Show/hide task list
Shift+Tab Toggle permission mode

Model & Thinking Modes

Shortcut Function
Alt+P / Option+P Switch models
Alt+T / Option+T Toggle Extended Thinking

Pasting Images

Shortcut Function
Ctrl+V / Cmd+V / Alt+V Paste image from clipboard

This is extremely useful when you paste a screenshot and ask, "Fix this UI bug."

Multi-line Input

Shortcut Supported Terminals
\ + Enter All terminals
Option+Enter macOS default
Shift+Enter iTerm2, WezTerm, Ghostty, Kitty
Ctrl+J All terminals

Text Editing (Emacs style)

Shortcut Function
Ctrl+A Move to start of line
Ctrl+E Move to end of line
Ctrl+K Delete to end of line
Ctrl+U Delete entire line
Ctrl+Y Paste deleted text
Alt+B Move back one word
Alt+F Move forward one word

Rewind

Shortcut Function
Esc × 2 times Rewind to previous state or summarize conversation

If Claude makes an unintended change, pressing Esc twice will undo that operation. It's a subtle but essential shortcut.


Slash Commands

Session Management

Command Function
/clear Clear chat history (also works with /reset or /new)
/resume [session] Resume a session (also works with /continue)
/fork [name] Fork the conversation at the current point
/rewind Go back to the previous checkpoint
/rename [name] Rename the session
/export [filename] Export conversation to a text file

Context Management

Command Function
/context Display context usage grid
/compact [instruction] Compact conversation (optional: specify focus)
/cost Show token usage statistics
/memory Edit the CLAUDE.md memory file

Settings & Diagnostics

Command Function
/config Open settings screen (also works with /settings)
/doctor Diagnose installation and settings
/help Show help
/usage Show plan usage limits
/theme Change color theme

Git & Code Review

Command Function
/diff Interactive diff viewer
/pr-comments [PR] Get comments from a GitHub PR
/security-review Review security vulnerabilities

Extensions

Command Function
/skills List available skills
/mcp Manage MCP servers
/batch <instruction> Execute large-scale changes in parallel
/hooks Manage hook settings

Other

Command Function
`/fast [on off]`
/vim Toggle Vim editing mode
/copy Copy last response to clipboard
/tasks Manage background tasks

CLI Flags (Launch Options)

Basic Usage

# Interactive mode
claude

# Launch with an initial prompt
claude "Explain the structure of this project"

# Continue the latest conversation
claude -c

# One-shot execution (run and exit)
claude -p "List package.json dependencies"

Model Selection

claude --model claude-opus-4-6       # Use Opus 4.6
claude --model claude-sonnet-4-6     # Use Sonnet 4.6
claude --fast                        # Launch in fast mode

Permission Control

# Launch in Plan mode (read-only)
claude --permission-mode plan

# Limit available tools
claude --tools "Bash,Edit,Read"

# Allow specific commands only
claude --allowedTools "Bash(npm run *)" "Read"

# Disallow specific commands
claude --disallowedTools "Bash(rm *)"

System Prompt

# Custom system prompt
claude --system-prompt "You are a Python expert"

# Read system prompt from a file
claude --system-prompt-file ./custom-prompt.txt

# Append to existing system prompt
claude --append-system-prompt "Always use TypeScript"

Output Format (For Automation)

# JSON output
claude -p --output-format json "query"

# Streaming JSON
claude -p --output-format stream-json "query"

# Structured output (with schema)
claude -p --json-schema '{"type":"object"...}' "query"

Cost Management

# Set maximum budget (USD)
claude -p --max-budget-usd 5.00 "Large-scale refactoring"

# Limit turn count
claude -p --max-turns 3 "Simple question"

Worktree (Parallel Work)

# Execute within an isolated git worktree
claude -w feature-auth

# Create a worktree with an auto-generated branch name
claude -w

Configuration File

Configuration File Precedence

Claude Code settings are managed across three scopes:

File Scope Purpose
~/.claude/settings.json User Personal settings shared across all projects
.claude/settings.json Project Team-shared settings (Git managed)
.claude/settings.local.json Local Personal project-specific settings (recommended in .gitignore)

Permission Settings

{
  "permissions": {
    "allow": [
      "Bash(npm run test *)",
      "Read(~/.zshrc)"
    ],
    "deny": [
      "Bash(rm *)",
      "Edit(**/.env*)"
    ],
    "defaultMode": "acceptEdits"
  }
}

There are four permission modes:

Mode Description
plan Read-only. No code changes are made
acceptEdits Auto-approve file edits, confirm command execution
bypassPermissions Auto-approve everything (dangerous)
default Confirm each time

Status Line

{
  "statusLine": {
    "type": "command",
    "command": "~/.claude/statusline.sh"
  }
}

You can display context usage or Git branch information in the status line.


CLAUDE.md ── Project Memory

CLAUDE.md is a file for providing persistent instructions to Claude Code. It is automatically read at the start of every session.

Location

Location Scope
CLAUDE.md (project root) Entire project
.claude/CLAUDE.md Entire project
~/.claude/CLAUDE.md User-wide (all projects)

What to Write

# CLAUDE.md

## Basic Rules
- Respond in Japanese
- Git commit messages should be in English

## Environment
- Node.js: v24.13.0 (managed by Volta)
- Package manager: pnpm

## Coding Conventions
- Use TypeScript strict mode
- Write tests with Vitest

Modular Rule Management

In large projects, you can manage rules modularly in the .claude/rules/ directory:

.claude/rules/
  ├── git.md           # Git rules
  ├── typescript.md    # TypeScript conventions
  └── security.md      # Security rules

Hooks ── Automated Workflows

Hooks are processes executed automatically in response to Claude Code events.

Main Events

Event Timing
Stop When Claude finishes responding
PreToolUse Before tool execution (can be blocked)
PostToolUse After successful tool execution
Notification When sending a notification
UserPromptSubmit When user submits a prompt
SessionStart When a session starts

Implementation Example: Play sound on completion

{
  "hooks": {
    "Stop": [
      {
        "matcher": "",
        "hooks": [
          {
            "type": "command",
            "command": "afplay /System/Library/Sounds/Glass.aiff"
          }
        ]
      }
    ]
  }
}

Implementation Example: Auto-format on file save

{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Edit|Write",
        "hooks": [
          {
            "type": "command",
            "command": "npx prettier --write $CLAUDE_FILE_PATH"
          }
        ]
      }
    ]
  }
}

Skills ── Reusable Instruction Sets

Skills provide a mechanism to package instructions specialized for specific tasks.

Creating a Skill

mkdir -p ~/.claude/skills/my-skill

Create ~/.claude/skills/my-skill/SKILL.md:

---
name: my-skill
description: Description of the skill
---

Write detailed instructions for the skill here...

Invoking a Skill

/my-skill arg1 arg2

For example, if you prepare an article writing skill, you can automate everything from generating an article template to Git pushing with a single command like /zenn-article-writer article-title.


MCP ── External Tool Integration

MCP (Model Context Protocol) is a protocol for connecting Claude Code with external services and tools.

Adding a Server

# HTTP-based server
claude mcp add --transport http notion https://mcp.notion.com/mcp

# Local stdio-based server
claude mcp add --transport stdio airtable \
  --env AIRTABLE_API_KEY=YOUR_KEY \
  -- npx -y airtable-mcp-server

Management Commands

claude mcp list       # List servers
claude mcp get github # Get details
claude mcp remove github  # Remove
Server Purpose
GitHub PR/Issue management
Sentry Error monitoring
Notion Document management
Slack Messaging
PostgreSQL Database queries

Power User Techniques

1. Execute commands instantly with ! prefix

! npm test
! git status

By typing ! followed by a command in the prompt input, you can run terminal commands directly without involving Claude.

2. Leverage background tasks

Use Ctrl+B to push tasks to the background. This is useful when you want to ask another question while running tests.

3. Timing for /compact

Consider running /compact when context exceeds 50%. You can check usage at any time with /context.

4. Parallel development with Worktrees

claude -w feature-login   # Develop login feature in a separate branch
claude -w fix-bug-123     # Work on bug fixes in parallel

You can develop multiple features simultaneously without polluting your main branch.

5. Accept suggestions with Tab key

Grayed-out command suggestions may appear when starting a session. You can accept them directly with the Tab key.

6. Diagnose issues with /doctor

If you feel something is "not working," run /doctor. It will automatically detect configuration errors and environmental issues.


Troubleshooting

Common Issues and Solutions

Issue Solution
Insufficient context Use /compact to compress or /clear to start fresh
Cannot connect to MCP server Check auth state via /mcp or diagnose with /doctor
Permissions asked every time Add to allow in settings.json
File changes not reflected Roll back with Esc × 2 and try again
Slow response Switch to fast mode with /fast on

Summary

Category Key Items
Shortcuts Esc×2 (rewind), Ctrl+B (background), Shift+Tab (toggle permissions)
Commands /compact (compress), /context (usage), /doctor (diagnose)
CLI Flags -c (continue), -p (one-shot), -w (worktree)
Settings CLAUDE.md (persistent instructions), Hooks (automation), Skills (reuse)
Extensions Integrate with GitHub, Slack, DB, etc., via MCP

Claude Code is more than just an AI chat; it is a development partner residing in your terminal. Mastering these shortcuts and settings will drastically improve your development efficiency.

Start by checking your context usage with /context.

Discussion