Ravindra BagaleCourses & study guides Track your progress
AI CODING ASSISTANTS · CHAPTER 2 · SETUP

How to Use Claude Code in the Terminal (CLI Setup, Step by Step)

Claude Code also runs as a command-line tool. Type claude in any terminal, in any editor, even on a server over SSH. It reads your project, edits files and runs commands with your permission.

In short: install with one command, run claude in your project folder, sign in, run /init to create CLAUDE.md, and keep permission prompts on.

Why use the CLI

WHY

The terminal works everywhere: Neovim, Vim, Emacs, IntelliJ's terminal, a remote Linux box. You are not tied to one editor. You can also script it with claude -p for one-shot jobs.

What you need

WHAT
  • A supported system: macOS 13+, Windows 10 1809+, Ubuntu 20.04+, Debian 10+ or Alpine 3.19+. 4 GB+ RAM.
  • An Anthropic account: a paid Claude plan (Pro, Max, Team, Enterprise) or a Claude Console account (pay per use).
  • A terminal: Bash, Zsh, PowerShell or CMD. Internet is required.

How it flows

1 · Install one command 2 · cd into project claude 3 · Sign in browser login, once 4 · /init creates CLAUDE.md 5 · Ask + approve read each edit and command

Install steps

HOW
  1. macOS, Linux or WSL: run curl -fsSL https://claude.ai/install.sh | bash.
  2. Windows PowerShell: run irm https://claude.ai/install.ps1 | iex.
  3. The installer shows no progress bar. Wait, then open a new terminal.
  4. Check: claude --version prints a version number.
  5. Go to your project: cd my-project, then run claude.
  6. Sign in when asked (or later with /login). Check with claude auth status --text.
  7. Native installs update themselves. To update by hand: claude update.
curl -fsSL https://claude.ai/install.sh | bash
claude --version
cd my-project
claude

Daily commands

CommandWhat it does
claudestart a chat in this folder
claude "explain this project"start with a first prompt
claude -p "..."one answer, then exit (good for scripts)
cat log.txt | claude -p "explain"send a file's text in
claude -ccontinue the last chat in this folder
claude updateupdate now

Settings inside a session

  1. /init: Claude reads the project and writes a starter CLAUDE.md. Edit it to be short and true.
  2. Permission modes: press Shift+Tab to cycle modes: manual, accept edits and plan, plus auto mode where it is available. Beginners: stay in manual or plan.
  3. /model: switch model. /compact: shrink a long chat. /usage: see what is using your plan.
  4. Esc: stop Claude mid-step. /ide: connect to VS Code or JetBrains for diffs, when you run it in an external terminal.

Configuration files

  1. CLAUDE.md (project root): rules, test command, files to avoid.
  2. ~/.claude/settings.json (you) or .claude/settings.json (shared in the repo): permissions, environment variables, MCP servers.
  3. Deny secret files so Claude never reads them:
.claude/settings.json
{
  "permissions": {
    "deny": ["Read(./.env)", "Read(./secrets/**)", "Bash(rm -rf:*)"]
  }
}

First task (5 minutes)

  1. In a small repo run claude, then type: “Explain this project in 5 lines.”
  2. Then: “Add a test for the add function in utils.py and run pytest.”
  3. Read each proposed edit and command. Approve with care.
  4. Check with git diff yourself. Commit only what you understand.
Rule: never run Claude Code with permission checks turned off on your real machine or on a production server.

Verify your setup: let Claude Code fix a small bus fare bug, with your approval

Hello friends. The chapter above showed how to install Claude Code and start it with the claude command. Now we prove the whole setup works: the command is on your PATH, you are signed in, and Claude can read a file, propose a fix and run the tests while you approve each step. The practice is a fictional bus depot called Banyan Bus Depot. The starter fare.py fails 4 tests and passes 3, and a correct fix passes all 7.

Ravindra Bagale's Tip

For your first runs, start Claude Code with claude --permission-mode manual so it asks before every edit and every command. Read each request, then approve it. Speed comes later; understanding comes first.

Practice label: Banyan Bus Depot and its fare rule are fictional teaching data. It is not a real bus service, and no real passenger data is used. Passing these tests proves only the listed cases.
Environment (tested): on 16 November 2026 the starter and fixed files below were run on this course's Linux build machine with Python 3.13.5 and pytest 9.1.1. Starter: 4 failed, 3 passed. Fixed file: 7 passed. The AI tool itself runs on your own computer, so its words will differ from any example here.
Checked against official docs: every menu name, command and setting in this practice was checked on 16 November 2026 against the Claude Code setup, quickstart, permission modes, troubleshooting and installation troubleshooting pages on code.claude.com. These tools update often. If a menu name looks different on your screen, search for the same words in the official docs or the Command Palette, and do not guess.

