How to Use Claude Terminal | CLI Introduction for Mac, Windows & Linux

When you want to run Claude from the terminal, many people aren't sure where to start. Claude Code's CLI — which launches an interactive session with a single claude command and autonomously handles file reading, code writing, and shell execution — can take you from installation to your first prompt in under five minutes. This article, based on Anthropic's official documentation, covers installation steps for Mac, Windows, and Linux, as well as basic commands, key bindings, and how to integrate Claude into scripts.

AI-powered article summarypowered by Claude
結論powered by Claude

To use Claude Code in the terminal, install it with a single line — curl -fsSL https://claude.ai/install.sh | bash (macOS, Linux, WSL) or irm https://claude.ai/install.ps1 | iex in PowerShell, then simply type claude to start a session. The native installer includes automatic background updates, while installing via Homebrew or WinGet requires manual updates.

During a session, just three shortcuts cover the basics: Ctrl+C to interrupt, Esc to stop a response, and /help to display the command list. For non-interactive execution (CI integration, pipe chaining), the print mode claude -p "question" is the standard approach, and it also accepts piped input like cat logs.txt | claude -p "summarize".

For session management, three flags are essential: claude -c (resume the most recent conversation), claude -r "name" (resume by name), and claude --bg "task" (run in the background). When using Claude from the terminal, the key advantages over the desktop app are combining it with scripts and running tasks in the background.

目次 (12)

What Is Claude Terminal?

Claude Code is a coding-focused AI tool provided by Anthropic, with the terminal (command line) as its primary interface. Rather than reading a response and copying it like a chat UI, launching the claude command lets the AI autonomously read files, write code, and execute shell commands.

While it's also available as a VS Code / JetBrains extension, a desktop app, and a browser version (claude.ai/code), the terminal version (CLI) is the most flexible for embedding into development workflows — including CI integration, script embedding, and headless execution.

  • Supported OS: macOS 13.0+, Windows 10 1809+, Ubuntu 20.04+, Debian 10+, Alpine 3.19+ (official)
  • Requirements: 4GB+ RAM, x64 or ARM64 processor, internet connection
  • Available plans: Pro, Max, Team, Enterprise, Console (free plans not supported)

Installation — Mac, Linux, and Windows

macOS / Linux / WSL

Open a terminal (Mac: Cmd + Space → Terminal; Linux: Ctrl + Alt + T), paste the following, and press Enter:

curl -fsSL https://claude.ai/install.sh | bash

After installation completes, close and reopen the terminal for the claude command to be recognized. If you prefer Homebrew, you can also install it with brew install --cask claude-code (stable channel), but the Homebrew version does not auto-update — you'll need to run brew upgrade claude-code manually.

Windows (PowerShell)

Press Win + X → open Windows PowerShell (or Terminal) and run:

irm https://claude.ai/install.ps1 | iex

If you're using CMD, you can use curl -fsSL https://claude.ai/install.cmd -o install.cmd && install.cmd && del install.cmd as an alternative. You can also install via WinGet with winget install Anthropic.ClaudeCode (also no auto-update). After installation, close and reopen PowerShell and claude will be available.

Verifying the Installation

claude --version   # Outputs the version number
claude doctor      # Detailed diagnosis of installation status

If you see command not found, your PATH may not be set. On Mac/Linux, you can add it with echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc && source ~/.zshrc (official troubleshooting).

Updating

The native installer version updates automatically in the background. To apply an update manually immediately:

claude update

If you want to pin a version, you can switch to /config → Auto-update channel → stable (approximately one week behind, stable release).

Starting Your First Session and Authentication

After installation, navigate to your project directory and type claude:

cd ~/my-project
claude

The first time, a browser will open asking you to sign in to your Claude account. After signing in, return to the terminal and the interactive session will begin. You can continue using it from then on (no need to sign in again).

To check authentication status or log out, use these commands:

claude auth status   # Display login status as JSON (--text for plain text)
claude auth logout   # Log out
claude auth login    # Sign in again

Basic CLI Command Reference

Here are the main commands for starting and managing sessions (official CLI reference):

