Back to articles

Prompting Best Practices with Claude Code

Claude Code is a powerful tool, but every interaction consumes tokens. Poor usage habits can quickly blow up your consumption while degrading response quality. The good news? A few simple habits can cut your consumption by 2x or 3x.

This article presents essential practices for optimizing your daily Claude Code usage: context management, MCP configuration, and effective prompting patterns.

Table of Contents
  1. Understanding context and its impact
  2. Mastering essential commands
  3. Being concise and structured
  4. Optimizing MCP configuration
  5. Advanced prompting patterns
  6. Session management and workflows
  7. Session checklist
  8. Common mistakes to avoid

Understanding context and its impact

Why context blows up your consumption

With every message you send, Claude Code transmits the entire conversation to the model. This means a long session consumes exponentially more tokens.

Simple visualization:
Message 1: 100 tokens sent
Message 2: 300 tokens (previous 100 + 200 new)
Message 10: 5000 tokens (entire history)
Message 30: 20000 tokens

You pay for your history with every request. This is trap number one.

The golden rule: One session = One topic

Never mix multiple topics in the same session. Each context switch should trigger a fresh, clean session.

Bad practice

[40-message session]
- Messages 1-15: Backend debugging
- Messages 16-25: React styling
- Messages 26-30: nginx config
- Messages 31-40: Documentation

All 40 messages carry context from 4 topics. Massive waste.

Good practice

[Session 1] Backend debugging → /clear
[Session 2] React styling → /clear
[Session 3] nginx config → /clear
[Session 4] Documentation

Each session is isolated and lightweight.

Context accumulates with every message. Use /clear whenever you switch topics.

Mastering essential commands

claude Start session
/context Check size
/compact If > 10k tokens
/clear New topic

The /clear command

Purpose: Completely erases conversation history.

When to use it:

Just fixed a bug → /clear
Switching from Python to JavaScript → /clear
Finished a code review → /clear
Session exceeded 25 messages → /clear

Important: Don't fear losing context. If you need information from the previous session, summarize it in one sentence in your new session.

The /compact command

Purpose: Summarizes the conversation while keeping only essential information.

When to use it:

Difference between /clear and /compact:
/clear = New session, clean slate
/compact = Same session, summarized version

The /context command

Purpose: Displays current context content sent to Claude.

Why it's crucial: It's your consumption dashboard. This command shows you EXACTLY what's being sent with each request.

=== Current Context ===
- History: 18 messages (approximately 12000 tokens)
- Files read: 3 files (approximately 2000 tokens)
- Active MCPs: filesystem, playwright, postgres (approximately 2500 tokens)
- System context: 1000 tokens
ESTIMATED TOTAL: 17500 tokens

Action based on result:

Build the habit: /context every 10-15 messages to monitor your consumption.

Being concise and structured

Principle: No chit-chat

Claude doesn't need pleasantries or narrative context. Get to the point.

Inefficient (120 tokens)

Hey Claude! Hope you're doing well.
So here's the thing, I've got a
little issue with my code. Yesterday
I tried to do something but it
didn't work. I think it might be
related to the database...

Efficient (25 tokens)

Bug: random timeouts GET /api/users
Stack: Flask + PostgreSQL + Redis
File: src/api/users.py
Diagnose the cause.

Savings: 75% fewer tokens, clearer information.

Pattern: Structured requests

Organize complex requests into clear sections:

CONTEXT: [1 sentence]
PROBLEM: [1-2 sentences]
GOAL: [what you want]
CONSTRAINTS: [if relevant]

Real example:

CONTEXT: Flask API in production, 200 req/min
PROBLEM: 15% of POST /orders requests fail with "connection pool exhausted"
GOAL: Identify and fix DB connection leak
CONSTRAINTS: No downtime possible

File to audit: src/api/orders.py

Group requests together

Anticipate and group related requests into a single instruction.

Inefficient (6 messages)

You: Create validate_email
Claude: [creates]
You: Check format
Claude: [adds]
You: And allowed domains
Claude: [adds]
You: And log errors
Claude: [adds]

Efficient (1 message)

Create validate_email() that:
- Validates RFC 5322 format
- Accepts only @company.com
- Logs invalid attempts
- Returns bool
- Includes 5 unit tests

Group all your requests into a single message. Each round-trip costs the entire context.

Optimizing MCP configuration

Understanding MCP impact

Each active MCP (Model Context Protocol) adds its complete documentation to the context of EVERY request, even if you don't use it.

MCP Impact per request
Playwright (browser) ~1000 tokens
PostgreSQL ~700 tokens
Filesystem ~500 tokens
Git ~400 tokens

Warning: With 5 active MCPs, you pay ~3000 tokens in "system tax" per message, before you've even written anything.

Rule: Disable by default, enable as needed

Most of the time, you only need 1 or 2 MCPs maximum.

Task Needed MCPs Unnecessary MCPs
Python refactoring filesystem browser, database, git
E2E UI tests filesystem, playwright database, git
Code review filesystem all others
SQL optimization filesystem, postgres browser, web

How to disable MCPs

Open your configuration file (~/.config/claude/settings.json) and add "disabled": true:

{
  "mcpServers": {
    "playwright": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-playwright"],
      "disabled": true
    },
    "postgres": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-postgres"],
      "disabled": true
    },
    "filesystem": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-filesystem"],
      "disabled": false
    }
  }
}

