Library · Automation: browser, screen and schedules

Claude Code CLI: when the terminal beats the IDE

Builder50 minUpdated: October 2026
42 of 105 in the library

Time: about 20 min theory + 30 min practice


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.

🎨 Picture this: VS Code is like an office computer with a mouse. The CLI is like phoning instructions to a mechanic in a garage. When there's one mechanic and you need to give jobs to three crews at once, the phone (CLI) works better than walking over to explain things to each crew in person.


Key concepts

  • The claude command: starts Claude from anywhere in the terminal
  • The -p flag (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.md in 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.

bash
# 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
claude

Claude 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

🎨 Picture this: the Claude CLI is like a Swiss Army knife. The fully opened knife (interactive mode) is a full conversation. One specific tool from the knife (the -p flag) is a quick, targeted action. The pipe is passing the knife down a line of hands.

1. Interactive mode (like in VS Code)

bash
cd my-project/
claude
# A full chat opens inside the terminal

2. Single request with -p (print mode)

bash
# 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

bash
# 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

bash
# 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.txt

The CLI in scripts: real examples

🎨 Picture this: the CLI in a script is like an autopilot on a plane. The pilot sets the route once, then the plane flies itself. A script with Claude Code works the same way: you set it up once, and it runs every day without you.

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.

bash
#!/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:

bash
#!/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:

bash
#!/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 0

CLI vs MCP Marketplace: which to choose when

🎨 Picture this: the CLI is like a hammer and nails. Always at hand, fast, reliable. MCP (Model Context Protocol) is like specialized construction gear (a hammer drill, a laser level). You need it for specific jobs, but it has to be installed and set up.

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

🎨 Picture this: Git worktrees are like several desks on one computer. On one you build a feature, on another you fix a bug, on the third Claude runs tests, all at the same time, without switching branches.

bash
# 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 independently

Claude 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.md files for different tasks
  • You can run a code review in one worktree while writing code in another

Useful CLI flags

bash
# 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-reference

Claude Code in GitHub Actions

yaml
# .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_SUMMARY

For 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

  1. Install the CLI with the native installer (the command at the top of the lesson)
  2. Check that it works: claude -p "Write hello world in Python"
  3. Try a pipe: cat your-script.py | claude -p "Find the bugs"
  4. Create a daily-report.sh that analyzes git log and sends a summary
  5. Add a pre-commit hook with code review

Tools and resources


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 -p flag 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