Claude Code went from zero to the most-used AI coding tool in eight months. If you work in DevOps and still haven’t set it up, you are leaving serious productivity on the table. This guide covers everything — installation, configuration, CLAUDE.md setup, and real workflows for Terraform, Kubernetes, and AWS.
What is Claude Code and Why DevOps Engineers Are Switching
Claude Code is a terminal-first AI coding agent built by Anthropic. Unlike GitHub Copilot, which completes your current line, or Cursor, which sits inside an IDE, Claude Code runs in your terminal and operates as an autonomous agent. You give it a task — “review this Terraform plan for security issues” — and it reads files, runs commands, and iterates until the task is done.
The reason senior engineers are switching is simple: Claude Code fits how infrastructure work actually happens. You are already in the terminal. You are already working with files, git, and config. Claude Code plugs directly into that workflow without forcing you into a new editor.
Three key differences from other tools:
- Agent loops, not autocomplete — Claude Code doesn’t just suggest the next word. It reads multiple files, executes commands, and makes a series of decisions to complete a task end-to-end.
- Context awareness — It understands your entire project via the CLAUDE.md file (more on this below), not just the current file.
- Terminal native — No IDE required. Works over SSH, in CI/CD, inside Docker containers, or on a remote server.
Installing Claude Code
Requirements: Node.js 18 or later.
npm install -g @anthropic-ai/claude-code
Verify installation:
claude --version
Authenticate with your Anthropic account:
claude login
This opens a browser window to authenticate. Once done, your API key is stored locally. If you prefer manual key setup:
export ANTHROPIC_API_KEY="your_key_here"
Add that to your .bashrc or .zshrc to make it permanent.
Claude Code running in terminal — writing production Terraform modules from natural language instructions
Your First Claude Code Session
Navigate to your project directory and start a session:
cd ~/my-infrastructure-repo
claude
You are now in an interactive session. Try these basic commands:
- Ask a question:
explain the VPC setup in main.tf - Edit a file:
add a lifecycle rule to the S3 bucket in storage.tf - Run and fix:
run terraform validate and fix any errors - Explain unfamiliar code:
explain what this Ansible role does
Claude reads your project files automatically when you reference them. It understands context across multiple files — if your VPC is defined in networking.tf and referenced in ec2.tf, Claude understands both sides.
The CLAUDE.md File — Your Project Instructions
This is the single most important thing you can do to get better results. CLAUDE.md is a plain markdown file in your project root that Claude reads at the start of every session. Think of it as the onboarding doc you would give a new engineer.
touch CLAUDE.md
Here is a real example for an AWS/Terraform project:
# Project Context
This is an AWS infrastructure project using Terraform for a multi-tenant e-learning platform.
## Stack
- AWS (us-east-1 primary, eu-west-1 DR)
- Terraform 1.9 — HashiCorp style guide
- Ansible for configuration management
- Kubernetes (EKS 1.30)
- Monitoring: Prometheus + Grafana
## Rules
- Never delete production resources without explicit confirmation
- Always add these tags to every resource: Environment, Project, Owner, CostCenter
- Use remote state in S3 with DynamoDB locking
- All security groups must have descriptions
- Never use 0.0.0.0/0 in ingress rules without a comment explaining why
## Conventions
- Module names: lowercase with hyphens (e.g., `ec2-web-servers`)
- Variable names: snake_case
- Always create outputs for resources other modules may need
With this file in place, Claude Code knows your stack, your rules, and your conventions without you having to repeat them every session.
Slash Commands Every DevOps Engineer Should Know
Type / to see all available commands. The most useful ones for infrastructure work:
| Command | What It Does |
|---|---|
/help | Show all available commands |
/clear | Clear conversation context (start fresh) |
/review | Full code review of a file or directory |
/explain | Explain any code, config, or error |
/fix | Fix errors automatically |
/test | Generate tests for current code |
/commit | Generate a semantic commit message |
/pr | Generate a pull request description |
Real examples you can use today:
/review infrastructure/terraform/
/fix Can't create resource: subnet CIDR overlaps with existing
/explain this Kubernetes deployment manifest
/commit
Setting Up Custom Commands for Infrastructure Teams
You can create reusable commands that encode your team’s workflows. Create the commands directory:
mkdir -p .claude/commands
Example — create a security audit command:
<!-- .claude/commands/security-audit.md -->
Run a complete security audit of the Terraform code in the current directory.
Check for:
- Public S3 buckets (check all bucket policies and ACLs)
- Overly permissive IAM policies (wildcards, admin access)
- Unencrypted EBS volumes or RDS instances
- Missing resource tags
- Security groups with 0.0.0.0/0 ingress
- Hardcoded credentials or secrets
Output a prioritized report with HIGH / MEDIUM / LOW severity for each finding.
Now use it with /security-audit in any session.
Claude Code analyzing a Kubernetes deployment manifest for misconfigurations and security issues
Real DevOps Use Cases
Writing Terraform Modules
Write a reusable Terraform module for an ALB with HTTPS redirect,
target group, and health checks. Follow the conventions in CLAUDE.md.
Claude reads your CLAUDE.md, understands your tagging requirements, and generates a properly structured module with variables, outputs, and documentation.
Reviewing Kubernetes YAML
Review the manifests in k8s/production/ for security issues,
resource limits, and missing liveness/readiness probes.
Claude checks all files in the directory, cross-references your existing configs, and gives a prioritized list of issues.
Generating Ansible Playbooks
Write an Ansible playbook to harden a fresh Ubuntu 22.04 EC2 instance:
disable root SSH, set up fail2ban, configure UFW, install CloudWatch agent.
Debugging CI/CD Failures
Paste a Jenkins pipeline error directly and ask:
Here is my Jenkins pipeline failure. The build fails at the Terraform apply stage.
Diagnose the issue and suggest the fix:
[paste error output]
Writing AWS Lambda Functions
Write a Python Lambda function that reads Cost Explorer data daily
and sends a Slack notification if spend exceeds $50/day.
Include the IAM policy it needs.
Claude Code working autonomously — writing, testing, and fixing code in a single session
Claude Code vs GitHub Copilot vs Cursor
| Feature | Claude Code | GitHub Copilot | Cursor |
|---|---|---|---|
| Interface | Terminal | IDE extension | IDE (VS Code fork) |
| Agent capability | Full agentic loops | Limited | Partial |
| Context window | 200K tokens | ~8K tokens | 200K tokens |
| CLAUDE.md / rules | Yes | Limited | Yes (.cursorrules) |
| Works over SSH | Yes | No | No |
| Infrastructure-aware | Excellent | Good | Good |
| Price | Usage-based | $10/month | $20/month |
| Best for | Complex, multi-file tasks | Inline completion | IDE-centric work |
For DevOps engineers who live in the terminal and manage large infrastructure codebases, Claude Code wins on context, agent capability, and SSH compatibility.
Common Mistakes and How to Avoid Them
Not writing a CLAUDE.md file. Claude will give generic responses without project context. Spend 15 minutes writing a CLAUDE.md — it pays back in every session.
Being too vague. “Fix my Terraform” gives poor results. “Review main.tf for security group rules that allow unrestricted inbound access and fix them” gives excellent results.
Applying AI-generated IaC without review. Always run terraform plan and review the diff before applying. Claude is very good, but production infrastructure deserves human eyes on the output.
Ignoring context limits. For very large repos, point Claude at specific directories rather than asking it to read everything at once.
Not using custom commands. If you find yourself giving the same instructions repeatedly, turn them into a .claude/commands/ file.
FAQ
What is Claude Code? Claude Code is a terminal-based AI coding agent from Anthropic. It runs in your terminal, reads your project files, executes commands, and completes complex tasks autonomously — not just autocomplete, but full agentic workflows.
Is Claude Code free to use? Claude Code requires an Anthropic API key. There is a free tier with usage limits. For heavy daily use, expect costs in the $10–30/month range depending on project complexity and frequency.
How is Claude Code different from GitHub Copilot? Copilot suggests the next line or block of code in your IDE. Claude Code operates as an autonomous agent — it reads multiple files, runs commands, and iterates to complete full tasks end-to-end, all from your terminal.
Can Claude Code work with Terraform and AWS? Yes, and it excels at this. It understands Terraform HCL, Kubernetes YAML, Ansible playbooks, AWS CLI, and most infrastructure tooling. Set up a CLAUDE.md with your stack details for best results.
What is a CLAUDE.md file? A CLAUDE.md is a plain markdown file in your project root that gives Claude persistent instructions about your project — stack, conventions, rules, and context. Claude reads it at the start of every session so you never have to repeat yourself.
Conclusion
Claude Code is a genuine productivity multiplier for infrastructure engineers. The setup takes under five minutes. The CLAUDE.md file takes fifteen. After that, you have an AI agent that understands your full project and can handle complex, multi-step infrastructure tasks end-to-end.
Start with one real task today — a Terraform module, a Kubernetes review, a CI/CD debug session — and build from there.
Need help automating your infrastructure beyond AI tooling? View DevOps services →
Related: MCP Servers Explained: How to Connect Claude to Your Infrastructure Tools