Engineering Notes

Engineering Notes

Thoughts and Ideas on AI by Muthukrishnan

Claude Code CLI Best Practices Checklist

02 Feb 2026

A comprehensive guide to tips, tricks, and best practices for maximizing productivity with Claude Code.


Table of Contents

  1. Initial Setup & Configuration
  2. CLAUDE.md Configuration
  3. Permissions & Security
  4. Context Management
  5. Custom Commands & Slash Commands
  6. Hooks for Automation
  7. Parallel Development with Git Worktrees
  8. CLI Usage Patterns
  9. MCP Server Integration
  10. Session Management
  11. Keyboard Shortcuts & Navigation
  12. Advanced Tips & Tricks
  13. Common Pitfalls to Avoid

1. Initial Setup & Configuration

Getting Started

Settings Hierarchy

Claude Code uses hierarchical settings stored in JSON files:

Example settings.json

{
  "model": "claude-sonnet-4-20250514",
  "maxTokens": 4096,
  "permissions": {
    "allowedTools": ["Read", "Write", "Bash(git *)"],
    "deny": [
      "Read(./.env)",
      "Read(./.env.*)",
      "Write(./production.config.*)"
    ]
  }
}

2. CLAUDE.md Configuration

Purpose

CLAUDE.md is your project’s persistent memory—loaded automatically at the start of every session.

Best Practices

What to Include

What NOT to Include

File Locations

LocationScope
~/.claude/CLAUDE.mdGlobal (all projects)
./CLAUDE.mdProject root (shared with team)
./subdirectory/CLAUDE.mdSubdirectory-specific

Example CLAUDE.md

# Project Context
FastAPI REST API for user authentication. Uses SQLAlchemy + Pydantic.

## Key Directories
- `app/models/` - database models
- `app/api/` - route handlers
- `app/core/` - configuration and utilities

## Common Commands
```bash
uvicorn app.main:app --reload  # dev server
pytest tests/                   # run tests

Gotchas


---

## 3. Permissions & Security

### Managing Permissions
- [ ] Use `/permissions` command to configure allowlist
- [ ] Select "Always allow" when prompted for trusted actions
- [ ] Consider `--dangerously-skip-permissions` for trusted workflows (use with caution)
- [ ] Use `/sandbox` for OS-level isolation

### Permission Configuration
```json
{
  "permissions": {
    "allow": [
      "Read",
      "Grep",
      "LS",
      "Bash(npm run test:*)",
      "Bash(git commit:*)",
      "Edit"
    ],
    "deny": [
      "WebFetch",
      "Bash(curl:*)",
      "Read(./.env)",
      "Read(./secrets/**)"
    ]
  }
}

Security Best Practices


4. Context Management

Monitor Context Usage

Context Optimization Tips

Custom Status Line (Advanced)

You can customize the status line to show:


5. Custom Commands & Slash Commands

Creating Project Commands

Store prompt templates in .claude/commands/ directory:

mkdir -p .claude/commands

Example: Fix GitHub Issue Command

Create .claude/commands/fix-issue.md:

Please analyze and fix the GitHub issue: $ARGUMENTS.

Follow these steps:
1. Use `gh issue view` to get the issue details
2. Understand the problem described in the issue
3. Search the codebase for relevant files
4. Implement the necessary changes to fix the issue
5. Write and run tests to verify the fix
6. Ensure code passes linting and type checking
7. Create a descriptive commit message
8. Push and create a PR

Remember to use the GitHub CLI (`gh`) for all GitHub-related tasks.

Usage: /project:fix-issue 1234

Personal Commands

Store in ~/.claude/commands/ for commands available across all projects.

Command Features

---
allowed-tools: Bash(git add:*), Bash(git status:*), Bash(git commit:*)
description: Create a git commit with context
---

6. Hooks for Automation

Hook Events

EventWhen It Fires
PreToolUseBefore Claude executes an action
PostToolUseAfter Claude completes an action
UserPromptSubmitWhen you submit a prompt
SessionStartWhen Claude starts
SessionEndWhen session terminates
StopWhen Claude finishes responding
NotificationWhen Claude sends an alert
PermissionRequestWhen Claude requests permission (v2.0.45+)

Example: Auto-Format on File Edit

{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Edit|Write",
        "hooks": [
          {
            "type": "command",
            "command": "jq -r '.tool_input.file_path' | xargs npx prettier --write"
          }
        ]
      }
    ]
  }
}