Command Description
claude Start an interactive session
claude "question" Start a session with an initial prompt
claude -p "question" Run in non-interactive (print) mode and exit
cat file | claude -p "summarize" Process piped input
claude -c Continue the most recent conversation
claude -r "name" Resume by name or session ID
claude --bg "task" Run a session in the background
claude update Manually update to the latest version
claude --version / -v Check version

Key startup flags:

  • --model opus: Specify the model to use (opus, sonnet, haiku, fable)
  • --permission-mode plan: Start in plan mode (no automatic edits)
  • --bare -p "query": Minimal mode (fast; does not load hooks, plugins, or CLAUDE.md)
  • --name "auth-fix": Name the session for easy resumption later

Key Bindings and Slash Commands in Interactive Mode

Shortcuts available during an interactive session (official documentation):

Shortcut Action
Esc Stop the current response (work in progress is preserved)
Ctrl+C Clear input (press twice to end the session)
Ctrl+D End the session
Ctrl+R Reverse search through command history
Shift+Tab Toggle permission mode
\ + Enter Enter multi-line input mode

Type / to display a list of slash commands. The most commonly used ones:

  • /help: Command list
  • /clear: Reset the conversation (treated as a new session)
  • /resume: Select and resume a past session from a list
  • /config: Settings screen (model, theme, auto-update channel, etc.)
  • /btw question: A side question that is not stored in the conversation (only references current context)

You can also run shell commands directly with the ! prefix:

! git status
! npm test

In this case, the output is added directly to the session's context, so you can reference it in the next prompt — for example, "The test failed. Please fix it."

Pipes and the -p Flag — CI and Script Integration

claude -p (print mode) is the standard method for non-interactive execution, used when calling from scripts or GitHub Actions:

# Summarize a log file
cat error.log | claude -p "Summarize the cause of these errors in English"

# Automate code review
git diff HEAD~1 | claude -p "Point out the issues with this diff"

# Pass JSON output to downstream processes
claude -p "Today's TODO as a JSON array" --output-format json

You can also combine background execution to run tests in parallel:

claude --bg --exec 'pytest -x'   # Launch pytest as a background job
claude agents --json              # Check running background sessions as JSON

Session Management — Resuming, Naming, and Parallel Execution

Commands for pausing and resuming long tasks:

# Resume the most recent conversation in the same directory
claude -c

# Resume by session name
claude -n "auth-refactor"   # Name the session when starting
claude -r "auth-refactor"   # Resume later by name

# Run multiple tasks in parallel in the background
claude --bg "Fix the front-end build error"
claude --bg "Increase API test coverage"
claude agents                    # List background sessions
claude attach 7c5dcf5d           # Attach to a specific session
claude logs 7c5dcf5d             # View output only

To delete all Claude-related project data (settings, history, transcripts):

claude project purge ~/work/repo --dry-run   # Preview what will be deleted
claude project purge ~/work/repo             # Actually delete

Common Issues and Solutions

command not found: claude (Mac/Linux)

Close and reopen the terminal. If the problem persists, run echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc && source ~/.zshrc and try claude again.

'irm' is not recognized (Windows)

This usually happens when running in CMD. Switch to PowerShell (a prompt starting with PS C:\) and try again.

dyld: cannot load on macOS

Your macOS version is below 13.0. Go to the Apple menu → About This Mac to check your version, then update via Software Update.

Terminal is unresponsive after authentication

Press Ctrl+C and launch claude again. If a session is lingering, run claude auth logoutclaude auth login to start fresh.

Diagnose with claude doctor

For errors not covered above, run claude doctor to display details about your installation status, PATH, authentication state, and the last update attempt. Most errors can be identified here.


Using Claude Code from the terminal starts with a single installation command, and typing claude launches an interactive session immediately. For basic operation, just remember three things: Esc (stop), Ctrl+D (exit), and /help (command list). From there, alternating between the -p flag and the -c flag covers everything from script integration to session resumption. For detailed CLI options, the official reference has a comprehensive list — refer to it when looking for a specific flag.

参考になったら ♡
Clauder Navi 編集部
@clauder_navi

Anthropic の Claude / Claude Code を中心に、日本のエンジニア向けに最新動向と実務 を毎日発信。 運営方針 は メディアについて をご覧ください。