AI Personal Learning
and practical guidance
CyberKnife Drawing Mirror

Getting to grips with Claude Code: a practical guide to boosting AI programming productivity

Getting to grips with Claude Code: hands-on agent-based coding tips from the frontline

Claude Code Agentic Coding is a command-line tool for agentic coding. Agentic coding refers to the idea of giving AI some autonomy to understand tasks, plan steps, and perform actions (e.g., read/write files, run commands) to do coding-related work, rather than just code completion or Q&A. This guide brings together the best practices for coding in different codebases, languages, and environments using the Claude Code Practical tips and tricks that are proven to work.

Anthropic Recently released Claude Code, this tool was originally developed as a research project to allow in-house engineers and researchers to more naturally integrate the Claude models are integrated into the daily coding process.


Claude Code The design philosophy is deliberately low-level and unopinionated, providing access close to the original model without forcing the user to follow a specific workflow. This design makes it a powerful tool that is flexible, customizable, scriptable, and relatively secure. However, this flexibility also means that engineers who are new to agent-based coding tools need some learning time until they figure out the best practices for themselves.

In this article, we'll introduce some of the things that have been Anthropic Effective models that have been extensively validated by internal teams and external engineers. These suggestions are not golden rules or universally applicable; you can consider them as a starting point and then experiment boldly to find what works best for you.

1. Customize your work environment

Claude Code Acts as an agent-based coding helper that automatically integrates contextual information into prompts. While context collection consumes time and tokens, it can be optimized by adjusting environment settings. Understanding and utilizing CLAUDE.md Documentation is a critical first step.

a. Creation CLAUDE.md file

CLAUDE.md is a special document thatClaude Code automatically loads its contents into the context when a dialog is started. This makes it an ideal place to record the following information:

  • Common bash commands
  • Description of project core documents and tool functions
  • Code style specification
  • Test Execution Instructions
  • Code repository collaboration specifications (e.g., branch naming conventions, merge and variant base selection, etc.)
  • Development environment settings (e.g.pyenv use, applicable compiler version)
  • Any special behaviors or warnings that need attention in the project
  • Other hopes Claude Long-term "remembered" information

CLAUDE.md There are no mandatory formatting requirements for the document and it is recommended to keep it simple and human readable. Example:

# Bash 命令
- npm run build: 构建项目
- npm run typecheck: 运行类型检查器
# 代码风格
- 使用 ES 模块 (import/export) 语法,而非 CommonJS (require)
- 尽可能使用解构导入 (例如 import { foo } from 'bar')
# 工作流程
- 完成一系列代码更改后,务必运行类型检查
- 为提高性能,优先运行单个测试,而不是整个测试套件

You can set the CLAUDE.md Files are placed in multiple locations:

  • Warehouse root directoryor if you run claude command's directory (the most common usage). Name it CLAUDE.md and submit it to git in the configuration so that it can be shared across sessions and team members (recommended). If you want the local configuration not to be shared, you can name the CLAUDE.local.md incorporate .gitignoreThe
  • (of a computer) run claude Any parent directory of the command directoryThis is particularly useful in monorepo. This is especially useful in monorepo. For example, if you add the root/foo directory and run claudeThis can be done in the root cap (a poem) root/foo directory are placed under the CLAUDE.md file, both are automatically loaded.
  • (of a computer) run claude Any subdirectory of the command directory. Contrary to the previous case, when you work with files in subdirectories, theClaude will load these subdirectories on demand. CLAUDE.md Documentation.
  • Your user home directory (~/.claude/CLAUDE.md). The configuration here will be applied to all your claude Sessions.

(of a computer) run /init command, theClaude will automatically generate a base for you CLAUDE.md Documentation.

b. Tuning your CLAUDE.md file

CLAUDE.md The file will become Claude part of the prompt, so it should be polished just as you would a common prompt. A common misconception is to add a lot of content without verifying its effectiveness. Take the time to experiment and see which commands the model follows better.

You can manually edit the CLAUDE.mdThe Claude Code Press # key, giving a command thatClaude It will automatically be integrated into the relevant CLAUDE.md file. Many engineers code with frequent use of # to document commands, documents, and style guides, and to CLAUDE.md The changes are included in the commit so that team members can benefit as well.

