跳到正文
DEV Community· Jaideep Parashar·· 6 小時前AI 評分62

Claude Code 的 7 個實用技巧,讓 AI 輔助開發更有條理

7 Claude Tricks Every Developer Must Know to Write Better Code

AI 導讀

文章整理了 7 個 Claude Code 實用技巧,涵蓋 CLAUDE.md、Plan Mode、測試驗證、子智能體、/compact 與 /clear、MCP 整合及 hooks。作者指出,這些做法著重建立清晰上下文、控制工具權限和驗證結果,而非單純加快程式碼生成。這些技巧不能取代人工審查和工程判斷。

正文

Most developers know that Claude can write code.

It can explain Python functions.

Debug JavaScript.

Generate SQL queries.

Review APIs.

And help build applications.

But here's something I've been thinking about:

Are we using Claude as a coding assistant, or are we actually learning how to work with it as an engineering tool?

There's a difference.

Asking Claude to write a function is easy.

Getting it to understand your project, respect architectural decisions, investigate bugs, run tests, and work within clearly defined boundaries is another matter.

And that's where things become interesting.

Today, I want to share seven practical Claude tricks that developers should explore, particularly if they're using Claude Code, Anthropic's coding agent.

These aren't magic prompts.

They're ways to make AI-assisted development more structured, reliable, and useful.

1. Stop Explaining Your Project Every Time. Use CLAUDE.md.

Imagine opening Claude Code and repeatedly explaining the same things.

"We use TypeScript."

"Don't add unnecessary dependencies."

"Run the tests before finishing."

"Follow our existing API conventions."

"Don't modify the database migrations."

If you're repeating these instructions across sessions, there's a better approach.

Claude Code supports a project instruction file called CLAUDE.md.

You can create one manually or generate a starting version using: /init

Then refine the file with the information Claude genuinely needs.

For example:

Project Instructions

Stack

  • TypeScript
  • Node.js
  • PostgreSQL

Development Rules

  • Follow existing project conventions.
  • Prefer simple solutions.
  • Avoid unnecessary dependencies.
  • Do not modify database migrations without explicit approval.

Verification

  • Run npm test.
  • Run npm run lint.
  • Report any failing checks.

The benefit isn't simply convenience.

You're making important project context reusable.

But there's a catch.

Don't turn CLAUDE.md into a 50-page instruction manual.

Keep it focused on conventions, commands, and decisions that aren't obvious from the codebase.

And remember: project instructions guide the model; they don't enforce hard security boundaries.

For sensitive actions, use actual permissions and controls.

My takeaway: If you have to explain something repeatedly, it probably belongs in a reusable project instruction.

2. Use Plan Mode Before Claude Touches Your Code

Here's a mistake I think developers should avoid.

You ask an AI coding assistant to implement a feature.

It immediately begins editing files.

A few minutes later, you discover it misunderstood the requirement.

Now you're reviewing changes you never wanted.

Claude Code has a useful feature called Plan Mode.

You can start a session in Plan Mode with:

claude --permission-mode plan

Or switch modes during an interactive session until Plan Mode is active.

In this mode, Claude can inspect the project and propose an approach without directly editing your source files.

Try something like:

I want to add rate limiting to this API.
Before implementing anything:

  1. Inspect the existing architecture.
  2. Identify where rate limiting belongs.
  3. Compare two possible approaches.
  4. Identify security and performance risks.
  5. List the files that would need changes.
  6. Propose a minimal implementation plan. Do not modify any files yet.

This changes the conversation.

Instead of immediately discussing code, you're discussing engineering decisions.

You can challenge the plan.

Remove unnecessary complexity.

Clarify requirements.

Then authorize the implementation.

I particularly like this approach for changes involving authentication, databases, APIs, and existing production systems.

My takeaway: Sometimes the best thing AI can do before writing code is help you decide what code should exist.

3. Give Claude a Test, Not Just a Task

Most developers ask AI to complete a task.

"Fix this function."

"Build this endpoint."

"Add this feature."

But how will Claude know the work is actually finished?

A function that looks correct isn't necessarily correct.

An endpoint that returns HTTP 200 isn't necessarily behaving as intended.