Your task: start Claude Code inside the practice folder and ask it to make bus_fare charge 10 rupees for the first 2 km and 3 rupees for every started kilometre after that, and reject a distance of 0 or less with a message that contains km.

Setup (practice folder banyan-fares)

HOW
  1. Create the practice folder with the name shown below, and save the two files from this section inside it.
  2. Create a virtual environment: on macOS or Linux run python3 -m venv .venv. On Windows run py -3 -m venv .venv.
  3. Activate it: on macOS or Linux run source .venv/bin/activate. In Windows Command Prompt run .venv\Scripts\activate.bat, and in Windows PowerShell run .venv\Scripts\Activate.ps1.
  4. Install pytest inside the virtual environment: python -m pip install pytest.

Starter fare.py (int() drops part kilometres, and 0 or negative km is accepted):

fare.py
"""Banyan Bus Depot fare helper (fictional teaching depot, not a real bus service)."""


def bus_fare(km: float) -> int:
    """Return the fare in rupees: 10 for the first 2 km, then 3 for every started km."""
    # Starter bugs: int() drops part kilometres, and a distance of 0 or less is not rejected.
    if km <= 2:
        return 10
    return 10 + 3 * int(km - 2)

Simple tests test_fare.py:

test_fare.py
import pytest

from fare import bus_fare


def test_one_km_is_minimum_fare():
    assert bus_fare(1) == 10


def test_two_km_is_minimum_fare():
    assert bus_fare(2) == 10


def test_three_km():
    assert bus_fare(3) == 13


def test_part_km_counts_as_started_km():
    assert bus_fare(2.5) == 13


def test_five_point_two_km():
    assert bus_fare(5.2) == 22


def test_zero_km_rejected():
    with pytest.raises(ValueError, match="km"):
        bus_fare(0)


def test_negative_km_rejected():
    with pytest.raises(ValueError, match="km"):
        bus_fare(-4)

Before you ask the AI, run python -m pytest -q in the folder. You should see 4 failed, 3 passed. That proves Python and pytest work before the AI tool is involved.

The exact prompt to try (copy it as it is):

claude-prompt.txt
Read fare.py and test_fare.py. Fix bus_fare for the fictional Banyan Bus Depot: 10 rupees for the first 2 km, then 3 rupees for every started km after that, so 2.5 km costs 13. Raise ValueError with a message that contains km when km is 0 or less. Do not change test_fare.py. Then run python -m pytest -q and show me the result.

HOW to verify your Claude Code setup

HOW
  1. Check the command: open a new terminal and run claude --version. A working install prints a version number.
  2. Start in the folder, in Manual mode: run cd banyan-fares and then claude --permission-mode manual. Manual mode asks before every edit and command. As of November 2026, a plain claude in a terminal can start in auto mode on recent versions, which approves many actions for you.
  3. Sign in if asked: on first use Claude Code opens your browser to log in. Inside the session, type /status to confirm which sign-in method is active.
  4. Paste the prompt above and wait. Claude reads both files and then asks before it edits fare.py.
  5. Approve with care: read the proposed edit. Approve it only if it changes fare.py and not the test file. Then read the test command it wants to run and approve that too.
  6. Confirm yourself: exit Claude Code and run python -m pytest -q in the same folder. Expect 7 passed.

What a correct result looks like: Claude says the starter rounds part kilometres down and does not reject 0 or negative distances. Its edit uses rounding up, for example math.ceil(km - 2), and raises ValueError with km in the message. After you approve the test command, Claude shows 7 passed, and your own pytest run matches. If Claude edits test_fare.py, reject that edit, because the tests describe the correct fare.

Real pytest output after the fixed file:

pytest-after.txt
.......                                                                  [100%]
7 passed in 0.01s
Optional completed fare.py (try it yourself first)

Claude may write the checks in a different order. Any version is fine if all 7 tests pass and the test file is unchanged.

fare.py
"""Banyan Bus Depot fare helper (fictional teaching depot, not a real bus service)."""
import math


def bus_fare(km: float) -> int:
    """Return the fare in rupees: 10 for the first 2 km, then 3 for every started km."""
    if km <= 0:
        raise ValueError("km must be more than 0")
    if km <= 2:
        return 10
    return 10 + 3 * math.ceil(km - 2)

