Optimizing Context and Memory Management
- Hierarchical and Nested CLAUDE.md Files: Place project-specific rules in directory-level CLAUDE.md files (e.g., frontend/CLAUDE.md for UI guidelines). Claude automatically prioritizes the most relevant one based on your current working directory, allowing fine-grained control without global overrides.
- Reference External Files in Rules: In CLAUDE.md, link to other docs like "See: @docs/api.md" or "See: @.cursor/rules/self-improvement.mdc" to pull in additional context dynamically, reducing duplication and keeping instructions modular.
- Tune CLAUDE.md with Emphasis and Improvers: Run your CLAUDE.md through a prompt improver tool, then add phrases like "IMPORTANT" or "YOU MUST" to enforce adherence. This helps Claude stick to custom styles or constraints more reliably during long sessions.
- Self-Improvement Rules in CLAUDE.md: Add a rule that triggers Claude to analyze your codebase for recurring patterns (e.g., bugs or new libraries) and update CLAUDE.md automatically when they appear in 3+ files, evolving your setup over time.
Advanced Prompting and Thinking Modes
- Escalate Thinking with Magic Phrases: Use graduated keywords like "think", "think hard", "think harder", or "ultrathink" to allocate more tokens for deep reasoning on bugs or architecture. For example, "ultrathink about the security implications" forces extra computational budget, shown as italic gray text.
- Interrupt and Redirect with Escape: Press Escape to halt Claude mid-task without losing context, or double-tap to browse and edit previous messages for quick alternatives, perfect for steering away from dead-end paths.
- /clear for Fresh Starts: Run /clear between tasks to wipe irrelevant history and prevent token bloat from summaries, especially in long-running sessions.
- Avoid the Rabbit Hole: If stuck after 3-4 attempts, treat it like a "slot machine", save your state, let Claude run for 30 minutes, then accept or restart fresh rather than tweaking endlessly.
Tool Permissions and Security Tweaks
- Curate Tool Allowlists in .claude/settings.json: Manually edit this file (and commit to git) to restrict tools like Edit or Bash(git commit:*), sharing safe permissions team-wide and preventing accidental overreach.
- Session-Specific Permissions with --allowedTools: Launch Claude with --allowedTools to limit capabilities for one session, avoiding permanent changes, ideal for testing risky operations.
- Safe YOLO Mode in Containers: Run claude --dangerously-skip-permissions inside a Docker container (no internet) for low-stakes tasks like linting, minimizing security risks while bypassing prompts.
- Allowlist Domains with /permissions: Pre-approve URL fetching from specific sites via /permissions to skip repeated confirmations during web-related tasks.
- -mcp-debug for Troubleshooting: Start Claude with --mcp-debug to log and diagnose issues when connecting to external servers, speeding up integration setups.
Git and Version Control Integrations
- Commit Before Requests: Always commit your code and work in feature branches before prompting Claude. This creates easy rollback points if experiments fail.
- Prompt for Git History Searches: Explicitly instruct Claude to "analyze git logs" for insights on changes, ownership, or rationale, accelerating codebase exploration.
- Handle Complex Git Ops: Let Claude manage reverts, rebase conflicts, or patch grafting by describing the task naturally, no need for manual commands.