Tips & Tricks Advanced

Level up your Claude Code usage with these power-user techniques. Learn how to write effective prompts, handle large repositories, optimize costs, integrate with your IDE, and avoid common mistakes.

1. Writing Effective Prompts for Code

The quality of Claude Code's output depends heavily on the quality of your prompts. Here are proven strategies for getting better results:

Be Specific About What You Want

Instead of This Say This
"Fix the bug" "Fix the bug where the login form rejects emails containing plus signs in src/components/LoginForm.tsx"
"Make it faster" "Optimize the getUserPosts query in src/api/posts.ts by adding pagination and an index on the userId column"
"Add tests" "Write Jest unit tests for all public methods in src/services/UserService.ts, including edge cases for null inputs and empty arrays"
"Refactor this" "Extract the validation logic from the handleSubmit function in CheckoutForm.tsx into a separate validateCheckout utility function"

Provide Context and Constraints

Claude Code Session
# Good: provides context and constraints
Claude > Create a rate limiter middleware for our Express API.
         Requirements:
         - Use Redis for distributed rate limiting (we use ioredis)
         - Allow 100 requests per minute per IP
         - Return 429 status with a Retry-After header
         - Match the existing middleware patterns in src/middleware/
         - Include TypeScript types

# Good: references existing patterns
Claude > Add a new API endpoint for managing blog tags. Follow the
         exact same patterns used in src/routes/categories.ts for
         the route structure, validation, and error handling.

Use Iterative Refinement

Don't try to get everything perfect in one prompt. Start with the core functionality and refine:

Claude Code Session
# Step 1: Core implementation
Claude > Create a basic search feature for the blog posts page

# Step 2: Refine
Claude > Add debouncing to the search input (300ms delay)

# Step 3: Polish
Claude > Add a loading spinner while search results are being fetched

# Step 4: Edge cases
Claude > Handle the empty state when no results are found

2. Using Context Effectively

The /compact Command

Long conversations consume more tokens (and cost more). Use /compact periodically to summarize the conversation while retaining key context.

Claude Code Session
# After a long conversation about refactoring...
Claude > /compact

# Claude summarizes the conversation so far and frees up context
# You can continue working with less token usage

Session Management

Terminal
# Continue your last conversation
$ claude -c

# Resume a specific conversation by ID
$ claude --resume abc123def

# Start fresh (new conversation)
$ claude
When to Start Fresh: Start a new session when switching to a completely different task. Carrying irrelevant context from a previous task can confuse Claude and increase costs.

3. Batch Operations

Use Claude Code's non-interactive mode (-p flag) for scripting and batch operations:

Bash Script
#!/bin/bash
# Add JSDoc comments to all TypeScript files in a directory

