当前位置: 首页 > Skill >

Claude Code official best practices for ALL AGENT

Claude Code official best practices for ALL AGENT

Claude Code official best practices for ALL AGENT

Apply all 9 chapters of Claude Code official best practices for ALL AGENT — verification, explore-plan-code, prompts, environment, communication, session management, automation, failure patterns, and intuition.

1.1.1 2026.11.16 828
获取Skill文件查看使用说明
作 者:沈辰 许可证: 更新时间:2026.11.16
本文目录展开

Claude Code Best Practices Skill

Apply these best practices from the official Claude Code documentation.

Core Constraint

Claude's context window fills up fast and performance degrades as it fills. This is the single most important resource to manage. All best practices flow from this constraint.

1. Give Claude a way to verify its work

  • Always provide pass/fail checks: test suites, build exit codes, linters, output diffs, screenshot comparisons
  • Without verification, "looks done" is the only signal and the user becomes the verification loop
  • Choose strictness level: single prompt → /goal condition → Stop hook → verification subagent (independent reviewer)
  • Claude should show evidence (test output, commands run, screenshots) rather than claiming success
  • Provide verification criteria in the initial prompt, not after implementation

2. Explore first, then plan, then code

Follow four phases for non-trivial tasks:

  1. Explore: Enter plan mode, read files, understand architecture, make no changes
  2. Plan: Create detailed implementation plan (Ctrl+G lets user edit in text editor)
  3. Implement: Exit plan mode, code + write tests + run test suite + fix failures
  4. Commit: Descriptive commit message, create PR

Skip planning when: scope is clear, fix is small (typo, log line, variable rename), or diff can be described in one sentence. Plan when: uncertain about approach, changes span multiple files, or modifying unfamiliar code.

3. Provide specific context in prompts

  • Reference specific files, mention constraints, point to example patterns
  • Scope the task: specify which file, what scenario, testing preferences
  • Point to sources: direct to git history, documentation, API references
  • Reference existing patterns: show Claude how similar things are done in the codebase
  • Describe the symptom: provide bug symptoms, likely location, and "fixed" definition

Provide rich content via: @ file references, pasted screenshots, URLs, piped data (cat error.log | claude), or telling Claude to fetch context itself.

4. Configure your environment

CLAUDE.md

  • Run /init to generate starter, then refine over time
  • Include: Bash commands Claude can't guess, non-standard code style rules, testing instructions, repo etiquette, architectural decisions, environment quirks, common gotchas
  • Exclude: anything Claude can figure out from code, standard conventions, detailed API docs (link instead), frequently-changing info, long tutorials, self-evident practices
  • Rule of thumb: for each line, ask "Would removing this cause Claude to make mistakes?" If not, cut it
  • Place at: ~/.claude/CLAUDE.md (global), ./CLAUDE.md (project root, check into git), ./CLAUDE.local.md (personal, gitignore), parent directories (monorepos), child directories (on-demand)
  • Use @path/to/import to import additional files
  • Add emphasis ("IMPORTANT", "YOU MUST") to improve adherence

Permissions

  • Auto mode: separate classifier model reviews commands, blocks only risky ones
  • Permission allowlists: permit specific safe commands like npm run lint or git commit
  • Sandboxing: OS-level isolation restricting filesystem and network access

CLI tools

  • Use gh, aws, gcloud, sentry-cli for external service interaction
  • Claude can learn new CLI tools: "Use 'foo-cli-tool --help' to learn about it, then solve A, B, C"

MCP servers

  • claude mcp add to connect Notion, Figma, databases, issue trackers, monitoring data

Hooks

  • Deterministic scripts that run at specific workflow points (unlike CLAUDE.md which is advisory)
  • Configure in .claude/settings.json, browse with /hooks
  • Claude can write hooks for you

Skills

  • Create SKILL.md in .claude/skills/ for domain knowledge and reusable workflows
  • Invoke with /skill-name
  • Use disable-model-invocation: true for workflows with manual side effects

Subagents

  • Define in .claude/agents/ with independent context and tool permissions
  • Useful for tasks reading many files or needing isolation

Plugins

  • Bundle MCP servers, skills, and hooks for one-click installation
  • Browse installed with /plugins

5. Communicate effectively

Ask codebase questions

  • Ask like you'd ask a senior engineer — no special prompting needed
  • Great for onboarding: "How does logging work?", "How do I make a new API endpoint?"

Let Claude interview you

  • For larger features, have Claude interview first using AskUserQuestion tool
  • Cover: technical implementation, UI/UX, edge cases, concerns, tradeoffs
  • Write complete spec to SPEC.md after interview
  • Start fresh session to execute spec (clean context focused on implementation)
  • Best specs: name files/interfaces involved, state what's out of scope, end with end-to-end verification step

