← Back to Tutorials

Getting Started with Claude Code on the CLI

AI

What is Claude Code?

Claude Code is Anthropic's official command-line interface (CLI) tool that brings Claude's AI capabilities directly into your terminal. It acts as an interactive agent that can read and edit files, run shell commands, search codebases, and help with complex software engineering tasks — all from the command line.

Claude Code is particularly powerful for infrastructure engineers and developers who want to leverage AI for system architecture, automation scripting, code review, troubleshooting, and documentation — what can be called AI-Augmented Infrastructure Engineering.

Prerequisites

  • Node.js 18+ installed on your system
  • An Anthropic API key or a Claude Pro/Max subscription
  • A terminal (Linux, macOS, or Windows with WSL)

Installation

Install via npm (Recommended)

npm install -g @anthropic-ai/claude-code

Verify Installation

claude --version

Authentication

On first launch, Claude Code will prompt you to authenticate. You have two options:

Option 1: Anthropic API Key

Set your API key as an environment variable:

export ANTHROPIC_API_KEY="sk-ant-your-key-here"

To persist across sessions, add it to your shell profile:

echo 'export ANTHROPIC_API_KEY="sk-ant-your-key-here"' >> ~/.bashrc
source ~/.bashrc

Option 2: Claude Pro/Max Subscription

Simply run claude and follow the OAuth login flow in your browser. This links your subscription directly.

Basic Usage

Start an Interactive Session

claude

This opens an interactive chat where you can ask Claude to help with coding, debugging, infrastructure tasks, and more.

One-Shot Commands

Run a single prompt without entering interactive mode:

claude -p "Explain what this Kubernetes deployment does" < deployment.yaml

Pipe Input

Pipe files or command output directly to Claude:

cat /var/log/syslog | claude -p "Summarize any errors in this log"
kubectl get pods -o yaml | claude -p "Are there any pods in a crash loop?"

Working with Projects

Claude Code is context-aware. Navigate to your project directory before starting:

cd /path/to/your/project
claude

Claude can then read your files, understand the codebase structure, and make targeted edits. It will ask for permission before modifying files or running commands.

Project Instructions with CLAUDE.md

Create a CLAUDE.md file in your project root to give Claude persistent context:

# CLAUDE.md
This is a Kubernetes-based microservices platform.
- Infrastructure is managed with Terraform in /infra
- Services are in /services, each with their own Dockerfile
- CI/CD runs through GitHub Actions
- Always use the staging namespace for testing changes

Claude reads this automatically and follows the instructions throughout the session.

Useful Slash Commands

Inside an interactive session, use these built-in commands:

  • /help — Show available commands
  • /clear — Clear conversation context
  • /compact — Compress the conversation to save context window space
  • /cost — Show API usage costs for the current session
  • /init — Generate a CLAUDE.md file for the current project

Infrastructure Engineering Use Cases

Claude Code is a force multiplier for infrastructure work. Here are practical examples:

Analyze and Debug Configurations

claude -p "Review this nginx config for security issues" < /etc/nginx/nginx.conf

Generate Terraform Modules

claude
> Create a Terraform module for an AWS VPC with public and private subnets,
  NAT gateway, and flow logs enabled

Write Automation Scripts

claude
> Write a bash script that checks disk usage on all mounted volumes,
  sends a Slack alert if any exceed 85%, and logs results to /var/log/disk-check.log

Troubleshoot Live Systems

journalctl -u kubelet --since "1 hour ago" | claude -p "What's causing the kubelet issues?"

Document Infrastructure

claude
> Read through the Ansible playbooks in /ansible and generate
  a runbook documenting what each playbook does and when to use it

Configuration and Settings

Global Settings

Claude Code stores settings in ~/.claude/. You can configure behavior like auto-approve permissions for trusted operations.

Permission Modes

Claude Code asks for permission before running commands or editing files. You can adjust this:

  • Default: Asks for approval on every action
  • Auto-approve reads: Allows file reads without prompting
  • Dangerously skip permissions: Use only in trusted, isolated environments

Model Selection

Toggle between available models during a session:

/model opus     # Use Claude Opus (most capable)
/model sonnet   # Use Claude Sonnet (faster)
/model haiku    # Use Claude Haiku (fastest, most affordable)

Tips for Effective Use

  • Be specific: Instead of "fix the config," say "update the Kubernetes service to use NodePort 30080 instead of ClusterIP."
  • Provide context: Tell Claude about your environment, constraints, and what you've already tried.
  • Use CLAUDE.md: Project-level instructions save time by eliminating repetitive context.
  • Pipe real data: Feed logs, configs, or command output directly for accurate analysis.
  • Review before applying: Always review Claude's suggested changes before accepting edits to production configs.
  • Use for documentation: Claude excels at generating runbooks, READMEs, and architecture docs from existing code.

LLM-Assisted Engineering Workflow

Integrating Claude Code into your daily workflow creates an LLM-Assisted Engineering practice:

  • Design: Describe requirements and have Claude draft architecture, Terraform, or Kubernetes manifests.
  • Build: Use Claude to write automation scripts, CI/CD pipelines, and monitoring configurations.
  • Debug: Pipe logs and metrics to Claude for rapid root cause analysis.
  • Document: Auto-generate documentation from your codebase and infrastructure configs.
  • Review: Have Claude audit configs for security, performance, and best practices.

This approach accelerates delivery, reduces human error, and ensures consistent documentation across your infrastructure.