Tip: Create multiple versions of this file for different needs:

To launch Claude Code with a specific configuration, use the --mcp-config option:

# Launch with minimal config
claude --mcp-config ~/.config/claude/settings-minimal.json

# Launch for backend work
claude --mcp-config ~/.config/claude/settings-backend.json

# Create aliases in your .bashrc or .zshrc
alias claude-mini="claude --mcp-config ~/.config/claude/settings-minimal.json"
alias claude-back="claude --mcp-config ~/.config/claude/settings-backend.json"
alias claude-front="claude --mcp-config ~/.config/claude/settings-frontend.json"

Disable all MCPs except filesystem by default. Enable others only when needed.

Advanced prompting patterns

Pattern: Instructions without explanation

By default, Claude likes to explain what it's doing. It's educational but costly.

Standard

You: Create a validation function
Claude: I'll create a function
that validates passwords according
to standard security criteria.
It will check minimum length,
presence of special characters...
[code]

Optimized

You: Create a validation function.
Code only, no explanation.

Claude: [code directly]

Always add "code only" or "direct action" when you don't need explanations.

Pattern: Targeted file reading

Don't read entire files if you only need a section.

Inefficient

You: Read src/api/users.py (500 lines)
Claude: [reads everything]
You: Just look at get_user_by_id

You paid for 500 lines when you only needed 20.

Efficient

You: Read only the function
get_user_by_id in src/api/users.py

Or use grep to target.

Pattern: Direct commands

For simple actions, request the action directly without preamble.

Inefficient

You: Could you please run the
unit tests to see if there are
any errors?

Efficient

You: pytest

For standard bash actions, be minimalist:

Add "code only" or "no explanation" to save 40-60% of tokens on responses.

Session management and workflows

Workflow: Complete feature

Inefficient approach

[Single 2-hour session with 50 messages]
- Brainstorming
- Iterative implementation
- Tests
- Documentation
- Fixes

Massive context, enormous waste.

Efficient approach

[Session 1 - Planning] 10 msg → /clear
[Session 2 - Implementation] 15 msg → /clear
[Session 3 - Tests] 8 msg → /clear
[Session 4 - Docs] 5 msg

38 messages in 4 lightweight sessions.

Workflow: Debugging

Debugging tends to blow up context with logs and stack traces.

3-phase strategy:

PHASE 1 - Diagnosis (short session)
You: Bug on POST /orders: timeouts
Logs: [20 relevant lines]
Code: src/api/orders.py
Diagnose the probable cause.
Claude: Probable cause: connection pool leak line 45
You: /clear

PHASE 2 - Fix (new session)
You: Fix the connection pool leak in src/api/orders.py line 45
Claude: [fixes]
You: /clear

PHASE 3 - Validation (new session)
You: pytest tests/test_orders.py
Claude: [runs tests]

Break large tasks into short, focused sessions. /clear between each phase.

Session checklist

Before starting

  • What's my precise goal for this session?
  • Which MCPs do I actually need?
  • Have I prepared all necessary information?

During the session

  • Am I staying on the same topic? (if not → /clear)
  • Has my session exceeded 20 messages? (→ /compact or /clear)
  • Am I repeating information already given?
  • Am I asking for unnecessary explanations?

Every 10-15 messages

  • Type /context to check context size
  • If > 10000 tokens: decide between /compact or /clear

Common mistakes to avoid

Mistake 1: The marathon session

Symptom: A session that lasts hours with 60+ messages on various topics.

Impact: Consuming 50000+ tokens when 10000 would have sufficed.

Solution: Set a limit of 25 messages per session.

Mistake 2: All MCPs enabled by default

Symptom: You've never touched your settings.json.

Impact: 2000-3000 token "tax" per message.

Solution: Disable everything except filesystem, enable on a case-by-case basis.

Mistake 3: Reading entire large files

Symptom: "Read src/main.py" when the file is 1000 lines.

Impact: 1000+ tokens consumed unnecessarily.

Solution: Use grep or request targeted reads.

Mistake 4: Asking for systematic explanations

Symptom: Claude explains at length before each action.

Impact: 40-60% more tokens.

Solution: Add "code only, no explanation".

Mistake 5: Never using /context

Symptom: You don't know how many tokens your session is consuming.

Impact: You're navigating blind.

Solution: Type /context every 10-15 messages.

Conclusion

Optimizing your Claude Code usage means adopting simple habits:

  1. One session = One topic: /clear between each context switch
  2. Less than 25 messages per session: Beyond that, /compact or /clear
  3. Check context regularly: /context every 10-15 messages
  4. Disable unused MCPs: Only filesystem is needed 80% of the time
  5. Be concise and structured: No chit-chat, grouped information
  6. Direct action: "Code only" when you don't need explanations

Remember: These practices can reduce your consumption by 50-70% without impacting productivity. On the contrary, short, focused sessions produce better results.

Start with just one habit: type /context before your big requests. You'll immediately see your context's impact. Then gradually add the other practices.

Have questions or other techniques to share? Contact me or find me on LinkedIn.

Thomas Bourimech

Thomas Bourimech

Freelance Developer & AI Integrator

thomasbourimech.com