exist Anthropic Internally, sometimes the prompt improver to optimize CLAUDE.md document and adjust the wording of the instructions (e.g., use "IMPORTANT" or "YOU MUST" for emphasis) to improve model compliance.

Mastering Claude Code: A Practical Guide to Improving AI Programming Efficiency-1

c. Management Claude The list of tools licensed by the

By default, theClaude Code Permission is requested for any operation that may modify your system: writing to files, executing many bash commands, using the MCP tools, etc. This conservative design prioritizes security. You can customize the allowlist to allow tools that you are confident are safe, or to allow potentially unsafe actions that can be easily undone (e.g. file editing.)git commit).

There are four ways to manage the license tool:

  • Select when prompted in a session "Always allow"The
  • activate (a plan) Claude Code after use /allowed-tools command Add or remove tools from the license list. For example, adding Edit Allow to always edit the file, add Bash(git commit:*) executable git commitor add mcp__puppeteer__puppeteer_navigate license Puppeteer MCP server for navigation.
  • Manual editing under the item .claude/settings.json (which is recommended to be included in version control to be shared with the team) or in the user's home directory under the ~/.claude.jsonThe
  • utilization --allowedTools command-line flag (computing) Set permissions for a specific session.

d. If using GitHubInstallation gh command-line tool

Claude Know how to use gh Command Line Tools vs. GitHub interactions for creating issues, launching pull requests, reading comments, etc. If you don't have ghAs soon as you install the GitHub API or the corresponding MCP server.Claude can still interact in these ways.

2. To Claude Provision of additional tools

Claude With access to your shell environment, you can script it like you would script yourself, with a handy set of scripts and functions. It can also utilize more sophisticated tools through the MCP and REST APIs.

a. Let Claude Using the bash utility

Claude Code inherits your bash environment and therefore has access to all your tools. Although Claude understand sth. like unix tools and gh It can't automatically know about your customized bash utility, you need to tell it:

  1. telling Claude The name of the tool and examples of its usage.
  2. have sb do sth Claude (of a computer) run --help View the tool documentation.
  3. Record commonly used customization tools in the CLAUDE.md Center.

b. Let Claude Using MCP

MCP, the Model Context Protocol (Model Context Protocol), a specification that allows language models to interact with external tools and services.Claude Code It can be used either as an MCP server or as an MCP client. As a client, it can connect to any number of MCP servers to access their tools in three ways:

  • In Project Configuration(Run it in the project directory) Claude Code (when available).
  • In the global configuration(available in all projects).
  • warehouse .mcp.json file(available to all who use the codebase). For example, you can set the Puppeteer cap (a poem) Sentry The server is added to the .mcp.json This is so that every engineer on the team can use these tools right out of the box.

When using the MCP, the MCP can be configured via the --mcp-debug Flag activation Claude Helps diagnose configuration problems.

c. Use of customized slash commands

For repetitive workflows - such as debugging loops, log analysis, etc. - prompt templates can be stored in the .claude/commands folder in the Markdown file. When you type / When you do, these templates appear in the slash command menu. You can submit these commands to the git, for use by the rest of the team.

Custom slash commands can contain special keywords $ARGUMENTS, which is used to pass parameters attached to the invoked command.

For example, here's one that can be automatically pulled and repaired GitHub issue slash command:

请分析并修复 GitHub issue: $ARGUMENTS。
请遵循以下步骤:
1. 使用 `gh issue view` 获取 issue 详细信息
2. 理解 issue 中描述的问题
3. 在代码库中搜索相关文件
4. 实现必要的代码更改以修复问题
5. 编写并运行测试以验证修复
6. 确保代码通过 linting 和类型检查
7. 创建描述性的 commit 消息
8. 推送代码并创建 PR
记住,所有与 GitHub 相关的任务都使用 GitHub CLI (`gh`)。

Save the above to .claude/commands/fix-github-issue.md After the file Claude Code hit the nail on the head /project:fix-github-issue command uses it now. For example, running /project:fix-github-issue 1234 would have allowed Claude to fix issue number 1234. similarly, you can add commands that you personally use to the ~/.claude/commands folder to make it available for all sessions.

3. Experimenting with common workflows

Claude Code Not imposing a specific workflow gives you the flexibility to use it on demand. With this flexibility, a number of proven models have emerged from the user community:

