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
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
- 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
Install steps
- macOS, Linux or WSL: run
curl -fsSL https://claude.ai/install.sh | bash. - Windows PowerShell: run
irm https://claude.ai/install.ps1 | iex. - The installer shows no progress bar. Wait, then open a new terminal.
- Check:
claude --versionprints a version number. - Go to your project:
cd my-project, then runclaude. - Sign in when asked (or later with
/login). Check withclaude auth status --text. - 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
| Command | What it does |
|---|---|
claude | start 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 -c | continue the last chat in this folder |
claude update | update now |
Settings inside a session
- /init: Claude reads the project and writes a starter
CLAUDE.md. Edit it to be short and true. - 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.
- /model: switch model. /compact: shrink a long chat. /usage: see what is using your plan.
- Esc: stop Claude mid-step. /ide: connect to VS Code or JetBrains for diffs, when you run it in an external terminal.
Configuration files
- CLAUDE.md (project root): rules, test command, files to avoid.
- ~/.claude/settings.json (you) or .claude/settings.json (shared in the repo): permissions, environment variables, MCP servers.
- Deny secret files so Claude never reads them:
{
"permissions": {
"deny": ["Read(./.env)", "Read(./secrets/**)", "Bash(rm -rf:*)"]
}
}First task (5 minutes)
- In a small repo run
claude, then type: “Explain this project in 5 lines.” - Then: “Add a test for the add function in utils.py and run pytest.”
- Read each proposed edit and command. Approve with care.
- Check with
git diffyourself. Commit only what you understand.
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.
नमस्कार मित्रांनो. वरच्या chapter मध्ये आपण Claude Code install करून claude command ने कसं सुरू करायचं ते पाहिलं. आता पूर्ण setup चालतो का ते तपासूया: command PATH मध्ये आहे, तुम्ही sign in आहात, आणि Claude file वाचून fix सुचवतो आणि tests चालवतो, पण प्रत्येक step ला तुमची परवानगी घेतो. हा सराव Banyan Bus Depot नावाच्या काल्पनिक bus depot वर आहे. Starter fare.py मध्ये 4 tests fail आणि 3 pass होतात, आणि बरोबर fix केल्यावर सगळे 7 pass होतात.
नमस्ते दोस्तों. ऊपर के chapter में हमने Claude Code install करके claude command से शुरू करना देखा. अब पूरा setup चलता है या नहीं, यह जांचते हैं: command PATH में है, आप sign in हो, और Claude file पढ़कर fix सुझाता है और tests चलाता है, पर हर step पर आपकी मंज़ूरी लेता है. यह अभ्यास Banyan Bus Depot नाम के काल्पनिक bus depot पर है. Starter fare.py में 4 tests fail और 3 pass होते हैं, और सही fix के बाद सभी 7 pass होते हैं।
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.
Ravindra Bagale's Tip – मराठी
सुरुवातीला Claude Code claude --permission-mode manual ने सुरू करा, म्हणजे प्रत्येक edit आणि command आधी तो परवानगी मागेल. प्रत्येक request वाचा आणि मगच approve करा. आधी समजणं, वेग नंतर.
Ravindra Bagale's Tip – हिंदी
शुरुआत में Claude Code को claude --permission-mode manual से चलाओ, ताकि हर edit और हर command से पहले वह पूछे. हर request पढ़ो, फिर approve करो. पहले समझ, रफ़्तार बाद में।
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.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)
- Create the practice folder with the name shown below, and save the two files from this section inside it.
- Create a virtual environment: on macOS or Linux run
python3 -m venv .venv. On Windows runpy -3 -m venv .venv. - 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. - 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):
"""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:
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.txtRead 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
- Check the command: open a new terminal and run
claude --version. A working install prints a version number. - Start in the folder, in Manual mode: run
cd banyan-faresand thenclaude --permission-mode manual. Manual mode asks before every edit and command. As of November 2026, a plainclaudein a terminal can start in auto mode on recent versions, which approves many actions for you. - Sign in if asked: on first use Claude Code opens your browser to log in. Inside the session, type
/statusto confirm which sign-in method is active. - Paste the prompt above and wait. Claude reads both files and then asks before it edits
fare.py. - Approve with care: read the proposed edit. Approve it only if it changes
fare.pyand not the test file. Then read the test command it wants to run and approve that too. - Confirm yourself: exit Claude Code and run
python -m pytest -qin 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
- Problem:
command not found: claudeor'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/binon macOS and Linux, so add it withecho 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrcand thensource ~/.bashrc. Use~/.zshrcinstead if your shell is zsh. - Problem: on Windows you see
'irm' is not recognized. Fix: you are in Command Prompt, not PowerShell. Open PowerShell and runirm https://claude.ai/install.ps1 | iex, or use the CMD install command from the official setup page. - 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 hereprompt, or runclaude auth login. - 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. - Problem:
API Error: 403after 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. - Problem: an error says the organization has been disabled even though your subscription is active. Fix: an old
ANTHROPIC_API_KEYin your shell is overriding your login. Rununset ANTHROPIC_API_KEY, remove that line from your shell profile, startclaudeagain, and check with/status. - 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. - Problem: you are not sure what is wrong. Fix: type
/doctorinside Claude Code, or runclaude doctorin your shell ifclaudewill 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.
Start in Manual mode while you learn
claude --permission-mode manual so Claude asks before every edit and every command.Check the setup in three commands
claude --version proves the program is on your PATH./status shows how you are signed in, and /doctor checks the install.शिकताना Manual mode वापरा
claude --permission-mode manual ने सुरू करा, म्हणजे प्रत्येक edit आणि command आधी Claude परवानगी मागतो.तीन commands ने setup तपासा
claude --version ने program PATH मध्ये आहे हे कळतं./status ने sign in कसं आहे ते दिसतं, आणि /doctor install तपासतो.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
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.