Skip to content
explainroo
Working with AI agents

Claude Code Best Practices

Updated 4 min read

With explainroo How to Prompt a Coding Agent to Make an Explainer Video
On this page
  1. Scope the task before asking for code
  2. Give Claude project-specific context
  3. Keep the session focused
  4. Require a check that matches the change
  5. Add automation only when it earns its upkeep

Claude Code is Anthropic’s coding assistant for working with a code repository through the terminal, IDE, desktop app, or web. It can inspect files, edit code, and run commands. Clear instructions and checks help it produce better results.

Give Claude a focused task with the project details it needs, plus a way to check its changes. Anthropic’s best-practices guidance recommends managing the context window, which holds the information available during a session. The window fills as Claude reads and works. When it gets crowded, Claude can lose track of earlier details or make more mistakes.

Scope the task before asking for code

Tell Claude what you want it to change, where the code is, and which constraints to follow. A prompt such as “Fix the failing login test in auth/session.test.ts; preserve the existing session behavior and run the relevant tests” gives Claude a clear task and a way to tell when it is done.

For larger or uncertain changes, separate exploration from implementation. Ask Claude to trace the current behavior and identify likely files, then propose an approach before editing. Plan mode keeps investigation separate from editing and reduces the chance that Claude solves the wrong problem. During planning, ask Claude to consider both failure cases and security risks. It may not raise every difficult question on its own.

Use plan mode selectively. Anthropic recommends skipping it for small, obvious edits, such as a typo or variable rename. If you can describe the full change in one sentence, ask Claude to make it directly.

Give Claude project-specific context

Put stable project instructions in a CLAUDE.md file. Claude reads this file at the start of a session. Use it for information that applies across tasks. Run /init to create a starting point, then edit it to reflect how the repository actually works. Anthropic describes this and other Claude Code features in its product overview.

Keep the file concise. Include details Claude would otherwise have to rediscover, such as the project’s purpose, directory layout, and coding conventions. Also include build and test commands and important constraints. For example, if a project must use static exports or meet accessibility requirements, state that directly. Remove outdated instructions and details for just one feature. A long file uses context in every session. A project-focused example shows how repository-specific details can make those instructions more useful.

For task-specific context, point Claude to relevant files or provide the exact error, expected behavior, and existing pattern to follow. Use file references, paste relevant content, or share a screenshot when the problem is visual. Avoid asking Claude to search the entire repository when you already know the likely location.

Keep the session focused

Treat the context window as a limited working space. Each file Claude reads adds information to the session, as do its instructions and the results it produces. When a long session shifts between unrelated tasks, Claude has a harder time keeping important details in view.

Give separate tasks separate sessions when their context does not overlap. During a long task, check the context display and condense or reset the session when it becomes crowded. Keep recurring project rules in CLAUDE.md; keep one-off requirements in the prompt. This keeps useful context in each session without adding details for every task.

Require a check that matches the change

Tell Claude how to verify its work before it starts. For a code change, that might mean running a targeted test, a full test suite, or a build. For a visual change, provide a screenshot or describe the expected appearance and ask Claude to compare the result.

Anthropic recommends closing the verification loop so Claude can run a check and respond to its result. Depending on the task and setup, ask Claude to use /verify, define a goal, or configure a hook. A hook is a command that runs automatically at a chosen point. A hook can run a formatter after edits or a check before a commit. Keep the check relevant: a focused test gives faster feedback than an unrelated, long suite.

Review the diff yourself before accepting changes. Confirm that Claude changed the intended files, preserved existing behavior, and did not introduce unrelated edits. Tests help catch failures, but they do not prove that a design choice or security-sensitive change is correct.

Add automation only when it earns its upkeep

Reusable instructions and automation reduce repeated prompting. Use a skill to give Claude guidance for matching tasks. Consider a hook for a deterministic action that should run at a specific point. Claude Code also supports running work alongside other tools and in CI, as described in the overview.

Start with one repeated task, such as reviewing a pull request or running a standard check. Test the automation and explain its behavior; remove it when setup or review costs more than it saves. Give Claude only the permissions it needs. Review commands carefully before allowing them to change files, access secrets, or affect external services.

Free and open source

Let your AI agent make the video

explainroo lets a coding agent like Claude Code or Codex make narrated explainer videos and product demos. The voice, the word timing and the rendering run on your own computer, with no API key and no cost per video. Optional outside services use your own key.

Copy this into your AI agent

Make me a short explainer video about [your topic]. Use explainroo for it: run npx --yes explainroo docs and follow what it prints.

Getting started Example videos GitHub

Made with explainroo: How explainroo makes a video

More on working with ai agents

All guides on working with ai agents