Subscribe To Our Newsletter
You will receive our latest post and tutorial.
Thank you for subscribing!

required
required


Advanced Tips & Tricks for Claude Code

Advanced Tips & Tricks for Claude Code

After mastering the basics, here are advanced techniques that will make you significantly more productive with Claude Code.

1. Piping Input to Claude Code

Pipe command output directly to Claude Code for analysis:

# Analyze test failures
pytest tests/ 2>&1 | claude "Analyze these test failures and suggest fixes"

# Review a diff
git diff main | claude "Review this diff for potential issues"

# Analyze logs
tail -100 /var/log/app.log | claude "What errors are in these logs?"

2. Headless Mode for Automation

Use the -p flag for non-interactive mode, perfect for CI/CD and scripts:

# Generate a code review
claude -p "Review the code in src/ for security vulnerabilities" > review.md

# Generate documentation
claude -p "Generate API documentation for all endpoints in routes/" > api-docs.md

# Use in a shell script
#!/bin/bash
RESULT=$(claude -p "Is there a TODO in main.py? Reply yes or no")
if [ "$RESULT" = "yes" ]; then
  echo "Found TODOs!"
fi

3. Resuming Conversations

Continue where you left off:

# Resume the most recent conversation
claude --resume

# Continue a specific session
claude --resume session-id

4. Multi-File Editing Patterns

Claude Code excels at coordinated changes across files:

> Add a "lastLogin" field to the User model, update the migration, 
update the API serializer, and add it to the admin dashboard view

Claude Code will edit all four files in a single coordinated operation.

5. Using Claude Code with Docker

# Let Claude manage Docker containers
> Build and run the Docker container, then check if the app is healthy

# Debug container issues
> The Docker container keeps crashing on startup. Check the logs and fix the issue

6. Efficient Context Management

Help Claude Code work efficiently with large codebases:

  • Use /compact — When conversations get long, compact the context to free up space
  • Be specific about files — “Edit src/auth/login.py” is better than “Edit the login code”
  • Create a good CLAUDE.md — This reduces the need for Claude to search for basic project info

7. Permission Auto-Approval

Speed up workflows by pre-approving safe commands:

# In .claude/settings.json
{
  "permissions": {
    "allow": [
      "Bash(npm test)",
      "Bash(npm run build)",
      "Bash(git status)",
      "Bash(git diff *)",
      "Read",
      "Glob",
      "Grep"
    ]
  }
}

8. Claude Code in CI/CD

Integrate Claude Code into your development pipeline:

# GitHub Actions example
name: Code Review
on: pull_request
jobs:
  review:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm install -g @anthropic-ai/claude-code
      - run: |
          claude -p "Review the changes in this PR for bugs, \
          security issues, and code quality" > review.md
        env:
          ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}

9. Custom Slash Commands

Create reusable prompts as custom slash commands in your project’s .claude/commands/ directory:

# .claude/commands/review-component.md
Review the React component at $ARGUMENTS for:
1. Accessibility issues
2. Performance problems
3. Missing error handling
4. Proper TypeScript types

Then use it:

> /project:review-component src/components/UserProfile.tsx

10. Keyboard Shortcuts

Shortcut Action
Ctrl+C Cancel current operation
Ctrl+D Exit Claude Code
Up Arrow Cycle through previous prompts
Escape Cancel current input

Conclusion

You’ve now completed the full Claude Code tutorial series! From installation to advanced automation, you have all the tools you need to be highly productive with Claude Code. Happy coding!

Full Tutorial Series

  1. Introduction to Claude Code – Installation & Setup
  2. Your First Conversation with Claude Code
  3. Code Generation with Claude Code
  4. Debugging with Claude Code
  5. Refactoring Code with Claude Code
  6. Working with Git using Claude Code
  7. Writing Tests with Claude Code
  8. Project Configuration – CLAUDE.md & Memory
  9. Using MCP Servers with Claude Code
  10. Advanced Tips & Tricks for Claude Code

Previous: Using MCP Servers with Claude Code

February 25, 2026

Using MCP Servers with Claude Code

Using MCP Servers with Claude Code

MCP (Model Context Protocol) is an open standard that lets Claude Code connect to external tools and data sources. MCP servers give Claude Code new abilities like fetching web content, querying databases, or interacting with third-party APIs.

What is MCP?

MCP follows a client-server architecture:

  • MCP Client — Claude Code itself, which connects to servers
  • MCP Server — A lightweight program that exposes tools via the MCP protocol

When you add an MCP server, its tools become available to Claude Code just like built-in tools.

Adding an MCP Server

Use the claude mcp add command:

# Add a filesystem MCP server
claude mcp add filesystem -- npx -y @anthropic-ai/mcp-filesystem /path/to/dir

# Add a PostgreSQL MCP server
claude mcp add postgres -- npx -y @anthropic-ai/mcp-postgres "postgresql://localhost/mydb"