a. Explore, plan, code, submit

This is a generalized process that applies to a wide range of issues:

  1. have sb do sth Claude Read related documents, images or URLs. It can be given broad instructions ("read the file that handles logging") or specific filenames ("read logging.py"), but explicitly told not to write any code for the time being.
    • In this step, especially for complex problems, consider letting the Claude Use subagents to validate details or to investigate specific problems it may encounter. Doing this early in the dialog or task often preserves the usability of the context without sacrificing too much efficiency.
  2. have sb do sth Claude Developing plans to address specific issues. It is recommended to use the word "think" to trigger the extended thinking mode, which will give the Claude Additional computation time to more fully evaluate alternatives. The system has built-in mapping of thinking budgets at different levels: "think" < "think hard" < "think harder" < "ultrathink". Each level allocates more thinking budget for Claude Use.
    • If the results of this step seem reasonable, you can let the Claude Write the plan to a document or create GitHub issue, so that if the subsequent implementation (step 3) does not meet expectations, you can fall back to this state.
  3. have sb do sth Claude Write code to realize their programs. This is also a good time to ask it to explicitly validate the rationality of the various parts of the program as it is realized.
  4. have sb do sth Claude Submit results and create a pull request.. If relevant, it is also possible to make Claude update README maybe changelog, explaining what it just did.

Steps #1 and #2 are critical - without them, theClaude Often, you will jump straight to the coding stage. While sometimes that's exactly what you want, for problems that require more in-depth thinking, it's important to first let the Claude Conducting research and planning can significantly improve the end result.

b. Write tests, submit; code, iterate, submit

this is Anthropic A highly respected workflow internally, especially for changes that can be easily verified through unit, integration, or end-to-end testing. Test-driven development (TDD) is made even more powerful with agent-based coding:

  1. have sb do sth Claude Write tests based on expected input/output pairs. Explicitly communicate that test-driven development is taking place so that it avoids creating mock implementations, even if the functionality doesn't exist yet.
  2. telling Claude Run the tests and confirm that they fail. It is often helpful to explicitly instruct it not to write any implementation code at this stage.
  3. When you are satisfied with the test.have sb do sth Claude Submit Test CodeThe
  4. have sb do sth Claude Write code that passes tests, and instructs it not to modify the test itself. Tell Claude Keep trying until all tests pass. It usually takes several iterations (write code, run tests, tweak code, run tests again).
    • At this stage, it can be required to use an independent sub-agent to verify that the implementation is not overfitting the test cases.
  5. When you are satisfied with the code changeshave sb do sth Claude Submit CodeThe

(coll.) fail (a student) Claude It performs best when there is a clear goal that can be iterated on - like a visual model, a test case, or some other form of expected output. By providing an expected output like a testClaude Changes can be made, results evaluated, and incremental improvements can be made until they are successful.

c. Writing code, comparing screenshots, iterating

Similarly to test workflows, you can also create a test workflow for the Claude Provide visual targets:

  1. for the benefit of Claude A way to capture browser screenshots(For example, using Puppeteer MCP server,iOS simulator MCP server, or manually copy and paste the screenshot to Claude).
  2. for the benefit of Claude A visual design draftYou can do this by copying and pasting, dragging and dropping the image, or providing the path to the image file.
  3. have sb do sth Claude Implementing the design in code, intercept the resulting graph and iterate until the result matches the design.
  4. When you're satisfied.have sb do sth Claude Submit CodeThe

Like humans.Claude s output usually improves significantly after iterations. The first version may be okay, but after 2-3 iterations it usually looks much better. To Claude Providing tools to view its output gives the best results.

Mastering Claude Code: A Practical Guide to Improving AI Programming Efficiency-1

d. Security YOLO mode

If you don't want to supervise the whole thing ClaudeYou can use the claude --dangerously-skip-permissions parameter to bypass all permission checks and let the Claude Work uninterruptedly until completion. This mode is well suited for performing workflows such as fixing lint bugs or generating sample code.

warnings: Let Claude Running arbitrary commands without validation is risky and can lead to data loss, system corruption, or even data leakage (e.g., via a prompt injection attack). To minimize these risks, it is highly recommended that containers without Internet access use the --dangerously-skip-permissions. You can refer to Claude Code provided in the repository based on the Docker Dev Containers reference implementationThe