6. Manage your session

Course-correct early and often

  • Esc: stop Claude mid-action, context preserved
  • Esc+Esc or /rewind: open rewind menu, restore previous state or summarize
  • "Undo that": have Claude revert changes
  • /clear: reset context between unrelated tasks
  • Rule: if corrected more than twice on same issue, /clear and start fresh with better prompt
  • Clean session + better prompt > long session + accumulated corrections

Manage context aggressively

  • /clear: completely reset context window (use frequently between tasks)
  • /compact : compact with specific instructions
  • /rewind → Summarize from here: condense from that point forward
  • /rewind → Summarize up to here: condense earlier messages, keep recent full
  • /btw: quick questions, answer in dismissible overlay, never enters history
  • Customize compaction in CLAUDE.md

Use subagents for investigation

  • Delegate research to subagents — they explore in separate context, report summaries
  • Also use for post-implementation verification: "use a subagent to review this code for edge cases"

Rewind with checkpoints

  • Every prompt creates checkpoint, files snapshotted before each change
  • Restore: conversation only, code only, both, or summarize from selected message
  • Checkpoints persist across sessions — close terminal and still rewind later
  • Only tracks Claude's changes, not a git replacement

Resume conversations

  • /rename sessions with descriptive names, treat like branches
  • claude --continue: resume most recent, claude --resume: choose from list

7. Automate and scale

Non-interactive mode

  • claude -p "prompt" for CI, pre-commit hooks, scripts
  • Output formats: plain text, --output-format json, --output-format stream-json --verbose

Multiple sessions

  • Worktrees: isolated git checkouts, edits don't collide
  • Desktop app: visual management of multiple local sessions
  • Claude Code on the web: cloud infrastructure, isolated VMs
  • Agent teams: automated coordination, shared tasks, team lead

Writer/Reviewer pattern: Session A implements, Session B reviews in fresh context.

Fan out across files

  • For large migrations: generate task list → write loop script → test on 2-3 files → run at scale
  • Use --allowedTools to scope permissions for unattended batch operations

Auto mode for autonomous runs

  • claude --permission-mode auto -p "fix all lint errors"
  • Classifier blocks scope escalation, unknown infrastructure, hostile-content actions
  • Non-interactive auto mode aborts if classifier repeatedly blocks (no user fallback)

Adversarial review step

  • Subagent reviews diff in fresh context, reports gaps
  • Prompt reviewer to flag only correctness/requirement gaps, not style preferences
  • Warning: reviewers asked to find gaps will usually report some even when work is sound — don't chase every finding, leads to over-engineering

8. Avoid common failure patterns

Pattern Symptom Fix
Kitchen sink session Unrelated tasks pollute context /clear between unrelated tasks
Correcting over and over Context polluted with failed approaches After 2 failures, /clear + better prompt
Over-specified CLAUDE.md Too long, Claude ignores half Ruthlessly prune
Trust-then-verify gap Plausible but misses edge cases Always provide verification; don't ship unverifiable
Infinite exploration Unscoped investigation fills context Scope narrowly or use subagents

9. Develop your intuition

  • These patterns are starting points, not iron rules
  • Sometimes let context accumulate (deep in one complex problem)
  • Sometimes skip planning (exploratory tasks)
  • Sometimes vague prompt is right (see how Claude interprets before constraining)
  • Notice what works: prompt structure, context provided, mode used
  • Ask why when Claude struggles: noisy context? vague prompt? too big for one pass?

Inter-chapter Relationships

Context Management (core constraint)
├── Provide specific context → fewer corrections → save context
├── Explore then plan → avoid solving wrong problem → save context
├── Manage context aggressively → /clear, /compact, subagents
└── Avoid failure patterns → kitchen sink, over-correction, infinite exploration

Verification (automation foundation)
├── Give verification means → unattended runs possible
├── Adversarial review → ensure correctness for long autonomous runs
└── Auto mode → batch unattended execution

Environment Configuration (multiplier)
├── CLAUDE.md → persistent knowledge every session
├── Skills → on-demand domain knowledge loading
├── Subagents → isolated investigation/verification
├── Hooks → deterministic auto-execution
├── CLI tools → efficient external service interaction
└── MCP servers → connect external data sources

Scaling
├── Non-interactive mode → CI/script integration
├── Multiple sessions → parallel development + independent review
├── File fan-out → large-scale batch operations
└── Agent teams → multi-task auto-coordination

推荐文章

更多
PHP时间戳与日期字符串相互转换方法详解