# Add a web fetch MCP server
claude mcp add fetch -- npx -y @anthropic-ai/mcp-fetch

Managing MCP Servers

# List all configured MCP servers
claude mcp list

# Remove an MCP server
claude mcp remove postgres

# Get details about a server
claude mcp get filesystem

MCP Server Scopes

MCP servers can be configured at different scopes:

# Project-level (stored in .claude/settings.json)
claude mcp add --scope project my-server -- command args

# User-level (stored in ~/.claude/settings.json)
claude mcp add --scope user my-server -- command args

Popular MCP Servers

Server Purpose Example Use
mcp-filesystem Access files outside project Read config files from other directories
mcp-postgres Query PostgreSQL Check database schema and data
mcp-fetch Fetch web URLs Read API docs, check endpoints
mcp-github GitHub integration Manage issues, PRs, repos
mcp-slack Slack integration Send messages, read channels

Using MCP Tools in Conversation

Once configured, MCP tools appear automatically. For example, with the postgres server:

> Show me all tables in the database

# Claude uses the MCP postgres tool to query information_schema

> What columns does the users table have?

# Claude queries the table structure directly

Creating Custom MCP Servers

You can create your own MCP servers for custom integrations. The MCP SDK is available in TypeScript and Python:

npm install @modelcontextprotocol/sdk

A minimal MCP server exposes tools that Claude Code can call:

import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";

const server = new McpServer({ name: "my-server", version: "1.0.0" });

server.tool("hello", "Say hello", { name: { type: "string" } },
  async ({ name }) => ({
    content: [{ type: "text", text: `Hello, ${name}!` }]
  })
);

const transport = new StdioServerTransport();
await server.connect(transport);

Summary

MCP servers extend Claude Code’s capabilities by connecting it to external tools and data sources. From databases to APIs to custom integrations, MCP makes Claude Code infinitely extensible. Next, we’ll cover advanced tips and tricks to maximize your productivity.

Previous: Project Configuration – CLAUDE.md & Memory

Next: Advanced Tips & Tricks for Claude Code

February 25, 2026

Project Configuration – CLAUDE.md & Memory

Project Configuration – CLAUDE.md & Memory

Claude Code can be customized per-project using a CLAUDE.md file and has a memory system that persists information across sessions. These features make Claude Code smarter about your specific project over time.

What is CLAUDE.md?

CLAUDE.md is a markdown file you place in your project root. Claude Code reads it at the start of every session, using it as persistent instructions for how to work with your project.

Creating CLAUDE.md

Use the init command to create one interactively:

claude /init

Or create it manually. Here’s an example:

# CLAUDE.md

## Project Overview
E-commerce API built with FastAPI and PostgreSQL.

## Tech Stack
- Python 3.11, FastAPI, SQLAlchemy 2.0
- PostgreSQL 15, Redis for caching
- pytest for testing

## Commands
- Run tests: `pytest tests/`
- Start dev server: `uvicorn app.main:app --reload`
- Run migrations: `alembic upgrade head`

## Conventions
- Use snake_case for Python, camelCase for JavaScript
- All API endpoints must have input validation
- Write tests for all new features

## Architecture
- app/models/ - SQLAlchemy models
- app/routes/ - API route handlers
- app/services/ - Business logic
- app/schemas/ - Pydantic schemas

What to Include in CLAUDE.md

  • Project overview — What the project does, its tech stack
  • Common commands — How to build, test, run, and deploy
  • Coding conventions — Style guides, naming patterns, preferences
  • Architecture — Directory structure and key file locations
  • Rules — Things Claude should always or never do

CLAUDE.md Hierarchy

Claude Code supports multiple CLAUDE.md files at different levels:

~/.claude/CLAUDE.md          # Global (all projects)
project-root/CLAUDE.md       # Project-level
project-root/src/CLAUDE.md   # Directory-level (scoped)

Directory-level files are loaded when Claude reads files in that directory, giving you scoped instructions.

Claude Code Memory

Claude Code has a persistent memory system that stores information across sessions. It automatically saves useful patterns it discovers about your project.

Memory is stored in ~/.claude/projects/<project-hash>/memory/.

Managing Memory

# Ask Claude to remember something
> Remember that we always use UTC timestamps in this project

# Ask Claude to forget something
> Forget the convention about UTC timestamps

# Memory is automatically updated as Claude learns about your project

Settings Files

Claude Code also supports .claude/settings.json for configuration:

{
  "permissions": {
    "allow": [
      "Bash(npm test)",
      "Bash(npm run lint)",
      "Read",
      "Write"
    ]
  }
}

This auto-approves specific tools and commands so you’re not prompted every time.

Summary

CLAUDE.md and memory make Claude Code smarter about your project over time. The more context you provide, the better Claude Code performs. Next, we’ll explore MCP servers and how they extend Claude Code’s capabilities.