Troubleshooting: common Claude Code setup problems

HOW
  1. Problem: command not found: claude or 'claude' is not recognized. Fix: first open a new terminal, because an old window keeps its old PATH. If it still fails, the installer puts the program in ~/.local/bin on macOS and Linux, so add it with echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc and then source ~/.bashrc. Use ~/.zshrc instead if your shell is zsh.
  2. Problem: on Windows you see 'irm' is not recognized. Fix: you are in Command Prompt, not PowerShell. Open PowerShell and run irm https://claude.ai/install.ps1 | iex, or use the CMD install command from the official setup page.
  3. Problem: the browser does not open during login. Fix: press c to copy the login URL and paste it into your browser yourself. Over SSH, WSL2 or a container, open that URL on your own computer and paste the code it shows at the Paste code here prompt, or run claude auth login.
  4. Problem: OAuth error: Invalid code. Fix: the code expired or was cut while copying. Press Enter to try again and finish the login quickly after the browser opens.
  5. Problem: API Error: 403 after login. Fix: on a Pro or Max plan, check that your subscription is active in your claude.ai settings. On a Console account, ask your admin to give you the Claude Code or Developer role.
  6. Problem: an error says the organization has been disabled even though your subscription is active. Fix: an old ANTHROPIC_API_KEY in your shell is overriding your login. Run unset ANTHROPIC_API_KEY, remove that line from your shell profile, start claude again, and check with /status.
  7. Problem: Claude edits files without asking. Fix: the session started in auto mode. Press Shift+Tab to change mode, or restart with claude --permission-mode manual.
  8. Problem: you are not sure what is wrong. Fix: type /doctor inside Claude Code, or run claude doctor in your shell if claude will not start. It prints read-only checks of your install and settings.

Practice cards: English and spoken Marathi

Each card below explains one idea on its own, so you can save or revise a single card without reading the whole chapter.

PRACTICE CARDAI Coding

Start in Manual mode while you learn

Run claude --permission-mode manual so Claude asks before every edit and every command.
Recent versions can start in auto mode, so choose the mode yourself for practice work.
Ravindra Bagale · ravindrabagale.com/ai-coding
PRACTICE CARDAI Coding

Check the setup in three commands

claude --version proves the program is on your PATH.
Inside the session, /status shows how you are signed in, and /doctor checks the install.
Ravindra Bagale · ravindrabagale.com/ai-coding
सराव कार्डमराठी

शिकताना Manual mode वापरा

claude --permission-mode manual ने सुरू करा, म्हणजे प्रत्येक edit आणि command आधी Claude परवानगी मागतो.
नवीन versions auto mode मध्ये सुरू होऊ शकतात, म्हणून सरावासाठी mode तुम्हीच निवडा.
Ravindra Bagale · ravindrabagale.com/ai-coding
सराव कार्डमराठी

तीन commands ने setup तपासा

claude --version ने program PATH मध्ये आहे हे कळतं.
Session मध्ये /status ने sign in कसं आहे ते दिसतं, आणि /doctor install तपासतो.
Ravindra Bagale · ravindrabagale.com/ai-coding

Quick quiz

1. What command installs Claude Code on macOS or Linux?

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

2. Which command creates a starter CLAUDE.md?

/init inside a session.

3. How do you get one answer and exit, for scripts?

claude -p "your question".

4. Which key cycles permission modes?

Shift+Tab.

Save tokens and money

SMART AI USE

Start Claude in the right subfolder, not your whole home folder. Use claude -p with piped input for small jobs. Run /compact or start a fresh session for each new task. Keep CLAUDE.md short.

Save these cards

INTERVIEW CARDAI Coding

Claude Code CLI vs VS Code extension?

CLI: any terminal, any editor, SSH, scripts (-p).
Extension: graphical panel and diffs inside VS Code.
Ravindra Bagale · ravindrabagale.com/ai-coding
COMPARISON CARDAI Coding

claude vs claude -p

claude: interactive chat, multi-step.
claude -p: one answer then exit; good for pipes and scripts.
Ravindra Bagale · ravindrabagale.com/ai-coding
REVISION CARDAI Coding

CLI in 4

Install script → new terminal → claude --version.
cd project → claude → sign in.
/init, Shift+Tab modes, deny .env.
Ravindra Bagale · ravindrabagale.com/ai-coding