Claude Code CLI: Essential Commands and Configuration
Claude Code is not just an AI assistant: it is a supercharged terminal that integrates into the developer's daily workflow. From the command line, you can manage files, run builds, launch tests, analyze code, and orchestrate complex tasks, all through a conversational interface that understands your project's context.
In this twelfth article in the series, we will explore in depth the Command Line Interface of Claude Code: installation methods on every platform, keyboard shortcuts that speed up your work, slash commands for agent control, the four-level configuration hierarchy, permission templates for security, and headless mode for CI/CD automation.
What You Will Learn
- Install Claude Code on macOS, Linux, Windows, and WSL
- Master keyboard shortcuts to speed up your workflow
- Use all available slash commands
- Understand the 4-level configuration hierarchy
- Configure permission templates for different security scenarios
- Run Claude Code in headless mode for CI/CD pipelines
- Troubleshoot common installation and configuration issues
- Optimize the CLI experience for daily work
Complete Series Overview
| # | Article | Focus |
|---|---|---|
| 1 | Claude as Technical Partner | Setup and first steps |
| 2 | Context and Project Setup | CLAUDE.md and configuration |
| 3 | Ideation and Requirements | MVP and user personas |
| 4 | Backend and Frontend Architecture | Spring Boot and Angular |
| 5 | Code Structure | Organization and conventions |
| 6 | Advanced Prompt Engineering | Advanced techniques |
| 7 | Testing and Quality | Strategies and test generation |
| 8 | Professional Documentation | README, API, ADR |
| 9 | Deploy and DevOps | Docker, CI/CD, monitoring |
| 10 | Evolution and Maintenance | Refactoring and scalability |
| 11 | Real Project Integration | Claude Code in production |
| 12 | Claude Code CLI (you are here) | Commands and configuration |
| 13 | Agent Skills | Modular capabilities |
| 14 | Specialized Subagents | Role-specific agents |
| 15 | Hooks and Automation | Event-driven workflows |
| 16 | Ralph Wiggum Method | Autonomous iterative dev |
| 17 | BMAD Method | AI-driven agile |
| 18 | Multi-Agent Orchestration | Agent pipelines |
| 19 | Claude Cowork | AI for knowledge workers |
| 20 | Security and Privacy | Best practices |
| 21 | Monitoring and Productivity | Metrics and dashboards |
1. Installing Claude Code
Claude Code supports multiple platforms and installation methods. The choice of method
depends on the operating system and personal preferences. All methods install the same
claude binary which is added to the system PATH.
Prerequisites
Before proceeding with the installation, make sure you meet the following requirements on your system:
System Requirements
| Requirement | Minimum Version | Notes |
|---|---|---|
| Node.js | 18.0+ | Required for the JavaScript runtime |
| npm | 9.0+ | Included with Node.js |
| Git | 2.30+ | For repository operations |
| Operating System | macOS 12+, Ubuntu 20.04+, Windows 10+ (WSL2) | Native support for Linux and macOS, WSL for Windows |
| Anthropic Account | Pro, Max, or Team plan | Required for API authentication |
Method 1: Installation via npm (Recommended)
The most universal method is global installation via npm. It works on all platforms where Node.js is available and ensures simple updates.
# Global installation
npm install -g @anthropic-ai/claude-code
# Verify installation
claude --version
# First launch and authentication
claude
# Update to the latest version
npm update -g @anthropic-ai/claude-code
Method 2: Installation via curl (macOS and Linux)
For those who prefer to avoid npm, a direct installation script is available that downloads the precompiled binary. This method is particularly useful in environments without Node.js preinstalled.
# macOS and Linux
curl -fsSL https://cli.anthropic.com/install.sh | sh
# Verify that the binary is in the PATH
which claude
# Expected output: /usr/local/bin/claude
# First run
claude
Method 3: Installation via Homebrew (macOS)
macOS users who use Homebrew as their package manager can install Claude Code through the official tap. This method integrates Claude Code into Homebrew's centralized package management.
# Add the official Anthropic tap
brew tap anthropics/claude-code
# Installation
brew install claude-code
# Update
brew upgrade claude-code
# Verify version
claude --version
Method 4: Installation on Windows (PowerShell + WSL)
On Windows, Claude Code requires WSL2 (Windows Subsystem for Linux) to work properly. The installation can be performed directly from Windows PowerShell or from within the WSL terminal.
# Step 1: Install WSL2 (if not already installed)
wsl --install
# Step 2: Open the WSL terminal (Ubuntu)
wsl
# Step 3: Install Node.js in WSL
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt-get install -y nodejs
# Step 4: Install Claude Code
npm install -g @anthropic-ai/claude-code
# Step 5: Verify
claude --version
# Alternative: Direct installation from PowerShell
# (Requires Node.js installed on Windows)
npm install -g @anthropic-ai/claude-code
Note on Windows Compatibility
Claude Code on Windows works best with WSL2 because many development tools (Git, compilers, build tools) are natively supported on Linux. If you work with projects that require Unix-like tools, WSL2 is strongly recommended. The native PowerShell experience is supported but may have limitations with certain system commands.
Authentication
After installation, the first launch of claude starts the authentication flow.
Claude Code supports two main authentication methods.
Authentication Methods
| Method | Use | Configuration |
|---|---|---|
| Anthropic Console | Individual Pro/Max accounts | Automatic browser login on first launch |
| API Key | Team, Enterprise, CI/CD accounts | Environment variable ANTHROPIC_API_KEY |
| AWS Bedrock | Enterprise on AWS infrastructure | AWS credentials configuration |
| Google Vertex AI | Enterprise on GCP infrastructure | Google Cloud credentials configuration |
# Method 1: Environment variable (current session)
export ANTHROPIC_API_KEY="sk-ant-api03-xxxxx"
# Method 2: .env file in the project root
echo 'ANTHROPIC_API_KEY=sk-ant-api03-xxxxx' >> .env
# Method 3: Permanent configuration in .bashrc or .zshrc
echo 'export ANTHROPIC_API_KEY="sk-ant-api03-xxxxx"' >> ~/.zshrc
source ~/.zshrc
# Verify authentication
claude --print-auth-status
2. Keyboard Shortcuts
Keyboard shortcuts are essential for efficient use of Claude Code. Knowing them allows you to quickly switch between operating modes, manage context, and control the execution flow without interrupting your work rhythm.
Complete Shortcuts Table
| Shortcut | Action | Detailed Description |
|---|---|---|
! |
Bash Mode | Activates direct Bash mode. Type ! followed by the command
to execute it in the terminal without Claude interpreting it as a prompt.
Example: !npm test directly runs the tests. |
@ |
Mention File/Folder | Mentions a file or folder to add them to the current context.
Supports Tab autocompletion. Example: @src/app/services/
loads the entire folder into the context. |
Esc |
Interrupt | Interrupts Claude's current operation. Useful when a generation is going in the wrong direction or taking too long. |
Esc + Esc |
Rewind Menu | Double pressing Escape opens the rewind menu that allows you to go back to a previous state of the conversation, undoing Claude's last actions. |
Ctrl+R |
Full Output | Shows the complete output of the last executed command, including parts that may have been truncated for brevity. |
Shift+Tab |
Auto-Accept (YOLO Mode) | Activates automatic acceptance mode for subsequent operations. Claude will execute actions without asking for confirmation. Use with caution in production environments. |
Shift+Tab+Tab |
Plan Mode | Activates planning mode. Claude analyzes the task, creates a structured plan, and presents it for approval before executing any action. |
Ctrl+C |
Cancel Input | Cancels the text typed in the current input without interrupting the Claude Code session. |
Ctrl+D |
Exit | Closes the current Claude Code session while saving the conversation history. |
Tab |
Autocompletion | Autocompletes file names, folders, and slash commands in the input prompt. |
YOLO Mode: Usage and Precautions
YOLO mode (You Only Live Once) activated with Shift+Tab is a
powerful but dangerous tool. When active, Claude executes all operations - including
file modifications, command execution, and package installation - without
asking the user for confirmation.
When to Use YOLO Mode
- Rapid prototyping: When you are exploring ideas in a dedicated branch
- Automated refactoring: When you have already validated the plan and want fast execution
- Boilerplate generation: When Claude needs to create many similar files
- Sandbox environments: When working in Docker containers or disposable VMs
When NOT to Use YOLO Mode
- Production: Never on main/master branches or production environments
- Destructive operations: When the task could involve file deletion
- System commands: When Claude might execute commands with sudo
- Sensitive data: When the context contains credentials or confidential data
Plan Mode: Structured Planning
Plan mode (Shift+Tab+Tab) is the opposite of YOLO mode. It forces Claude
to create a detailed plan before executing any action. The plan includes:
- Analysis of the requested task and identification of involved files
- Ordered sequence of operations to execute
- Potential risks and dependencies between operations
- Estimate of the number of files to modify
- Explicit request for approval before execution
# Activate Plan Mode with Shift+Tab+Tab, then type the prompt:
> Add email validation to the registration form
# Claude responds with a plan:
# Execution Plan:
# 1. Read src/app/auth/register.component.ts
# 2. Read src/app/auth/register.component.html
# 3. Add email validator to the FormGroup
# 4. Add error message in the template
# 5. Add tests for email validation
# 6. Update the validation service
#
# Files involved: 4
# Operations: 6
#
# Proceed? [y/n]
3. Slash Commands
Slash commands are special commands that control Claude Code's behavior.
They are typed directly in the prompt preceded by the / character. Each command
has a specific function for managing the session, context, and configuration.
Complete Slash Commands Table
| Command | Description | Usage Example |
|---|---|---|
/add-dir |
Adds a directory to the current working context | /add-dir ../shared-libs to include shared libraries |
/agents |
Shows and manages available subagents in the .claude/agents/ directory |
/agents to list all configured subagents |
/clear |
Clears the current conversation history, freeing up context | /clear after completing a task to start fresh |
/config |
Opens and modifies Claude Code configuration files | /config to view and modify settings |
/help |
Shows the complete guide of available commands | /help for quick reference |
/mcp |
Manages configured MCP (Model Context Protocol) servers | /mcp to see the status of connected servers |
/model |
Changes the AI model used in the current session | /model claude-sonnet-4-20250514 to switch to Sonnet |
/permissions |
Views and modifies permissions granted to Claude Code | /permissions to review what Claude can do |
/rewind |
Goes back to a previous state of the conversation | /rewind to undo the last actions |
/status |
Shows the current session status, context, and token usage | /status to check how many tokens have been used |
Advanced Use of Slash Commands
Slash commands can be combined in logical sequences to manage complex work sessions. Here are some advanced usage patterns.
# Pattern 1: Context reset for a new task
/clear
/add-dir ./src/features/new-feature
Implement the UserProfile component following existing patterns
# Pattern 2: Status check before critical operations
/status
/permissions
Execute the refactoring of the payment module
# Pattern 3: Model switch for specific tasks
/model claude-sonnet-4-20250514 # For quick and frequent tasks
Generate boilerplate tests for all services
/model claude-opus-4-20250514 # For complex tasks
Analyze the architecture and propose improvements
# Pattern 4: Debug MCP connections
/mcp
# Verify that the required servers are connected
# before executing tasks that require them
Custom Slash Commands
In addition to built-in commands, Claude Code supports the creation of custom commands
through Markdown files in the .claude/commands/ directory. Each .md file
becomes a slash command that can be invoked in the session.
# Complete Code Review
Perform a thorough code review of the modified files.
## Checklist
1. Verify the logical correctness of the code
2. Check naming conventions and consistency
3. Identify potential bugs or edge cases
4. Verify error handling
5. Check test coverage
6. Evaluate performance and scalability
## Output
Produce a structured report with:
- **Severity**: Critical / Major / Minor / Suggestion
- **File and line**: Precise reference
- **Issue**: Clear description
- **Solution**: Proposed fix with code
# Pre-Deploy Verification
Before proceeding with the deploy, check:
1. Run `npm run build` and verify there are no errors
2. Run `npm test` and verify all tests pass
3. Check that no console.log statements remain in the code
4. Verify that environment variables are configured
5. Check that the .env.production file is up to date
6. Verify the version in package.json
Report the status of each point with a checkmark.
Once created, custom commands are invoked with /review or
/deploy-check directly in the Claude Code prompt.
4. Configuration Hierarchy
Claude Code uses a four-level hierarchical configuration system, where each level can override the settings of the level below it. This architecture allows for granular configurations ranging from corporate policies down to the personal preferences of individual developers.
Configuration Hierarchy (from highest to lowest)
| Level | File Path | Scope | Priority |
|---|---|---|---|
| Enterprise | /etc/claude-code/managed-settings.json |
Entire organization | Highest (cannot be overridden) |
| Project Local | .claude/settings.local.json |
Individual developer in the project | High |
| Project Shared | .claude/settings.json |
All developers on the project | Medium |
| User Global | ~/.claude/settings.json |
All of the user's projects | Base |
Level 1: Enterprise (Highest Priority)
The Enterprise configuration is managed by the system administrator and is located
at /etc/claude-code/managed-settings.json. Settings defined
at this level cannot be overridden by any other level.
It is the ideal mechanism for enforcing corporate security policies.
{
"permissions": {
"deny": [
"Bash(rm -rf /*)",
"Bash(sudo *)",
"Bash(chmod 777 *)",
"Write(~/.ssh/*)",
"Write(~/.aws/*)"
]
},
"security": {
"max_file_size_bytes": 10485760,
"blocked_domains": ["*.internal.company.com"],
"require_approval_for_network": true
},
"model": {
"default": "claude-sonnet-4-20250514",
"allowed": ["claude-sonnet-4-20250514", "claude-opus-4-20250514"]
}
}
Level 2: Project Local (settings.local.json)
The .claude/settings.local.json file is specific to the individual developer
in the context of a project. This file should not be committed
to the repository (it should be added to .gitignore) because it contains personal preferences.
{
"permissions": {
"allow": [
"Bash(npm run test:watch)",
"Bash(npm run dev)",
"Bash(docker compose up -d)"
]
},
"preferences": {
"model": "claude-opus-4-20250514",
"theme": "dark",
"auto_approve_reads": true
}
}
Level 3: Project Shared (settings.json)
The .claude/settings.json file is committed to the repository and shares
the project's configurations with the entire team. This is where the rules and permissions
that all developers must follow go.
{
"permissions": {
"allow": [
"Bash(npm run *)",
"Bash(mvn *)",
"Bash(gradle *)",
"Bash(git status)",
"Bash(git diff *)",
"Bash(git log *)",
"Read(*)",
"Write(src/**/*)"
],
"deny": [
"Bash(git push --force *)",
"Bash(git reset --hard *)",
"Bash(rm -rf *)",
"Write(.env*)",
"Write(**/credentials*)",
"Write(**/secrets*)"
]
},
"context": {
"include_patterns": ["src/**/*.ts", "src/**/*.html", "src/**/*.css"],
"exclude_patterns": ["node_modules/**", "dist/**", ".angular/**"]
}
}
Level 4: User Global
The ~/.claude/settings.json file in the user's home directory contains
global preferences that apply to all projects. It is the level with
the lowest priority and is overridden by any project configuration.
{
"permissions": {
"allow": [
"Bash(ls *)",
"Bash(cat *)",
"Bash(which *)",
"Bash(node --version)",
"Read(*)"
]
},
"preferences": {
"model": "claude-sonnet-4-20250514",
"auto_approve_reads": true,
"verbose_output": false,
"language": "it"
}
}
Conflict Resolution
When the same setting is defined at multiple levels, the level with the higher priority
prevails. In the case of lists (such as allow and deny),
deny entries from higher levels always prevail over allow
entries from lower levels. This ensures that corporate security policies
cannot be bypassed.
5. Permission Templates for Security
Permissions control which actions Claude Code can perform without asking for confirmation. Correct permission configuration balances productivity and security. Here are two ready-to-use templates for common scenarios.
Template 1: Basic Security (Standard Development)
This template is ideal for everyday development on projects where you want Claude to have autonomy over common development commands, but with protection on sensitive files and destructive operations.
{
"permissions": {
"allow": [
"Bash(npm run *)",
"Bash(npm test *)",
"Bash(npm install *)",
"Bash(npx *)",
"Bash(git status)",
"Bash(git diff *)",
"Bash(git log *)",
"Bash(git branch *)",
"Bash(git checkout *)",
"Bash(git add *)",
"Bash(git commit *)",
"Bash(tsc *)",
"Bash(ng *)",
"Bash(mvn *)",
"Bash(gradle *)",
"Bash(python -m pytest *)",
"Bash(docker compose *)",
"Bash(curl *)",
"Read(*)",
"Write(src/**/*)",
"Write(tests/**/*)",
"Write(docs/**/*)"
],
"deny": [
"Write(.env*)",
"Write(**/*.pem)",
"Write(**/*.key)",
"Write(**/credentials*)",
"Write(**/secrets*)",
"Write(~/.ssh/*)",
"Write(~/.aws/*)",
"Bash(rm -rf *)",
"Bash(sudo *)",
"Bash(chmod 777 *)",
"Bash(git push --force *)",
"Bash(git reset --hard *)"
]
}
}
Template 2: Strict Security (Critical Environments)
This template requires explicit approval for all write operations and denies any network access. It is ideal for environments with sensitive data, strict compliance, or production projects.
{
"permissions": {
"allow": [
"Read(src/**/*)",
"Read(tests/**/*)",
"Read(docs/**/*)",
"Bash(git status)",
"Bash(git diff *)",
"Bash(git log *)"
],
"deny": [
"Write(*)",
"Bash(npm install *)",
"Bash(npx *)",
"Bash(curl *)",
"Bash(wget *)",
"Bash(ssh *)",
"Bash(scp *)",
"Bash(nc *)",
"Bash(git push *)",
"Bash(git commit *)",
"Bash(docker *)",
"Bash(sudo *)",
"Bash(rm *)",
"Bash(mv *)",
"Bash(cp *)"
]
},
"security": {
"require_approval_for_all_writes": true,
"require_approval_for_network": true,
"audit_log": true,
"max_file_modifications_per_session": 10
}
}
Template Comparison
| Aspect | Basic Security | Strict Security |
|---|---|---|
| File reading | Automatic on all files | Automatic only on src/tests/docs |
| File writing | Automatic on src, test, docs | Requires approval for every file |
| Build commands | Automatic (npm, mvn, gradle) | Denied - read only |
| Git commands | Read + commit/checkout | Read only (status, diff, log) |
| Network access | curl allowed, no ssh/scp | Completely denied |
| Sensitive files | Blocked (.env, .pem, .key) | Blocked (all files for writing) |
| Ideal use | Everyday development | Audit, compliance, production |
6. Headless Mode
Headless mode allows running Claude Code in a non-interactive way, ideal for integration into CI/CD pipelines, automation scripts, and batch processes. In this mode, Claude receives a prompt, executes it, and returns the result in structured JSON format.
Basic Syntax
# Basic syntax
claude --print "Analyze the code in src/ and report issues" --output-format json
# With iteration limit
claude --print "Run tests and fix failures" \
--output-format json \
--max-iterations 10
# With specific model
claude --print "Generate API documentation" \
--output-format json \
--model claude-sonnet-4-20250514
# With explicit permissions
claude --print "Format all TypeScript files" \
--output-format json \
--allowedTools "Bash(npx prettier --write src/**/*.ts)" \
--allowedTools "Read(*)"
Main Headless Mode Flags
Headless Mode Flags
| Flag | Description | Default Value |
|---|---|---|
--print |
The prompt to execute in non-interactive mode | Required |
--output-format |
Output format (json, text, stream-json) |
text |
--max-iterations |
Maximum number of iterations (tool use cycles) | Unlimited |
--model |
AI model to use | From configuration |
--allowedTools |
Tools allowed for execution (repeatable) | From configuration |
--verbose |
Detailed output with debug logs | false |
GitHub Actions Integration
A powerful use case for headless mode is integration with CI/CD pipelines. Here is a complete example of a GitHub Actions workflow that uses Claude Code for automatic code review on every Pull Request.
name: Claude Code Review
on:
pull_request:
types: [opened, synchronize]
jobs:
review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install Claude Code
run: npm install -g @anthropic-ai/claude-code
- name: Run Code Review
env:
ANTHROPIC_API_KEY: 






