50 Essential Claude Code Rules No One Shares

This guide compiles 50 practical Claude Code best‑practice rules—from managing context windows and framing prompts to configuring CLAUDE.md, defining reusable skills, avoiding anti‑patterns, and leveraging advanced tricks—helping developers turn intuition into a reliable, industrial‑grade AI‑assisted workflow.

TonyBai
TonyBai
TonyBai
50 Essential Claude Code Rules No One Shares

Foundational Tips – Counter Entropy

Core logic: Context is scarce; clarity is the highest lever.

Clear Task Framing: Begin with Role + Task + Context in the first sentence.

Front‑Load Instructions: Place the most important constraints (e.g., “never modify config files”) at the very start of the prompt.

Verification (highest lever): Ask Claude to produce a way to verify its work, e.g., “Fix this bug and write a test case to verify the fix.”

Provide Screenshots: When UI changes are required, paste a screenshot so Claude can use its visual ability.

Address Root Causes: When an error occurs, instruct Claude to solve the underlying cause rather than merely suppress the error.

Plan Mode (Shift+Tab): For tasks involving more than two files, start in Plan mode and follow the workflow: Explore → Plan → Implement.

Review the Plan: Review Claude’s plan before it starts coding; correction cost is lowest at this stage.

One‑shot vs Plan: Small typo fixes can be one‑shot; refactoring a module requires a plan.

Specific Context: Reference specific files with @ instead of letting Claude read the whole repository.

Rich Content: Pipe logs directly, e.g., cat error.log | claude, to give Claude immediate feedback.

Clear Context: After a task finishes, run /clear to avoid context clutter.

Summarize Before Clear: Use /compact to compress context if you need to retain memory, then continue.

Configuration – Giving AI Rules

Core logic: Persist rules in files so they are not re‑taught each session.

CLAUDE.md as Constitution: Create a CLAUDE.md at the repository root; Claude reads it on every start.

Use /init: Run /init to let Claude analyze the project and generate an initial CLAUDE.md.

Prune Ruthlessly: Keep CLAUDE.md concise. Example: ❌ “Write elegant code.” ✅ “Run npm run test:unit to execute unit tests.”

Bash Commands: List project‑specific commands (build, deploy, test) in the file.

Code Style: Explicitly state preferences such as tab vs. space, TypeScript vs. JavaScript.

Import Rules: Define alias paths (e.g., @src/) to avoid guessing.

Child Directories: In monorepos, place separate CLAUDE.md files in subdirectories; Claude inherits them.

Permissions Allowlist: Use /permissions to whitelist safe commands such as ls, grep, npm test.

Sandbox Mode: Enable /sandbox for untrusted tasks to run in isolation.

Dangerously Skip: Use --dangerously-skip-permissions only when the environment is fully controlled (offline or sandbox).

CLI Tools: Install the GitHub CLI ( gh) so Claude can open PRs and view issues.

MCP Connect: Connect to Postgres or Notion with claude mcp add to avoid data silos.

Learn CLI: If a tool is unknown, let Claude run tool --help to learn its usage.

Skills & Automation – Extending Capability

Core logic: Package repeated workflows as “skills” and integrate Claude into CI pipelines.

Skills Definition: Create .claude/skills/SKILL.md to define reusable abilities.

Domain Knowledge: Encapsulate complex business logic (e.g., order‑state flow) as a skill and load it on demand.

Disable Model Invocation: For high‑risk skills, set disable-model-invocation: true to require human confirmation.

Custom Subagents: Define dedicated agents such as .claude/agents/security-reviewer.md.

Use the security‑reviewer subagent to act only as a reviewer, not a writer.

Delegate to Subagents: In the main session say “Use security‑reviewer to check the code just generated.”

Install Plugins: Run /plugin to browse the marketplace for ready‑made skill packs (e.g., Python code analysis).

Code Intelligence Plugin: Install to give Claude “go‑to definition” and “find references” via LSP.

Hooks: Configure hooks in .claude/settings.json, e.g., run Lint automatically after an Auto‑fix.

Headless Mode: Use claude -p "prompt" for fully automated scripts.

CI Integration: Run Headless Mode in GitHub Actions to automatically review PRs.

Structured Output: Add --output-format json so scripts can parse Claude’s answers.

Fan‑out Pattern: For batch changes across many files, loop claude -p in a shell script.

Anti‑patterns – Pitfall Guide

Core logic: Detect “smell of failure” and stop loss early.

The Kitchen Sink Session: Trying to fix bugs, add features, and write docs in one session leads to context pollution and degraded output. Solution: Finish one task then run /clear.

Over‑correcting: Re‑correcting twice without success reinforces the wrong path. Solution: Abort, run /clear, and improve the prompt.

The Trust‑then‑Verify Gap: Assuming code is correct without testing can cause production incidents. Solution: Never trust code that hasn’t passed tests.

The Infinite Exploration: Asking Claude to “investigate the codebase” without a scope consumes tokens without progress. Solution: Limit the search range or use a subagent for research.

Vague Error Reporting: Only saying “it fails” forces Claude to guess. Solution: Paste the full stack trace.

Pro Moves – Advanced Techniques

Resume Session: Use claude --resume to continue a session from a previous day.

Rename Session: Use /rename to give the session a meaningful name, e.g., feat-login-oauth.

Rewind (Esc+Esc): Double‑press Esc to roll back to the previous step, faster than editing code.

Let Claude Interview You: Prompt Claude to act as a senior architect and ask questions until enough information is gathered to write a spec.

Self‑Correction Loop: Prompt “Analyze the code you just generated, find three potential edge cases, and fix them.”

Model Tier Selection: Use a cheap model such as Haiku for simple lint fixes and a powerful model such as Opus for architectural design.

Parallel Sessions: Open two terminals: one as Writer, one as Reviewer, to boost quality.

Develop Intuition: Continuously use Claude to build a feel for context limits and model capabilities.

Conclusion – From Intuition to Methodology

Early use of Claude Code relies on intuition. To achieve stable, large‑scale production output, adopt a systematic methodology based on the 50 rules above. This transforms ad‑hoc prompting into an industrial‑grade workflow.

Reference: https://code.claude.com/docs/en/best-practices

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

cliautomationPrompt engineeringAI codingsoftware developmentbest practicesClaude Code
TonyBai
Written by

TonyBai

Tony Bai's tech world (tonybai.com). Not satisfied with just "knowing how", we strive for mastery. Focused on Go language internals, high-quality engineering practices, and cloud‑native architecture, exploring cutting‑edge intersections of Go and AI. Gophers who pursue technology are welcome—follow me and evolve with Go.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.