A successful build doesn't guarantee the feature works.

So here's a more useful technique.

Give Claude a way to verify its work.

For example:

The login endpoint fails when a session expires during token refresh.

Investigate the relevant code.

  1. Reproduce the problem with a failing test.
  2. Identify the root cause.
  3. Make the smallest reasonable fix.
  4. Run the relevant tests.
  5. Check for regressions.
  6. Summarize the changes and test results. Do not claim the issue is fixed unless the verification succeeds.

That's a much stronger request than:

"Fix my authentication bug."

Claude Code can run available test commands when permitted and inspect their results.

That doesn't eliminate the need for human review.

But it gives the development process a feedback loop.

And feedback loops are critical.

I've explored a related problem in Most Developers Test Their Code. Why Don't They Test Their AI?.

My takeaway: Don't ask AI to produce a solution without defining how the solution will be checked.

4. Use Subagents to Investigate Problems Without Filling Your Main Conversation

Here's something developers working on larger projects should know.

When an AI assistant explores a large codebase, it may read numerous files, search through logs, and investigate multiple components.

That information consumes context.

And not all of it needs to remain in your main conversation.

Claude Code supports subagents that can perform focused tasks in separate context windows.

For example:

Use a subagent to investigate how authentication and token refresh work
in this codebase.
Identify:

  • Important files.
  • Main execution flow.
  • Failure handling.
  • Potential inconsistencies. Return a concise summary with file references. Do not modify the code. The subagent can investigate and return its findings without dumping every intermediate detail into the main conversation.

You can use the same approach for code review, debugging research, or exploring unfamiliar parts of an application.

However, subagents aren't free performance boosters.

They may consume additional usage and can still make mistakes.

And there's little reason to delegate a trivial task that could be answered immediately.

My takeaway: Use subagents when separating the work improves clarity, not simply because running multiple agents sounds impressive.

7 Claude Tricks Every Developers Must Know

5. Learn When to Use /compact and /clear

Have you ever worked through a long AI conversation where the assistant gradually became less focused?

You've discussed one bug.

Then another feature.

Then a database migration.

Then an architecture question.

Eventually, the conversation contains so much information that you can barely remember what the original task was.

Claude Code provides tools for managing that context.

Use:

/compact

to summarize the conversation and reduce its context usage.

You can also specify what should be preserved:

/compact keep the current architecture
decisions, changed files, and test results

And when you're moving to an unrelated task:

/clear

starts a fresh conversation.

These commands serve different purposes.

/compact helps preserve useful continuity while summarizing older material.
/clear removes conversation history from the new task.

Compaction isn't perfect, of course. A summary may omit details you later need.

For important decisions, keep the source of truth in your project files, specifications, or tests rather than relying entirely on conversation memory.

My takeaway: Managing context is part of managing an AI development workflow.

6. Connect Claude to the Tools Your Workflow Actually Needs

One of the more useful developments in AI-assisted programming is the ability to connect models to external tools.

Claude Code supports integrations through the Model Context Protocol (MCP).

Depending on the integrations you configure, these can help Claude access relevant development resources such as issue trackers, documentation, and other services.

For example, imagine debugging an issue.

Your normal workflow might involve:

Opening a ticket.

Reading the acceptance criteria.

Searching the repository.

Reviewing relevant documentation.

Checking logs.

Then investigating the problem.

With a carefully configured tool integration, Claude may be able to access some of that information within the same workflow.

That's much more useful than copying and pasting disconnected snippets into a chat.

You can inspect MCP connection status in Claude Code using: /mcp

But here's an important warning.

More tool access is not automatically better.

Only connect trusted servers.

Review the permissions you're granting.

Avoid exposing secrets or unnecessary production data.

Treat external tool responses as potentially untrusted input.

And require explicit approval for sensitive or destructive actions.

The objective isn't to give an AI agent unrestricted access to everything.

It's to provide the smallest useful set of capabilities for the task.

My takeaway: Better AI workflows often require better connections, but those connections need boundaries.

7. Automate Your Development Rules With Hooks

This might be one of the most useful tricks for developers working repeatedly with Claude Code.

