Master Claude Code: The Ultimate CLI AI Guide for Seamless Development
This comprehensive guide walks you through everything you need to know about Claude Code—from installation on macOS, Linux, and Windows via WSL, to core commands, configuration, MCP integration, security settings, advanced features, and CI/CD automation—ensuring you can harness the full power of this AI-powered CLI tool.
Claude Code Overview
Claude Code is not a traditional AI IDE but a command‑line AI assistant that can help you debug, generate code, and interact with external services. It offers native Claude 4 Sonnet/Opus models, unlimited tool calls, large context windows (200K+ tokens), and direct system‑log access for precise debugging.
1. Installation Methods
1.1 Mirror Site Installation
Invitation link : https://aicodewith.com/?invitation=EK1S5F macOS :
curl -fsSL https://aicodewith.com/claudecode/resources/install-script-macos | bashLinux :
curl -fsSL https://aicodewith.com/claudecode/resources/install-script-linux | bashWindows (WSL) : Install WSL2 ( wsl --install), install Ubuntu from Microsoft Store, then run
curl -fsSL https://aicodewith.com/claudecode/resources/install-script-wsl | bash1.2 Official Installation
NPM global install : npm install -g @anthropic-ai/claude-code Verify version :
claude --version2. Basic Usage
2.1 First‑time Configuration
API key (required for official install): export ANTHROPIC_API_KEY="sk-your-key-here" (add to ~/.bashrc, ~/.zshrc, or ~/.config/fish/config.fish as appropriate)
Basic settings : claude config set -g model claude-sonnet-4, claude config set -g verbose true, claude config set -g outputFormat text Test installation : claude "Hello, Claude!" or
claude /doctor2.2 Core Commands
Start session : claude Fix bug : claude "帮我修复这个 bug" One‑off print : claude -p "" Read large file : cat file | claude -p "" Update : claude update Start MCP :
claude mcpSlash Commands (quick actions)
/help: list all commands /add-dir: add more working directories /bug: report an error /clear: clear chat history /compact: compress context /config: open configuration menu /cost: show token usage /doctor: run integrity check /init: initialize project and generate
CLAUDE.md /mcp: list MCP services and status /memory: edit memory /model: switch model /permissions: modify tool permissions /review: request code review /sessions: list sessions /status: show system/account status /terminal-setup: bind Shift+Enter /vim: toggle vim mode
3. MCP Integration (External Services & Databases)
MCP enables Claude to connect to external services, databases, and APIs directly from the CLI.
3.1 Basic MCP Commands
claude mcp list: list configured services claude mcp add: add a new service claude mcp remove: remove a service
Configuration file:
~/.claude.json3.2 Common MCP Services
Git MCP : npm install -g git-mcp-server then claude mcp add git "git-mcp-server" or
claude mcp add github "github-mcp-server --token $GITHUB_TOKEN"Database MCP : install server packages ( npm install -g postgres-mcp-server, npm install -g mysql-mcp-server, npm install -g sqlite-mcp-server) and configure with environment variables, e.g.,
export POSTGRES_URL="postgresql://user:password@localhost:5432/mydb"then
claude mcp add postgres "postgres-mcp-server --url $POSTGRES_URL"3.3 MCP Tool Permissions
Specify allowed tools: claude --allowedTools "Edit,View" Keyword‑based permissions: claude --allowedTools "Bash(git:status)" Combine built‑in and MCP tools:
claude --allowedTools "Edit,View,Bash(git:*)"4. Configuration System
4.1 Configuration Files
Global settings live in ~/.claude.json. Project‑specific settings can be placed in settings.json (or a similar file) in the project root.
{
"model": "claude-sonnet-4",
"verbose": true,
"outputFormat": "text",
"allowedTools": ["Edit", "View"]
}4.2 Environment Variables
DISABLE_NON_ESSENTIAL_MODEL_CALLS=1: skip automatic summarisation and git diff to save tokens MAX_THINKING_TOKENS: limit maximum thinking token usage (≈30‑40k) DISABLE_TELEMETRY=1: disable telemetry and error reporting CLAUDE_CODE_USE_BEDROCK / CLAUDE_CODE_USE_VERTEX: enable AWS Bedrock or Google Vertex AI verification HTTP_PROXY, HTTPS_PROXY, NO_PROXY: configure HTTP/HTTPS proxy settings
5. Security and Permission Management
Tools must be authorised before use, permissions are remembered per session, and risky actions require confirmation.
Level
Description
Risk
Interactive
Ask before each operation
Low
Allowlist
Only specified tools are usable
Medium
Dangerous
All tools are unrestricted
High
5.1 Recommended Strategies
Limit specific tool permissions, e.g., claude --allowedTools "Edit,View,Bash(git:status)" instead of granting all Bash access.
Protect sensitive data by using environment variables rather than hard‑coding credentials.
Regularly audit permission groups with claude config get allowedTools, claude config get disallowedTools, and claude config list.
6. Thinking Mode
Control Claude’s depth of reasoning with keywords in the prompt.
Depth 1: think Depth 2:
think about it, think a lot, think deeply, think hard, think more, megathinkDepth 3: think harder Example:
claude -p "We have a tricky concurrency bug. ultrathink and propose a fix."7. Config Command Reference
Command
Function
Example
claude config list
Show all settings
claude config list
claude config get
Retrieve a specific setting
claude config get theme
claude config set -g
Set a global value
claude config set -g theme dark
claude config add -g
Add an element to an array
claude config add -g env CLAUDE_CODE_ENABLE_TELEMETRY=1
claude config remove -g
Remove an element from an array
claude config remove -g env CLAUDE_CODE_ENABLE_TELEMETRY
8. CI/CD Integration (GitHub Actions)
name: Claude Code Review
on:
pull_request:
branches: [main, develop]
jobs:
claude-review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js 18
uses: actions/setup-node@v4
with:
node-version: '18'
- name: Install Claude Code
run: npm install -g @anthropic-ai/claude-code
- name: Review PR
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
run: |
claude -p "Review changes for security issues and bugs" \
--allowedTools "View" \
--output-format json > review-results.json
- name: Upload results artifact
uses: actions/upload-artifact@v4
with:
name: claude-review
path: review-results.jsonKey points: checkout PR diff, install official CLI, use read‑only View permission, output JSON for structured analysis.
8.1 Local Git Pre‑Commit Hook
#!/usr/bin/env bash
# .git/hooks/pre-commit (chmod +x)
staged=$(git diff --cached --name-only --diff-filter=ACM)
[ -z "$staged" ] && exit 0
payload=$(echo "$staged" | xargs cat)
analysis=$(echo "$payload" | \
claude -p "Review these changes for issues before commit" \
--allowedTools "View" \
--output-format json)
if echo "$analysis" | jq -e '.critical_issues[]' >/dev/null 2>&1; then
echo "❌ Critical issues found – commit blocked"
exit 1
fi
echo "✅ Claude analysis passed"9. Advanced Features
9.1 Persistent Memory
Run claude /init to generate a CLAUDE.md file that stores project context for future sessions.
Project: My Application
Overview
This is a React/Node.js application with PostgreSQL database.
Architecture
Frontend: React 18 with TypeScript
Backend: Node.js with Express
Database: PostgreSQL 14
Current Goals
- Implement authentication
- Add API documentation
- Set up CI/CD pipeline
Development Guidelines
- Use TypeScript for new code
- Follow ESLint configuration
- Write tests for new features9.2 Memory Commands
claude /memory: edit memory claude /memory view: view current memory
9.3 Multi‑Directory Workspaces
Add directories: claude --add-dir ../frontend ../backend ../shared Run a global analysis:
claude "analyze the entire application architecture"Conclusion
This guide provides a step‑by‑step, exhaustive reference for installing, configuring, and extending Claude Code. By following the instructions you can integrate the tool into local development, CI/CD pipelines, and team workflows while maintaining security and control.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
