Lesson 2 of 5 5 min

Claude Code Lesson 1: Setting Up for Success (Context & Rules)

Learn how to optimize Claude Code for your specific project. Master the usage of .claudeignore, .cursorrules, and surgical context management for Staff engineers.

The Paradigm Shift in Context Management

In the world of LLMs, Context is Gold. Every token you send into the context window is a trade-off. In this lesson, we explore how to configure Claude Code to be a surgical instrument rather than a blunt object.

When you work with a chatbot (like ChatGPT or Claude Web), you are essentially hand-feeding the AI small snacks of information. Claude Code, however, has a direct "buffet" access to your entire codebase. Without proper setup, it will "overeat"—consuming thousands of irrelevant tokens from build artifacts, logs, and vendor code, which leads to degraded reasoning and high latency.

1. The Power of .claudeignore (Physical Isolation)

Just as you don't want Git to track your node_modules or build artifacts, you don't want Claude Code to waste its attention on them.

The Technical Why: When Claude searches your project (using grep_search), it iterates through every file it can see. If it hits a minified bundle.js or a 50MB CSV file, its reasoning capabilities drop significantly. It might even try to "fix" the minified code, causing massive build errors.

Actionable Setup:

Create a .claudeignore file in your project root. This is your first line of defense. Unlike .gitignore, which is for your remote repo, .claudeignore is for the AI's "Eyes."

# --- Build & Dependency Junk ---
.next/
dist/
out/
build/
node_modules/
venv/
.venv/
target/
*.pyc

# --- Large Data & Assets ---
public/images/
public/videos/
*.log
*.csv
*.json
*.sql (except small seeds)

# --- IDE & System Files ---
.vscode/
.idea/
.DS_Store
.git/

2. Using .cursorrules (The Global Mandates)

Claude Code respects instructions found in .cursorrules (or CLAUDE.md). Think of this as the "Constitutional Law" of your project.

As a Staff Engineer, you have specific architectural preferences. You shouldn't have to tell the AI "Don't use classes" every single time you prompt. By placing these in a rules file, the agent internalizes them during the initial "Research" phase of every task.

Staff-Tier Rule Examples:

  • Architectural: "Always prefer functional composition over class-based inheritance."
  • Stylistic: "Use early returns to reduce indentation depth. Ensure every function has a JSDoc/Docstring."
  • Workflow: "You are prohibited from using git commit or git push. Your responsibility ends at disk verification."
  • Tech Stack: "We are migrating to Next.js App Router; do not use the Pages router for new files."

3. Surgical Context Usage: The "Read-Only" Mindset

A beginner asks: "Fix the bugs in my app."
A Staff Engineer asks: "Research the AuthService.ts and the user table. Propose a plan to implement JWT rotation with a 15-minute expiry."

Claude Code provides specialized tools for Surgical Context Management. Mastering these is the difference between a 30-second fix and a 5-minute hallucination.

Tool 1: ls -R (The Map)

Never read files until you know where you are. Use ls -R to get a directory tree. This allows you to say, "Ah, I see a services/ and a controllers/ folder, I should start my search there."

Tool 2: grep_search (The Compass)

Use this to find exactly where a specific function or variable is used. Pro Tip: Use the context parameter (e.g., context: 5) to see the surrounding logic. This often saves you from needing to use read_file at all, as you can see the calling convention right in the search result.

Tool 3: read_file (start_line, end_line) (The Scalpel)

If you have a 1,500-line file, never read the whole thing. It will flush out other useful context from Claude's memory. Instead, read the specific lines you need to modify.

4. Visualizing the Context Loop

graph TD
    User[Your Prompt] --> Agent[Claude Code Agent]
    Agent --> Ignore{Is it in .claudeignore?}
    Ignore -- Yes --> Skip[Skip File]
    Ignore -- No --> Rules[Check .cursorrules]
    Rules --> Tools[Execute Surgical Reads]
    Tools --> Context[Lean Context Window]
    Context --> Implementation[High-Accuracy Code]

5. Advanced: Custom Sub-Agents

One of the most powerful features of Claude Code (and similar agentic environments) is the ability to invoke specialized Sub-Agents.

If you have a massive task, like "Implement Unit Tests for the entire lib/ directory," don't do it in the main thread. Invoke a generalist sub-agent. This "compresses" the sub-task's history, keeping your main session context clean and fast.

6. Real-World Scenario: Legacy Migration

Imagine you are migrating a legacy Java app to Spring Boot.

  1. Stage 1: Ask Claude to search for all new InitialContext() calls using grep_search.
  2. Stage 2: Use read_file on the top 3 most-used classes to see the pattern.
  3. Stage 3: Update your .cursorrules to say "When refactoring context lookups, always use Spring @Bean injection."
  4. Stage 4: Execute the refactor file-by-file.

Final Takeaway

You are the Architect; Claude is the Builder. If the building site (Context) is cluttered with trash (Build files), the Builder will make mistakes. Clean the site with .claudeignore, set the laws with .cursorrules, and operate with surgical precision.

Mastering these setup steps ensures that Claude Code remains a high-speed asset rather than a context-saturated liability.

Want to track your progress?

Sign in to save your progress, track completed lessons, and pick up where you left off.