e. Codebase Questions and Answers (Q&A)

When approaching a new code base, you can use the Claude Code To learn and explore. You can learn as you would when pair programming with other engineers on the project from the Claude Question.Claude Ability to agentically search the code base to answer general questions, for example:

  • How does the logging system work?
  • How do I create a new API endpoint?
  • foo.rs Line 134 of the document async move { ... } What does it do?
  • CustomerOnboardingFlowImpl What border situations have been addressed?
  • Why is the call to foo() rather than bar()?
  • baz.py The code at line 334 of the file is in the Java What is the counterpart in

exist AnthropicThe use of the Claude Code The onboarding process, which has become core, significantly reduces the familiarization time for new team members and eases the burden on other engineers. No special prompts are needed! Just ask the question.Claude would then explore the code to find the answer.

Mastering Claude Code: A Practical Guide to Improving AI Programming Efficiency-1

f. Let Claude together with git each other

Claude Can effectively handle many git Operation. Many Anthropic Engineers will 90% above git hand over to Claude Processing:

  • look for sth. git histories to answer questions such as "What changes are included in v1.2.3?" , "Who is responsible for which feature?" or "Why is this API designed this way?" and so on. Clear Tips Claude refer to git Historical records help answer such questions.
  • Writing a commit messageTheClaude will automatically look at your code changes and recent history, synthesizing all relevant context to compose the message.
  • processing of complex git manipulateFor example, undoing file changes, resolving rebase conflicts, comparing and applying patches (patch grafting).

g. Let Claude together with GitHub each other

Claude Code It is possible to manage many GitHub Interaction:

  • Creating a pull request::Claude Understands the shorthand "pr" and will generate appropriate commit messages based on code differences (diffs) and surrounding context.
  • One-stop solution for simple code review comments: Simply tell it to fix the comment on the PR (which could be accompanied by more specific instructions) and push it back to the PR branch when it's done.
  • Fixing failed builds or linter warning.
  • Classification and triage Unprocessed issues: Let Claude Iterate through all open-state GitHub issue.

This eliminates the need for you to remember gh command's complex syntax while automating many routine tasks.

h. Let Claude deal with Jupyter notebook

Anthropic of researchers and data scientists using Claude Code to read and write Jupyter Notebook.Claude Being able to understand the output, including images, provides a shortcut for exploring and interacting with the data. There are no specific prompts or workflow requirements, but a recommended way to work with the VS Code Open side by side in Claude Code cap (a poem) .ipynb Documentation.

You can also make Claude Clean up or spruce up your before showing it to your coworkers Jupyter Notebook. explicitly telling it to make the notebook or its data visualizations "aesthetically pleasing" usually helps remind it that it's being optimized for the human reading experience.

4. Optimize your workflow

The following recommendations apply to all workflows:

a. Be specific in your instructions

Claude Code The success rate increases significantly when the instructions are more specific, especially on the first attempt. Giving clear directions at the outset reduces the cost of subsequent corrections.

Example:

Insufficiently specific instructions More specific instructions
Adding tests to foo.py because of foo.py Write a new test case that covers the boundary case when the user is not logged in. Avoid using mock.
for what reason? ExecutionFactory Is the API so strange? refer to ExecutionFactory (used form a nominal expression) git history to summarize how its API has evolved to date.
Add a calendar widget Check out the implementations of the existing widgets on the homepage to understand the patterns, especially how code and interfaces are separated.HotDogWidget.php is a good starting point. Then, follow this pattern to implement a new calendar widget that allows the user to select the month and can page forward/backward to select the year. Build from scratch and don't introduce new libraries other than those already used in the code base.

Claude Can infer intent, but it doesn't read minds. Specificity leads to better alignment of results.

Mastering Claude Code: A Practical Guide to Improving AI Programming Efficiency-1

b. To Claude Providing pictures

