Magic Tools
Claude GuidesBy CooconApril 13, 2026379 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

Blocking rm -rf in Claude Code: A Deny Rule Stopped 14 Deletes in Two Weeks, 7 Other Spellings Still Get Through, and a Hook That Closes the Gap

To keep Claude Code from deleting things by accident, I added a deny rule, Bash(rm -rf *), to my global settings. Across my sessions from October 7 to 21 it blocked 14 deletes. After each denial the model picked a new directory name 8 times and dropped the delete 6 times. It never tried another spelling. Then I replayed 22 delete commands verbatim against Claude Code 2.1.285 through a stub. rm -fr, rm -r -f, rm -Rf and rm -r deleted the directory in manual, auto and bypass mode alike. /bin/rm, find -delete and bash -c deleted it in manual and bypass mode. In auto mode, rm -fr inside the working directory skips the classifier because it 'would be allowed in acceptEdits mode'. A second, built-in dangerous-rm check fires on targets like $D/*, even in bypass mode, but loses track of a variable assignment when a heredoc comes earlier in the same command. The post ends with a PreToolUse hook that blocks every recursive spelling in all three modes and tells the model what to do instead.

claude-codehooks+5
pitfallsOct 21, 20268 min
315

Claude Code Auto Mode with DeepSeek, GLM or Kimi: What Each "temporarily unavailable" Reason Means and When Retrying Is Pointless (Fault-Injection Test)

On a third-party model, Claude Code auto mode sends one extra classifier request per side-effecting action, from your session model to the same backend: a 132,470-character system prompt, about 29.7K input tokens per check. When it fails, you see "xxx is temporarily unavailable, so auto mode cannot determine the safety of Bash". We injected faults and recorded each message: 500 (server error), 429 (rate-limited), 529 (overloaded) and connection resets (connection failed) are retried 5 times; no reply in 60 s gives (timed out). **No parentheses means a 4xx rejection: tried once, and retrying never helps.** A reply with no verdict gives "could not evaluate"; three in a row bring back manual approval. CLAUDE_CODE_AUTO_MODE_MODEL has no effect. Claude Code 2.1.285, real DeepSeek v4-pro and MiMo v2.5 backends.

claude-codedeepseek+7
pitfallsOct 11, 202612 min
460

Claude Code "Prompt is too long" vs "maximum context length": Why Auto-Compact Works for One and Not the Other (Tested)

Claude Code decides a request was too long by matching the error text. If the backend says prompt is too long or input is too long for requested model, it auto-compacts the conversation and retries — invisible to you. DeepSeek and OpenAI-style gateways say This model's maximum context length is …, which it doesn't recognize: you get API Error: 400 on every turn. Manual /compact works; the better fix is to declare the real window with CLAUDE_CODE_MAX_CONTEXT_TOKENS (non-claude- model IDs) or CLAUDE_CODE_AUTO_COMPACT_WINDOW (claude- IDs) so it compacts before hitting the limit. Tested on Claude Code 2.1.285 against a local stub.

claude-codedeepseek+6
pitfallsOct 5, 20267 min
474

Claude Code Stuck on a Spinner With No Response: It Waits 6 Minutes per Attempt, and 10 Retries Can Hang It for Over an Hour (Tested)

When Claude Code spins without output or sits at Retrying in 0s, the backend is usually not sending anything. Tested on 2.1.285 (API key + ANTHROPIC_BASE_URL): with no response headers it waits 6 minutes (360 s) per attempt before timing out — setting API_TIMEOUT_MS to 600000 or 900000 doesn't change that; only lower values work. With the default 10 retries it can hang for over an hour. A gateway that buffers the reply until generation finishes will never deliver a reply that takes over 6 minutes. Press Esc to interrupt. All tested against a local stub.

claude-codetroubleshooting+5
pitfallsOct 5, 20269 min
407

Published by Magic Tools