for file in src/utils/*.ts; do
  echo "Processing $file..."
  claude -p "Add JSDoc comments to all exported functions in $file. \
    Keep the code unchanged, only add documentation comments."
done
Terminal
# Pipe data into Claude Code for analysis
$ cat error.log | claude -p "Analyze these errors and summarize the top 5 most common issues"

# Use with git for automated commit messages
$ git diff --staged | claude -p "Generate a conventional commit message for these changes"

# Generate documentation from code
$ claude -p "Read all the route files in src/routes/ and generate an API reference in Markdown format"

4. Working with Large Repositories

Large codebases require some extra strategies to work effectively with Claude Code:

Guide Claude to the Right Files

Claude Code Session
# Instead of letting Claude search the whole repo...
Claude > The authentication code is in src/auth/. Look at
         src/auth/middleware.ts and src/auth/strategies/ to
         understand how login works.

# Point Claude to the relevant area
Claude > The bug is in the payment processing module.
         Start by reading src/payments/processor.ts and
         src/payments/stripe-client.ts

Use CLAUDE.md for Architecture Context

For large repos, a well-written CLAUDE.md saves Claude from having to discover the architecture on its own:

Markdown (CLAUDE.md)
# Project Architecture

## Directory Structure
- src/api/ - REST API routes and controllers
- src/services/ - Business logic layer
- src/models/ - Database models (Prisma)
- src/lib/ - Shared utilities and helpers
- src/workers/ - Background job processors
- src/events/ - Event handlers (pub/sub)

## Key Patterns
- All API routes go through src/api/router.ts
- Services never import from api/ (clean architecture)
- Database access is only through services, never directly in routes

Use /compact Aggressively

In large repos, Claude reads more files and the context fills up faster. Use /compact after completing each sub-task.

5. Keyboard Shortcuts

Shortcut Action When to Use
Ctrl+C Interrupt Claude's current action When Claude is doing something you want to stop
Ctrl+D Exit the Claude Code session When you're done working
Up Arrow Recall previous message When you want to repeat or modify a previous request
Escape Cancel current input When you want to clear what you're typing
Tab Autocomplete file paths When referencing files in your messages

6. Integration with IDEs

VS Code Extension

Claude Code has an official VS Code extension that embeds the CLI experience directly in your editor sidebar.

  1. Install the extension

    Search for "Claude Code" in the VS Code Extensions marketplace, or run:

    Terminal
    $ code --install-extension anthropic.claude-code
  2. Open the Claude Code panel

    Use the sidebar icon or press Ctrl+Shift+P and search for "Claude Code."

  3. Use it like the CLI

    The VS Code extension provides the same capabilities as the CLI, with the added benefit of seeing edits applied in your editor in real time.

Terminal Multiplexing (tmux/screen)

For terminal-only workflows, run Claude Code in one tmux pane while keeping your editor in another:

Terminal
# Create a tmux session with two panes
$ tmux new-session -s dev
# Pane 1: Your editor (vim, neovim, etc.)
# Pane 2: Claude Code

# Split vertically
# Ctrl+B, % (vertical split)
# Navigate with Ctrl+B, arrow keys

7. Cost Optimization

Claude Code uses the Anthropic API, which charges per token. Here are strategies to keep costs manageable:

Strategy Impact How
Use Sonnet for routine tasks High Reserve Opus for complex reasoning. Sonnet handles most coding tasks well at lower cost.
Use /compact regularly High Summarizes long conversations, reducing tokens sent in subsequent messages.
Start fresh for new tasks Medium Don't carry irrelevant context. Use /clear or start a new session.
Be specific in prompts Medium Specific prompts require fewer iterations, reducing total token usage.
Point to specific files Medium Tell Claude which files to look at instead of letting it search broadly.
Use -p for quick questions Low Non-interactive mode (claude -p) exits after one response, avoiding lingering sessions.
Monitor with /cost Awareness Check token usage and costs during your session.
Claude Code Session
# Check your session costs
Claude > /cost

Session Statistics:
  Messages: 24
  Input tokens: 45,230
  Output tokens: 12,450
  Estimated cost: $0.42

8. Common Pitfalls

Pitfall 1: Not Using Version Control

Always work in a git repository. Without version control, you have no safety net if Claude makes unwanted changes. Commit your work before starting a Claude Code session for large changes.

Pitfall 2: Accepting Changes Without Review

Even when using auto-accept mode, periodically review what Claude has done with git diff. AI-generated code can have subtle bugs that look correct at first glance.

Pitfall 3: Vague Prompts for Complex Tasks

"Make the app better" will not give good results. Be specific about what "better" means: faster load times, better error handling, more test coverage, etc.

Pitfall 4: Ignoring Context Limits

If your conversation gets very long, Claude may start losing track of earlier details. Use /compact or start a new session for unrelated tasks.

Pitfall 5: Not Using CLAUDE.md

Without a CLAUDE.md file, Claude has to rediscover your project's conventions in every session. Spend 5 minutes creating one and you'll save time on every future session.

Frequently Asked Questions

Claude Code itself does not browse the internet. However, it can run shell commands that access the internet (like curl or npm install), and you can add MCP servers that provide web access. It can also fetch URLs if you have the WebFetch tool enabled.

When Claude Code reads a file, the file content is sent to Anthropic's API as part of the conversation context. Anthropic's data retention policies apply. If you're working with sensitive code, review Anthropic's privacy policy and consider using AWS Bedrock or Google Vertex AI for additional data controls.

Claude Code uses the standard Anthropic API pricing. Costs depend on the model you use and how many tokens you consume. A typical coding session (30 minutes, moderate usage) costs roughly $0.20–$1.00 with Sonnet and $1–$5 with Opus. Use /cost to monitor usage during a session. You can also set spending limits in your Anthropic console.

Yes. Claude Code runs locally on your machine and accesses your local files. It works with any repository you have checked out locally, regardless of whether it's public or private. For enterprise data residency requirements, consider using Claude Code with AWS Bedrock or Google Vertex AI.

Claude Code works with any programming language. It has particularly strong support for Python, JavaScript/TypeScript, Java, C/C++, Go, Rust, Ruby, PHP, and shell scripting. It can also work with configuration files (YAML, JSON, TOML), markup languages (HTML, CSS, Markdown), and infrastructure-as-code (Terraform, CloudFormation).

Yes. Use the non-interactive mode (claude -p "your prompt") with the --dangerously-skip-permissions flag in sandboxed CI/CD environments. Common uses include automated code review, generating changelogs, fixing linting errors, and creating PR descriptions. Make sure to set the ANTHROPIC_API_KEY environment variable in your CI/CD configuration.

Report issues and request features on the Claude Code GitHub repository. You can also use the /doctor command to run diagnostics and collect system information for bug reports.

No. Claude Code requires an internet connection to communicate with the Anthropic API (or AWS Bedrock / Google Vertex AI). All AI processing happens on Anthropic's servers, not locally. You need a stable internet connection for the tool to function.

Congratulations!

You have completed the Claude Code CLI course. You now know how to install, configure, and use Claude Code effectively for real-world development tasks. Here is a summary of what you learned:

  1. Introduction — What Claude Code is and how it works
  2. Installation — Setting up Claude Code on any platform
  3. Basic Commands — Essential commands and slash commands
  4. Editing Code — Single and multi-file editing with AI
  5. Workflows — Bug fixing, feature development, code review, and git workflows
  6. Configuration — Settings, CLAUDE.md, MCP servers, hooks, and custom commands
  7. Tips & Tricks — Power-user techniques for maximum productivity

Keep practicing and experimenting. The more you use Claude Code, the more efficient your workflows will become.

← Back to Course Overview