Claude Excellent at working with pictures and charts, there are multiple ways to provide visual information:

  • Paste Screenshot(On macOS.Cmd+Ctrl+Shift+4 You can take a screenshot to the clipboard, and then add it to the Claude Code end-use Ctrl+V Paste. Note that here is the Ctrl+V Instead of the usual Cmd+V(and does not support remote pasting).
  • drag-and-drop (computing) image file to the prompt input box.
  • Provide the local file path of the imageThe

This is especially useful when working with design drafts for UI development, performing analysis, and visualizing diagrams for debugging. Even if you don't provide visual input to the Claude It would also be helpful to explicitly state that the visual presentation of the end result is important.

Mastering Claude Code: A Practical Guide to Improving AI Programming Efficiency-1

c. Mention that you wish to Claude Documents viewed or processed

Use the Tab key auto-completion feature to quickly reference a file or folder anywhere in your repository, helping you to Claude Find or update the correct resource.

Mastering Claude Code: A Practical Guide to Improving AI Programming Efficiency-1

d. To Claude Provide URL

Paste the specific URL next to your prompt.Claude can crawl and read its content. In order to avoid the risk of crawling the same domain (e.g. docs.foo.com) to pop up permission requests repeatedly, you can use the /allowed-tools command adds the domain to your license list.

e. Early and frequent course corrections

Although the auto-acceptance mode (press Shift+Tab (switch) allows the Claude work autonomously, but usually as active collaborators and guiding the Claude method gives better results. In the beginning to the Claude Thoroughly explaining the task gives the best results, but you can always fix it! Claude Directions.

The following four tools can help with orientation corrections:

  • Before codingrequest Claude develop a plan. Tell it explicitly not to start coding until you've confirmed that the plan works.
  • exist Claude any stage of the process (thinking, tool invocation, document editing)check or refer to Escape key interruption, which will preserve the current context and allow you to redirect or extend commands.
  • double-click Escape key to go back in history, edit one of the previous hints and explore different directions. You can edit the hints over and over again until you get a satisfactory result.
  • request Claude Undo changesThe following is an example of a different approach, often used in conjunction with Option #2.

even though Claude Code Sometimes it's possible to solve the problem perfectly on the first try, but making good use of these correction tools usually produces a better solution faster.

f. Utilization /clear Maintaining Contextual Focus

In the course of a long session, theClaude context window can be filled with irrelevant dialogs, file contents, and commands. This can degrade performance and sometimes distract Claude of attention. Frequent use between tasks /clear command resets the context window.

g. Use of checklists and temporary record boards for complex workflows

For large tasks that contain multiple steps or require an exhaustive solution - such as code migration, fixing a large number of lint bugs, or running complex build scripts - you can make it easier by having the Claude Using Markdown files (even GitHub issue!) as checklists and scratchpads to improve performance:

For example, to fix a large number of lint problems, you can do this:

  1. telling Claude Run the lint commandand writes all resulting errors (including filenames and line numbers) to a Markdown manifest file.
  2. directives Claude Addressing each issue on a case-by-case basis, after fixing and verifying, mark the list as complete and move on to the next one.

h. To Claude pass on data

There are a number of ways to send a message to Claude Provide data:

  • Copy and paste directlyto your prompt (the most common method).
  • pass (a bill or inspection etc)The pipe is entered into the Claude Code(e.g. cat foo.txt | claude), which is especially useful for working with logs, CSV files, and large amounts of data.
  • telling Claude Pulling data via bash commands, MCP tools, or custom slash commandsThe
  • request Claude Read fileor grab the URL (also applies to images).

Most sessions will use a combination of these methods. For example, you can pass in a log file through a pipe and then tell the Claude Use one of the tools to pull additional context to debug these logs.

5. Automate Your Infrastructure with Headless Mode

Claude Code incorporates headless modeThe following are some of the most common uses of CI, for non-interactive environments such as CI (continuous integration), pre-commit hooks, build scripts, and automated tasks. Use the -p flag with a prompt to enable headless mode, use the --output-format stream-json You can get streaming JSON output.

Note that headless mode does not persist between sessions and needs to be triggered each time.

a. Utilization Claude Triage of issues

The headless mode can be driven by the GitHub Event-triggered automation, such as when a new issue is created in your repository. For example, the public Claude Code Warehouse utilization Claude to check for emerging issues and assign them appropriate labels.

b. Utilization Claude As a code review Linter

Claude Code available Subjective code reviewIt goes beyond the scope of traditional linting tools, recognizing problems such as misspellings, outdated comments, and misleading function or variable names.

6. Adoption of multiple Claude Workflow for Efficiency

In addition to using the separate ClaudeSome of the most powerful application scenarios involve running multiple Claude Example:

a. Let a Claude Write the code, the other Claude to verify

A simple but effective way to do this is to have a Claude instance is responsible for writing the code, while another instance is responsible for reviewing or testing it. This is similar to collaborating with multiple engineers, and sometimes separate contexts are beneficial:

  1. utilization Claude Write code.
  2. (of a computer) run /clear Or start a second one in another terminal Claude Example.
  3. Make the second one. Claude Review of the first Claude The work.
  4. Start another Claude(or again) /clear) to read code and review feedback.
  5. let this one Claude Edit the code based on feedback.

You can handle tests in a similar way: let a Claude Write the test and then have another Claude Write code to pass these tests. You can even do this by assigning them different working draft boards and instructing them which one to use for writing and which one to use for reading, the Claude Communication between instances.

This segregation of duties is usually more effective than having a single Claude Handling everything produces better results.

b. Use of multiple check-out copies of the code repository

Anthropic Many engineers use this approach to avoid waiting for Claude Complete each step:

  1. In different foldersCreate 3-4 git CheckoutThe
  2. In different terminal tabsOpen each folderThe
  3. In each folderactivate (a plan) Claude, assigning different tasks.
  4. Toggle by turnCheck progress and approve/deny permission requests.

c. Utilization git worktrees

This approach is particularly effective for handling multiple independent tasks and is a lighter-weight alternative to creating multiple copies of the full code base.Git worktrees Allows you to check out different branches of the same repository into different directories. Each worktree has its own separate working directory and files, but shares the same Git history and reflog, which saves disk space over full replication of the repository.

utilization git worktreesYou can run more than one of them at the same time. Claude sessions that deal with different parts of the project separately, with each session focusing on its separate task. For example, you might have a Claude reconfiguring the authentication system, while another Claude Build a completely unrelated data visualization component. Since the tasks do not overlap, each Claude Both can work at full speed without having to wait for each other to make changes or deal with merge conflicts:

  1. Creating a worktree::git worktree add ../project-feature-a feature-a
  2. Starts in every worktree Claude::cd ../project-feature-a && claude
  3. as requiredCreate more worktrees(Repeat steps 1-2 in a new terminal tab).

Some tips on how to use it:

  • Use consistent naming conventions.
  • Keep a terminal tab for each worktree.
  • If you are using iTerm2 on a Mac, you can Setting up notifications in order to Claude Get alerts when you need to pay attention.
  • Use separate IDE windows for different worktrees.
  • Clean up when you're done:git worktree remove ../project-feature-a

d. Use of headless mode in conjunction with customized scripts

claude -p(Headless Mode) allows you to set the Claude Code Integrate programmatically into larger workflows while taking advantage of its built-in tools and system prompts. There are two main modes of using Headless Mode:

  1. Fanning out: Handle large-scale migrations or analysis (e.g., analyzing the sentiment of hundreds of logs or analyzing thousands of CSV files):
    1. have sb do sth Claude Write a script to generate a task list. For example, generate a list of 2000 files that need to be migrated from Framework A to Framework B.
    2. Iterate through the list of tasks and for each task programmatically call the Claude, give it a task and a set of tools it can use. For example:claude -p “将 foo.py 从 React 迁移到 Vue。完成后,如果成功,你必须返回字符串 OK,如果任务失败,则返回 FAIL。” --allowedTools Edit Bash(git commit:*)
    3. Run the script multiple times and optimize your tips to get the desired results.
  2. Pipelining: Will Claude Integration into existing data/processing pipelines:
    1. invocations claude -p “<你的提示>” --json | your_commandwhich your_command is your next step in dealing with the pipeline.
    2. JSON output (optional) helps provide structured data for subsequent automated processing.

For both use cases, use the --verbose Flags help with debugging Claude The verbose mode is usually recommended to be turned off in production environments for more concise output. It is often recommended to turn off verbose mode in production environments for cleaner output.

Hopefully, these tips will help you be more efficient with the Claude Code. Keep exploring and experimenting to find the coding style that works best for you.

May not be reproduced without permission:Chief AI Sharing Circle " Getting to grips with Claude Code: a practical guide to boosting AI programming productivity
en_USEnglish