The gist
VS Code with the extension is pretty and comfortable for beginners. But the real power of Claude Code shows up in the terminal: scripts, automation, CI/CD (Continuous Integration/Delivery: automatic building and shipping of code), chat bots (automated programs), and scheduled tasks (run on a timetable through the cron scheduler). The CLI (command-line interface) runs where there's no graphical interface at all: on a server, in Docker, through GitHub Actions.
Key concepts
- The
claudecommand: starts Claude from anywhere in the terminal - The
-pflag (print mode): a single request without the interactive mode - stdin/stdout/pipe: Claude as one link in a Unix chain of commands
--model/--max-budget-usd: control over the model and the cost- Headless mode (no graphical interface): for automation with no human in the loop
- API (application programming interface): the way programs talk to services
CLAUDE.mdin the folder: project context works in the CLI exactly the same as in VS Code
Theory
Installing the CLI
As of October 2026 the main way is the native installer (it updates itself). Current methods and system requirements: installation docs.
# macOS, Linux, WSL
curl -fsSL https://claude.ai/install.sh | bash
# Windows PowerShell
irm https://claude.ai/install.ps1 | iex
# Homebrew (macOS): doesn't update itself, use brew upgrade claude-code
brew install --cask claude-code
# Via npm (needs Node.js 22+): also works
npm install -g @anthropic-ai/claude-code
# Check the installation
claude --version
# First launch: browser sign-in opens
claudeClaude Code comes with the paid plans (Pro, Max, Team, Enterprise) or runs on an API key from the Console; it isn't included in the free claude.ai plan. Current prices and plans: What's current.
The CLI and the VS Code extension use the same account: sign in to one and it works in both.
CLI modes
1. Interactive mode (like in VS Code)
cd my-project/
claude
# A full chat opens inside the terminal2. Single request with -p (print mode)
# Asks a question and prints the answer right away
claude -p "Write a Python function that calculates sales tax"
# Pick the model
claude -p --model haiku "I need a quick answer"
# Cap the budget
claude -p --max-budget-usd 0.10 "Review this code"3. stdin: passing data through a pipe
# Analyze a file
cat server.log | claude -p "Find the errors and explain the causes"
# Analyze code
cat app.py | claude -p "Find potential bugs in this code"
# Analyze the output of another command
git diff HEAD~3 | claude -p "Write a changelog for these changes"
# Data from JSON
curl -s api.example.com/data.json | claude -p "Find anomalies in the data"4. File context
# Claude reads the file and answers the question
claude -p "What does this code do?" < main.py
# Several files through a temporary file
cat requirements.txt Dockerfile > /tmp/context.txt
claude -p "Are there any version conflicts?" < /tmp/context.txtThe CLI in scripts: real examples
Daily code report:
You can schedule runs with cron, and Claude Code itself has built-in routines and /loop: see the lesson Loop vs Scheduled Tasks.
#!/usr/bin/env bash
# daily-code-review.sh: runs every morning at 09:00
cd ~/project/
# Collect yesterday's changes
CHANGES=$(git log --since="1 day ago" --oneline)
if [ -z "$CHANGES" ]; then
echo "No changes"
exit 0
fi
# Send to Claude for analysis
SUMMARY=$(echo "$CHANGES" | claude -p "
Analyze these git commits from yesterday.
Point out: the main changes, possible risks, what should be tested.
Format: short bullets, no more than 200 words.
")
# Send to Telegram
curl -s -X POST "https://api.telegram.org/bot${BOT_TOKEN}/sendMessage" \
--data-urlencode "chat_id=${CHAT_ID}" \
--data-urlencode "text=📊 Yesterday's summary:\n${SUMMARY}"Automatic documentation:
#!/usr/bin/env bash
# generate-docs.sh
for file in src/**/*.py; do
echo "Documenting: $file"
# Generate a docstring for every function
# (work in a separate git branch and check git diff: the model may add extra text)
DOCS=$(cat "$file" | claude -p "
Add detailed docstrings to every function in this Python file.
Format: Google Style. Return only the code with the docstrings added.
")
# Overwrite the file
echo "$DOCS" > "$file"
done
echo "Documentation updated!"Code review before a commit:
#!/usr/bin/env bash
# pre-commit-review.sh (can be added to .git/hooks/pre-commit)
STAGED=$(git diff --cached)
if [ -z "$STAGED" ]; then
exit 0
fi
REVIEW=$(echo "$STAGED" | claude -p "
You are an experienced code reviewer.
Check these changes for: bugs, security issues, bad practices.
If everything is fine, reply PASS.
If there are problems, list them briefly.
")
echo "$REVIEW"
# If Claude found problems, block the commit
if [[ "$REVIEW" != *"PASS"* ]]; then
echo "❌ Code review found problems. Fix them and try again."
exit 1
fi
echo "✅ Code review passed"
exit 0CLI vs MCP Marketplace: which to choose when
| Task | CLI | MCP |
|---|---|---|
| Single request | ✅ Perfect | Overhead |
| Automation script | ✅ Native | Harder |
| CI/CD pipeline | ✅ Simple | Complex setup |
| Telegram/Discord bot | ✅ Via -p |
No point |
| Database access | MCP is better | ✅ Native integration |
| Browser automation | MCP is better | ✅ Playwright MCP |
| GitHub integration | Both are good | ✅ GitHub MCP |
| Working offline | ✅ Works | Needs a server |
| Docker/serverless | ✅ Native | Complex configuration |
Rule: the CLI for automation and scripts. MCP for integrations with specific services in interactive mode.
Git Worktrees: working in parallel
# Create a separate folder for a new feature
git worktree add ../project-feature-X feature/new-payment
# In the main folder: current work
cd ~/project/
claude # Working on the main branch
# In the neighboring folder: another Claude
cd ~/project-feature-X/
claude # The second Claude works on the feature independentlyClaude Code can create a worktree on its own: claude -w feature-auth starts a session in an isolated working copy.
Benefits:
- Different Claude sessions don't get in each other's way
- Different
CLAUDE.mdfiles for different tasks - You can run a code review in one worktree while writing code in another
Useful CLI flags
# Main flags
claude -p "request" # Print mode (no interaction)
claude -p --model haiku # Pick a model by alias (sonnet, opus, haiku, fable) or full name
claude -p --max-budget-usd 0.50 # Cost cap (print mode only)
claude -p --max-turns 3 # Cap on the number of agent steps
claude -p --tools "" # Disable all built-in tools (safety)
claude -p --output-format json # Output as JSON
# Working with context
claude --add-dir ../lib # Give access to an extra folder
claude --append-system-prompt "Answer in Spanish" # Add a rule to the system prompt (the instructions to the AI)
# Autonomous mode
claude --dangerously-skip-permissions # Skip confirmations (for CI)
# Use only in isolated environments (Docker, GitHub Actions)!
# Full list of flags: https://code.claude.com/docs/en/cli-referenceClaude Code in GitHub Actions
# .github/workflows/ai-review.yml
name: AI Code Review
on: [pull_request]
jobs:
ai-review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Install Claude Code CLI
run: npm install -g @anthropic-ai/claude-code
- name: Get PR diff
run: git diff origin/main...HEAD > /tmp/pr-diff.txt
- name: AI Review
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
run: |
# --tools "": PR text is untrusted (prompt injection), so Claude only reads the diff and replies, with no tools
REVIEW=$(cat /tmp/pr-diff.txt | claude -p \
--tools "" \
--max-budget-usd 1.00 \
"Review this PR for bugs and security issues. Be brief.")
echo "## AI Code Review" >> $GITHUB_STEP_SUMMARY
echo "$REVIEW" >> $GITHUB_STEP_SUMMARYFor reviewing PRs and answering @claude in comments there's also an official GitHub Action from Anthropic: anthropics/claude-code-action@v1 (quick setup with the /install-github-app command). Details: GitHub Actions docs.
Practice
- Install the CLI with the native installer (the command at the top of the lesson)
- Check that it works:
claude -p "Write hello world in Python" - Try a pipe:
cat your-script.py | claude -p "Find the bugs" - Create a daily-report.sh that analyzes git log and sends a summary
- Add a pre-commit hook with code review
Tools and resources
- Claude Code CLI docs: the official guide; flag reference: CLI reference
- Anthropic Claude Code GitHub: issues, the changelog and example plugins
- Node.js 22+: needed only if you install via npm
- Git Worktrees: official documentation
Key takeaways
The CLI opens Claude Code up to automation: scripts, CI/CD, bots, scheduled tasks. Where there's no GUI, the CLI is the only option.
The
-pflag turns Claude into a Unix tool:cat file | claude -p "analyze". That opens up endless combinations with other commands.
The CLI where you need speed and automation. MCP where you need integration with a specific service (database, browser, GitHub).
Next lesson
→ Competitors that lost: the story of Devin, Windsurf and Manus
The mark stays in this browser only and is never sent anywhere. My progress