Previous: Writing Tests with Claude Code

Next: Using MCP Servers with Claude Code

February 25, 2026

Writing Tests with Claude Code

Writing Tests with Claude Code

Writing tests is essential but often tedious. Claude Code can generate comprehensive test suites that cover your code’s behavior, edge cases, and error scenarios.

Generating Unit Tests

Point Claude Code at a function and ask for tests:

> Write unit tests for the validate_email function in src/utils/validators.py

Claude Code will generate tests covering:

  • Valid email addresses
  • Invalid formats (missing @, no domain, etc.)
  • Edge cases (empty string, very long emails, special characters)
  • Boundary conditions

Example generated test:

import pytest
from src.utils.validators import validate_email


class TestValidateEmail:
    def test_valid_email(self):
        assert validate_email("user@example.com") is True

    def test_valid_email_with_subdomain(self):
        assert validate_email("user@mail.example.com") is True

    def test_invalid_email_no_at(self):
        assert validate_email("userexample.com") is False

    def test_invalid_email_no_domain(self):
        assert validate_email("user@") is False

    def test_empty_string(self):
        assert validate_email("") is False

Generating Integration Tests

> Write integration tests for the /api/users endpoint. Test creating, reading, updating, and deleting users.

Testing Existing Code

Ask Claude to analyze code and determine what needs testing:

> Look at the OrderService class and write tests for any untested business logic

Test-Driven Development (TDD)

Claude Code supports TDD workflows:

# Step 1: Write the test first
> Write a failing test for a function that calculates shipping cost based on weight and destination

# Step 2: Implement the code
> Now implement the calculate_shipping function to make the tests pass

# Step 3: Run and verify
> Run the tests to confirm they pass

Running Tests

Ask Claude to run your test suite:

# Run all tests
> Run the full test suite

# Run specific tests
> Run only the authentication tests

# Run with coverage
> Run tests with coverage report

Fixing Failing Tests

When tests fail, Claude Code can diagnose and fix them:

> The test_create_user test is failing. Can you figure out why and fix it?

Best Practices

  1. Specify your testing framework — “Use pytest” or “Use Jest” helps Claude generate the right code
  2. Ask for edge cases — “Include edge cases and error scenarios”
  3. Request mocking when needed — “Mock the database calls in the tests”
  4. Match existing test patterns — “Follow the testing style used in test_auth.py”

Summary

Claude Code can write unit tests, integration tests, and support TDD workflows. It generates comprehensive test coverage and helps fix failing tests. Next, we’ll learn about configuring Claude Code with CLAUDE.md and memory.

Previous: Working with Git using Claude Code

Next: Project Configuration – CLAUDE.md & Memory

February 25, 2026

Working with Git using Claude Code

Working with Git using Claude Code

Claude Code integrates deeply with Git, making version control effortless. It can create commits, manage branches, review diffs, resolve merge conflicts, and even create pull requests.

Smart Commits

Let Claude Code analyze your changes and write a commit message:

> Commit my current changes with a descriptive message

Claude Code will:

  1. Run git status and git diff
  2. Analyze all staged and unstaged changes
  3. Write a clear, conventional commit message
  4. Stage the appropriate files and create the commit

Branch Management

# Create a feature branch
> Create a new branch called feature/user-authentication

# Switch branches
> Switch to the main branch

# View branch info
> Show me all branches and which one I'm on

Reviewing Changes

Ask Claude Code to explain what changed:

# Review your uncommitted changes
> What changes have I made since the last commit?

# Review changes between branches
> What's different between my branch and main?

# Review a specific commit
> Explain what commit abc1234 changed and why

Resolving Merge Conflicts

Claude Code can handle merge conflicts for you:

> I have merge conflicts after rebasing on main. Can you resolve them?

Claude Code will read each conflicting file, understand both sides of the conflict, and make an intelligent resolution based on the intent of both changes.

Creating Pull Requests

Let Claude Code create a PR with a proper description:

> Create a pull request for my current branch against main

Claude Code will:

  • Push your branch to the remote
  • Analyze all commits since branching from main
  • Write a descriptive PR title and body
  • Create the PR using the GitHub CLI

PR Review

You can also ask Claude Code to review an existing PR:

# Review a specific PR
> /review 42

# Or provide the URL
> Review this PR: https://github.com/user/repo/pull/42

Undoing Mistakes

# Undo the last commit (keeping changes)
> Undo my last commit but keep the file changes

# Discard changes to a file
> Revert all changes to src/config.js

# Stash work in progress
> Stash my current changes so I can switch branches

Summary

Claude Code makes Git workflows smooth — from smart commits to merge conflict resolution to PR creation. Next, we’ll explore how to use Claude Code for writing tests.

Previous: Refactoring Code with Claude Code

Next: Writing Tests with Claude Code

February 25, 2026