本文介绍PHP中时间数值(Unix时间戳)与日期字符串之间的相互转换方法。通过strtotime和date函数,实现将当前时间、指定日期转换为时间戳,以及将时间戳格式化为可读的日期时间字符串,并提供相关在线计算工具推荐。

2025.11.30 1,036
PHP日期转时间戳时区偏差怎么解决

在 PHP 中将日期字符串转换为时间戳时,若未显式指定时区,默认使用脚本配置的 date.timezone 或系统时区。当服务器时区与业务逻辑预期(如 UTC )不一致时,会产生偏差。解决核心是确保输入字符串携带明确时区信息,或在转换前统一设置时区上下文。

2026.10.24 1,031
JavaScript中利用replace结合正则实现replaceAll效果

JavaScript原生仅支持replace()进行单次或全局替换,缺乏类似Java的replaceAll()便捷方法。本文总结四种在JS中实现全量替换的方案:使用带g标志的正则、带gm标志的正则、扩展String原型以及split后join。通过对比代码示例,展示各方法的实现细节与适用场景,帮助开发者根据需求选择最优解。

2025.04.29 1,020
PHP跨域配置:怎么安全地允许指定域名而非使用通配符

在 PHP 中安全地允许指定域名跨域,核心是解析请求头中的 Origin ,验证其是否在白名单内,然后动态设置 Access-Control-Allow-Origin 响应头。不要使用通配符 * ,也不要硬编码单一域名。

2025.03.29 1,019
PHP实现基础文件上传:HTML表单与$_FILES处理流程

在 HTML 表单中设置 enctype="multipart/form-data" ,并在 PHP 后端通过 $_FILES 数组接收文件,调用 move_uploaded_file() 将临时文件移动到目标目录即可完成上传。

2026.09.07 1,016
OpenAI的Jalapeno芯片未落地,教你分辨300兆瓦算力消息

OpenAI计划在SB Energy租赁的数据中心部署约300兆瓦自研Jalapeno推理芯片,但目前双方仍处于洽谈阶段,交易细节与上线时间表均未公布。本文带你按报道原文核实项目所处阶段,厘清芯片发布、电力功率与实际推理算力的边界,并将融资意向与签约、开工、投运节点分开追踪,避免误将规划容量计入现有算力。

2026.12.02 1,014
Skill 文件
  • SKILL.md
    • Claude Code Best Practices Skill
    • Core Constraint
    • 1. Give Claude a way to verify its work
    • 2. Explore first, then plan, then code
    • 3. Provide specific context in prompts
    • 4. Configure your environment
      • CLAUDE.md
      • Permissions
      • CLI tools
      • MCP servers
      • Hooks
      • Skills
      • Subagents
      • Plugins
    • 5. Communicate effectively
      • Ask codebase questions
      • Let Claude interview you
    • 6. Manage your session
      • Course-correct early and often
      • Manage context aggressively
      • Use subagents for investigation
      • Rewind with checkpoints
      • Resume conversations
    • 7. Automate and scale
      • Non-interactive mode
      • Multiple sessions
      • Fan out across files
      • Auto mode for autonomous runs
      • Adversarial review step
    • 8. Avoid common failure patterns
    • 9. Develop your intuition
    • Inter-chapter Relationships
  • 项目或源文件

相关 Skill

更多
skill-creator-enhanced skill-creator-enhanced Enhanced skill creator with templates, validation, publishing workflow, and quality gates. Guides through skill creation process with best practices, common patterns, and ClawHub integration.
NextJS Frontend Development + Integration NextJS Frontend Development + Integration Generate production-ready Next.js projects with TypeScript, Tailwind CSS, shadcn/ui, and API integration. Use when the user asks to build, create, develop, or scaffold a Next.js application, web app, full-stack project, or frontend with backend integration. Prioritizes modern stack (Next.js 14+, TypeScript, shadcn/ui, axios, react-query) and best practices. Also triggers on requests to add features, integrate APIs, or extend existing Next.js projects.
Two Factor Authentication Best Practices Two Factor Authentication Best Practices 该技能为使用 Better Auth 的 twoFactor 插件实施安全的双因素认证(2FA)提供指导和强制规则。
docker-plus docker-plus Enhanced Docker with Dockerfile templates, multi-stage builds, security hardening, production best practices, Docker Compose patterns, and troubleshooting guides.
HR每日精选日报 HR每日精选日报 Generate a professional HR daily briefing report as a beautifully designed HTML page. Use when the user requests an HR daily report, HR industry news digest, human resources trend analysis, HR best practices compilation, or HR case study review. Covers insights from top consulting firms (McKinsey, Deloitte, BCG, Mercer, WTW), deep dives into HR functional modules (recruitment, performance, compensation, talent development, employee relations, HR planning) and the three-pillar model (HRBP, COE, S