Suppose you always want a formatter to run after Claude edits source files.

You can write:

"Remember to run the formatter."

But what happens if the instruction is overlooked?

What if the conversation becomes long?

What if another developer uses the same repository?

Claude Code supports hooks that can trigger configured actions at specific points in its workflow.

For example, a PostToolUse hook can run a formatting command after an appropriate file edit.

You can inspect and configure hooks through: /hooks

The important idea is that the formatter is executed through a configured mechanism rather than relying entirely on a conversational instruction.

This distinction matters.

There are rules we want AI to consider.

And there are checks we want the development environment to enforce.

They're not necessarily the same thing.

Examples of useful automated checks include formatting, linting, and selected validation steps.

For more sensitive controls, combine hooks with appropriate permission rules, sandboxing, and normal repository protections.

Hooks can execute commands, so their configuration deserves careful review.

My takeaway: If a check must happen consistently, don't rely solely on the model remembering to do it.

The Bigger Lesson: Claude Isn't Your Engineering Process

After looking at these seven capabilities, I think an important pattern emerges.

None of the most valuable techniques are simply about generating more code.

They're about improving the development process.

CLAUDE.md provides project context.

Plan Mode encourages better decisions.

Tests provide verification.

Subagents help organize investigation.

Context management improves focus.

MCP provides controlled access to useful tools.

Hooks help automate repeatable checks.

Together, these capabilities can make AI-assisted engineering more structured.

But they're not a substitute for engineering judgment.

A bad requirement can still produce a bad implementation.

An incorrect architectural assumption can still cause problems.

Tests can still miss important cases.

And an AI-generated fix can still introduce regressions.

That's why I increasingly believe the developer's job is not just to tell AI what to build, but to design the conditions under which its work can be trusted.

Don't Measure AI Development Only by Speed

Imagine two developers using Claude.

Developer A generates a feature in 10 minutes.

Developer B takes 30 minutes to clarify the requirement, review the architecture, implement the feature, and run verification.

Who is more productive?

We can't answer that from the time taken alone.

What if Developer A's feature introduces a production bug?

What if Developer B's implementation is easier to maintain?

What if both implementations are equally good?

We need to measure the outcomes, not simply the speed of code generation.

This is a principle I also emphasize in my work at ReThynk AI: AI evaluation should consider the quality, reliability, and value of the complete workflow, not merely whether the underlying model produced an output.

For teams looking beyond individual coding tricks, our AI Evaluation Framework: 7 Critical Metrics for AI Success explores how to think more systematically about assessing AI performance.

Because the goal isn't to make developers type fewer characters.

The goal is to help them build better software.

Frequently Asked Questions

  • What's the difference between Claude and Claude Code?

Claude is Anthropic's AI assistant, which can help with programming questions, code explanations, and other tasks through a conversational interface.

Claude Code is designed for development workflows and can interact with project files, execute supported commands, and use development tools with configured permissions.

Several techniques in this article, such as CLAUDE.md, Plan Mode, and hooks, specifically refer to Claude Code.

  • Which Claude trick should a beginner try first?

I would start with Plan Mode.

Before asking Claude to build something, ask it to examine your requirements, identify assumptions, and propose a simple implementation plan.

Then add a clear way to verify the result.

You don't need complicated agent architectures to benefit from structured AI-assisted development.

  • Can Claude Code replace human code review?

I wouldn't treat it as a complete replacement.

Claude can help identify suspicious logic, missing tests, and potential maintainability issues.

But it may misunderstand requirements, overlook vulnerabilities, or recommend unnecessary changes.

Human review and appropriate automated testing remain essential, especially for security-sensitive and high-impact systems.

Final Thoughts

I think we're entering an interesting stage of software development.

Knowing how to ask AI to write a function is becoming commonplace.

The bigger opportunity is learning how to make AI useful across the entire engineering workflow.

Not by adding as many tools and agents as possible.

But by creating better context, clearer boundaries, stronger verification, and simpler processes.

The best Claude trick isn't a secret command.

It's knowing how to turn AI assistance into a reliable engineering practice.

And that's a skill worth developing.

來源:DEV Community · dev.to