Magic Tools
Claude GuidesBy CooconApril 13, 2026246 views2 min read

Claude Code Tips and Best Practices

CLAUDE.md Project Configuration

CLAUDE.md is Claude Code's most powerful customization mechanism. Claude automatically reads this file at the start of each session, treating it as persistent project instructions.

Configuration Layers

File Path Scope Recommended Content
~/.claude/CLAUDE.md All projects (personal) Personal coding style preferences
project-root/CLAUDE.md Current project (shared) Tech stack, architecture, conventions
subdir/CLAUDE.md Specific module Module-specific rules

Effective CLAUDE.md Template

# Project Name

## Tech Stack
- Framework: Next.js 16 (App Router)
- Language: TypeScript 5
- Database: MySQL 8 + Prisma ORM

## Coding Standards
- Use ES module syntax (import/export)
- Prefer Server Components
- API responses use { code, msg, data } format

## Common Commands
- npm run build: Build the project
- npm run typecheck: Run type checker
- npm run test: Run tests

## Project Structure
src/app/     - Page routes
src/lib/     - Utilities and business logic
src/types/   - Type definitions

Context Management Strategies

Claude Code has a finite context window. Managing it effectively is key to a smooth experience.

  • Use /compact regularly: After long conversations, compress history while preserving key information
  • Reference files precisely: Give Claude exact file paths instead of letting it search the entire project
  • Segment large tasks: Break complex work into multiple conversations, each focused on a sub-goal
  • Use /clear when switching tasks: Start fresh when moving to an unrelated task

Effective Prompting Techniques

# Poor prompt
> Fix this bug

# Good prompt
> The getSession function in src/lib/auth.ts returns null instead of throwing
> an error when the token is expired. Change it to throw an AuthError, and
> update all callers in src/app/api/ to handle this exception.

Key principles:

  • Provide file paths: Reduces time Claude spends searching
  • Describe expected behavior: Don't just say "fix the bug" — explain what correct behavior looks like
  • Scope the changes: Be explicit about which files need modification

Multi-File Editing Strategies

Claude Code excels at cross-file refactoring with proper guidance:

  1. Give Claude the big picture first: "Read src/types/index.ts and all files in src/lib/actions/ to understand the current type definitions and API structure"
  2. Execute in stages: Modify type definitions first, then implementations, then callers
  3. Verify each step: "Run npm run typecheck to confirm the changes are correct"

Git Workflow Integration

# Generate commit message from current diff
> Review my changes and create a commit with an appropriate message

# Create a complete PR
> Create a PR from this branch to main with a summary and test plan

# Code review
> Review the last 3 commits and point out potential issues

Team Collaboration Best Practices

  • Share CLAUDE.md: Commit your project-level CLAUDE.md to the repo so all team members get consistent AI assistance
  • Standardize hooks: Set up team convention checks in .claude/settings.json (auto-lint, pre-commit validation)
  • Share prompt templates: Establish team-wide prompt templates for common scenarios like bug fixes, feature development, and code reviews

IDE Integration

Claude Code works across major development environments:

  • VS Code: Use the Claude Code extension directly within the editor
  • JetBrains: Supports IntelliJ IDEA, WebStorm, and the full JetBrains suite
  • Terminal: Run directly in any terminal, pairs well with Vim, Emacs, or any editor

FAQ

Is the CLAUDE.md file sent to Anthropic's servers?

Yes, CLAUDE.md content is included as part of the conversation sent to the API. If your CLAUDE.md contains sensitive information (like internal architecture details), ensure you're comfortable with Anthropic's data handling policies, or limit it to non-sensitive coding standards.

How do teams avoid CLAUDE.md merge conflicts?

Split CLAUDE.md by module: put universal conventions in the project root, and module-specific rules in subdirectories. This way, team members working on different modules won't conflict. Personal preferences go in ~/.claude/CLAUDE.md, which isn't committed to the repo.

Which IDEs does Claude Code support?

Claude Code officially provides a VS Code extension and JetBrains plugin. Since Claude Code is fundamentally a terminal tool, you can use it in any IDE or editor with terminal support, including Vim, Neovim, Emacs, and Sublime Text.

How can I control Claude Code's resource consumption?

Use the /cost command to check token usage at any time. Compress context with /compact, specify exact file paths, and break large tasks into smaller steps to effectively reduce token consumption.

Related Articles

Reproducing an Injection Chain That Cracks Claude Code Auto Mode: the Model Refuses the Malicious Binary, Then Writes Code That Pwns Itself

In late August embracethered published an attack chain where a plain 'summarize this page' request drags auto-mode Claude Code to a 60–80% code-execution rate — while Anthropic's commissioned third-party test reported 0.00%. I took the chain apart and tested it stage by stage in an isolated environment: the endpoint that nudges the model from WebFetch to curl, and the crux — the model's own 'safe' decision to refuse the unknown binary and write its own Python decoder instead lands straight on a same-name struct.py planted in the extracted directory. The deterministic parts (branching + module-shadow poison + mitigation controls) reproduce fully on my machine with real evidence; the live end couldn't complete a full RCE here because the classifier rate-limited and failed closed — flagged honestly. Ends with mitigations that actually help.

claude-codeauto-mode+5
hands-onAug 31, 20269 min
138

Cracking Open Claude Code's Auto-Mode Classifier: A 116K-Char System Prompt, Dissected Line by Line

My earlier retest confirmed auto mode calls the session model as a classifier before each risky Bash — but what it receives stayed a black box. This time I captured the full request: a 116,879-char system prompt opening 'You are a security monitor for autonomous AI coding agents.' I quote it verbatim to dissect the threat model, two-tier rules (1 HARD BLOCK / 68 SOFT BLOCK / 17 ALLOW), and two-stage evaluation — stage 1 grades harm only, stage 2 layers intent on top. Every number read out this session.

claude-codepermissions+5
hands-onAug 30, 202612 min
200
Turn a Home Mac mini Into an Always-On Claude Code Workstation: claudecodeui + SSH Reverse Tunnel, Take Over Sessions From Any Browser

Turn a Home Mac mini Into an Always-On Claude Code Workstation: claudecodeui + SSH Reverse Tunnel, Take Over Sessions From Any Browser

A Mac mini at home runs Claude Code around the clock — but how do you take over a session from a browser when you're away? This is a real setup that has been live for a week and in daily use: claudecodeui as the web UI (chosen over the official web version, ttyd, and code-server), an SSH reverse tunnel pushing it to a VPS, and nginx adding TLS plus login rate limiting to turn it into an ordinary URL. Includes full configs, real operating numbers (five days of tunnel uptime with zero drops, 170MB RSS), a <synthetic> placeholder bug hit and fixed within the first week, and an honest for-and-against on why not Tailscale.

claude-codeclaude-code-lab+7
claudeAug 29, 202612 min
211

You Set ANTHROPIC_BASE_URL. Claude Code Ignored It.

I exported ANTHROPIC_BASE_URL in .zshrc to point at a self-hosted API gateway, and Claude Code kept talking to Google Vertex anyway. On the same machine, a launchd-managed web UI insisted it wasn't authenticated at all. Neither bug was in the gateway — both were in the gap between 'I set the env var' and 'the process actually has it.'

claude-codebug-postmortem+2
pitfallsAug 24, 20264 min
276

Published by Magic Tools