Example: Block Sensitive Files

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Edit|Write",
        "hooks": [
          {
            "type": "command",
            "command": "python3 -c \"import json, sys; d=json.load(sys.stdin); p=d.get('tool_input',{}).get('file_path',''); sys.exit(2 if any(x in p for x in ['.env','package-lock.json','.git/']) else 0)\""
          }
        ]
      }
    ]
  }
}

Example: Desktop Notifications

{
  "hooks": {
    "Notification": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "notify-send 'Claude Code' 'Awaiting your input'"
          }
        ]
      }
    ]
  }
}

Hook Exit Codes

CodeMeaning
0Success, continue
1Non-blocking error
2Block action (PreToolUse/PermissionRequest)
3Deferred execution

7. Parallel Development with Git Worktrees

Why Worktrees?

Setup Worktrees

# Create worktree for a feature
git worktree add ../my-project-feature-auth feature/auth

# Create worktree from main
git worktree add ../my-project-refactor -b refactor/cleanup

# List worktrees
git worktree list

# Remove worktree
git worktree remove ../my-project-feature-auth

Parallel Workflow

  1. Create worktrees for each task/feature
  2. Open each worktree in separate terminal/IDE window
  3. Run /init in each worktree session
  4. Assign distinct tasks to each Claude instance
  5. Cycle through to check progress and approve permissions
  6. Cherry-pick completed work into main branch

Tools for Worktree Management

Best Practices


8. CLI Usage Patterns

Basic Usage

# Start interactive session
claude

# Start with initial prompt
claude "How does turnManager.js work?"

# Headless mode (non-interactive)
claude -p "How many files are in this project?"

# Resume previous session
claude --resume

Piping & Chaining

# Pipe input to Claude
cat data.csv | claude -p "Who won the most games?"

# Chain with other CLIs
git diff | claude -p "Explain these changes"

# Output to file
claude -p "Generate API docs" > api-docs.md

Useful Flags

FlagPurpose
-pPrint mode (headless, non-interactive)
--resumeResume previous session
--from-pr 123Resume session linked to PR
--verboseDebug mode (shows detailed output)
--mcp-debugDebug MCP connections
--allowedToolsSpecify allowed tools for this run
--output-format jsonJSON output for scripting
--dangerously-skip-permissionsSkip all permission prompts

Shell Integration

# Run shell commands in Claude session with ! prefix
! git status

# Bypass conversational mode for direct execution
!npm run test

9. MCP Server Integration

Adding MCP Servers

# Add MCP server globally
claude mcp add -s user playwright npx @playwright/mcp@latest

# Add to project
claude mcp add puppeteer npx @anthropic/mcp-puppeteer

Configuration in .mcp.json

Check into git for team-wide access:

{
  "servers": {
    "puppeteer": {
      "command": "npx",
      "args": ["@anthropic/mcp-puppeteer"]
    },
    "sentry": {
      "command": "npx",
      "args": ["@sentry/mcp-server"]
    }
  }
}

Document MCP Usage in CLAUDE.md

### Slack MCP
- Posts to #dev-notifications channel only
- Use for deployment notifications and build failures
- Do not use for individual PR updates

10. Session Management

Session Commands

CommandAction
/resumeOpen session picker
/clearClear current context
/compactManually compact context
/helpShow all commands

Session Picker Features

Best Practices


11. Keyboard Shortcuts & Navigation

Essential Shortcuts

ShortcutAction
EscapeStop Claude (not Ctrl+C!)
Escape (twice)Show previous messages
Up/DownNavigate command history
Ctrl+RReverse search history
Ctrl+VPaste images (not Cmd+V)
Shift+DragReference files properly

Terminal Setup


12. Advanced Tips & Tricks

Prompting Techniques

Using External Tools

Voice Input

Container Isolation

Run Claude Code in containers for:

Debugging

Token Efficiency


13. Common Pitfalls to Avoid

❌ Don’t Do This

✅ Do This Instead


Quick Reference Card

Daily Workflow

# Start session
claude

# Initialize project memory
/init

# Clear context for new task
/clear

# Resume previous session
/resume

# Check permissions
/permissions

Key Files

~/.claude/
├── settings.json          # Global settings
├── CLAUDE.md              # Global memory
└── commands/              # Personal commands

.claude/
├── settings.json          # Project settings (committed)
├── settings.local.json    # Local settings (git-ignored)
└── commands/              # Project commands

./CLAUDE.md                # Project memory (committed)
.mcp.json                  # MCP server config (committed)

Emergency Commands

# Skip all permissions (trusted environments only)
claude --dangerously-skip-permissions

# Update Claude Code
claude update

# Check version
claude --version

Last updated: February 2026 Based on community best practices and official Anthropic documentation