pub.towardsai.net 9 min read Original Source

Stop Using Claude Code Like a Chatbot. Use These 12 Patterns Instead

From plan mode and CLAUDE.md to hooks, subagents, and Git worktrees, these 12 patterns can make Claude Code faster, safer, and far more predictable.

READ HERE FOR FREE:- FRIENDS LINK

For my first few weeks with Claude Code, I treated it like a smarter chat window. I typed a vague request, watched it edit a dozen files, and then spent twenty minutes undoing what I never asked for. The tool was fine. My habits were wrong.

That experience taught me something I wish I had understood earlier: giving Claude Code more freedom does not automatically produce better code. It needs the right boundaries, enough context to understand the task, and a clear way to prove that its changes work.

Take a simple example: you ask it to add pagination to an API. A rushed session might change the endpoint, the database query, and several tests before you notice that the response format has changed too. A better workflow starts by locating the relevant code, agreeing on a plan, and defining what a successful result looks like.

That is what the patterns below are meant to solve. Rather than treating each feature as another trick to memorize, think of them as parts of a workflow: understand the task, limit unnecessary changes, verify the result, and keep control when something goes wrong.

What Is the Difference Between Chatting With Claude Code and Using It Properly?

The difference becomes clear when a task touches several parts of a codebase. A chatbot-style request leaves too many decisions open: which files to change, what to leave alone, and how to check the result.

A better workflow answers those questions before the edits begin. Plan mode helps with exploration, CLAUDE.md provides project-specific rules, hooks automate repeatable checks, and tests reveal whether the changes actually work.

The patterns below are grouped around those problems, with examples of when each one helps.

That is the shift. Here are the 12 patterns, grouped by what they fix.

Part 1: Stop It From Acting Before It Understands

Pattern 1: Start in Plan Mode

Plan mode lets you ask Claude Code to explore the codebase and propose a plan before making changes. It is a mode you switch into, not just a word you add to your prompt. Depending on your setup and version, you can enter it using the plan-mode control or the relevant command. While in plan mode, Claude investigates the task and prepares an approach for you to review before implementation begins.

Here’s the workflow:

  1. Switch to plan mode and ask Claude to inspect the relevant code without implementing the change.
  2. Ask it to write an implementation plan.
  3. Read the plan and correct it.
  4. Switch back to normal mode and let it implement against the approved plan.

For example: if you are adding pagination to an API, ask Claude to trace the endpoint, the database query, and the tests before it edits anything. Its plan should identify which files need to change and how the existing response format will be preserved. If it proposes rewriting unrelated modules, correct the plan first.

I now skip planning only when I could describe the diff in one sentence. Everything else starts here.

Pattern 2: Write a CLAUDE.md that Earns its Place

CLAUDE.md is a file Claude reads at the start of every conversation. The mistake is stuffing it with things Claude already knows. The useful content is bash commands Claude can’t guess, code style rules that differ from defaults, and non-obvious gotchas. Self-evident advice like “write clean code” belongs nowhere near it.

A good CLAUDE.md is short. It lists your build and test commands, your unusual conventions, and the traps that have bitten you before. If a line would not change Claude’s behavior, delete it.

For example, imagine this is your project’s CLAUDE.md file:

# Project Rules

## Tests
- Run API tests with: pytest tests/api/
- Run all tests with: pytest
## Database
- Create a migration for every database schema change.
- Never edit existing migrations.
## API Responses
- Keep existing response field names unchanged.
- Add tests when changing an endpoint.
# Project Rules

## Tests
- Run API tests with: pytest tests/api/
- Run all tests with: pytest
## Database
- Create a migration for every database schema change.
- Never edit existing migrations.
## API Responses
- Keep existing response field names unchanged.
- Add tests when changing an endpoint.

Now Claude has specific instructions it can follow instead of guessing. If you ask it to change an API endpoint, it knows which test command to run, how to handle database changes, and which response fields must stay the same.

Your own file should reflect your project’s real commands and conventions. Don’t copy these rules blindly if they don’t match your setup.

Pattern 3: Give Precise Instructions, With File References

Claude can infer intent, but it cannot read your mind. Compare these two prompts:

  • Weak: “Fix the login bug.”
  • Strong: “Login fails when the email has uppercase letters. Check auth/session.ts and the matching test file. Reproduce it with a failing test first, then fix it.”

The second prompt names the symptom, the files, and the order of work. It costs you ten extra seconds and saves a round of corrections.

Part 2: Make It Remember and Enforce Your Rules

Pattern 4: Use Hooks for Anything That Must Happen Every Time

Unlike CLAUDE.md instructions, hooks can automate specific actions at defined points in a workflow. When configured correctly, they are more reliable than asking Claude to remember an instruction, though you should still handle failures and verify the results. Claude can even help you write hooks.

For example, a Claude Code hook is a script that runs automatically when a configured event occurs. You can use one to run a formatter after Claude edits a file or trigger a check before a tool runs.

Here is a simple example of a hook configuration:

{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Edit|Write",
        "hooks": [
          {
            "type": "command",
            "command": "npm run format"
          }
        ]
      }
    ]
  }
}
{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Edit|Write",
        "hooks": [
          {
            "type": "command",
            "command": "npm run format"
          }
        ]
      }
    ]
  }
}

In this example, the hook runs npm run format after a matching edit or write tool use. It assumes your project has that script configured. A hook is not just an instruction asking Claude to format its code; it is a configured action that runs automatically when its event and matcher conditions are met.

Hooks can also fail, so check the command’s output and confirm the formatting worked. Before using a hook in your own project, follow the current Claude Code documentation and adapt the configuration to your setup.

Pattern 5: Turn Repeated Prompts Into Skills and Commands

If you paste the same instructions every week, you are doing manual work a file can do. Reusable workflows live in .claude/skills/<name>/SKILL.md or .claude/commands/<name>.md. A “fix issue” skill, an “API conventions” skill, and a “write release notes” command are all realistic examples.

My rule of thumb is simple. CLAUDE.md holds facts that always apply. Skills hold procedures that apply sometimes.

For example, here’s how to create a simple Skill

Suppose you often ask Claude Code to review Python code. Instead of repeating the same instructions, create a Skill for that task.

  1. Create a folder at .claude/skills/python-review/.
  2. Inside it, create a file named SKILL.md.
  3. Add the following content:

---
name: python-review
description: Review Python code for bugs, readability, and missing tests.
---

# Python Code Review

When reviewing Python code:
- Look for bugs and edge cases.
- Check readability and naming.
- Identify missing tests.
- Suggest focused improvements.
- Explain findings with file references.
- Do not modify files unless asked.
---
name: python-review
description: Review Python code for bugs, readability, and missing tests.
---

# Python Code Review

When reviewing Python code:
- Look for bugs and edge cases.
- Check readability and naming.
- Identify missing tests.
- Suggest focused improvements.
- Explain findings with file references.
- Do not modify files unless asked.
  1. Save the file. Claude Code can use the Skill when its description matches the task, depending on your setup and how Skills are invoked.

Keep a Skill focused on one reusable workflow. Include the steps, checks, and output format you want Claude to follow. Avoid putting secrets, unrelated project rules, or instructions that belong in CLAUDE.md inside it.

For more details, see the official Claude Code Skills documentation.

Pattern 6: Use Subagents for Research So Your Main Session Stays Clean

Investigation is context hungry. Reading forty files to answer one question can drown the main conversation. Subagents defined in .claude/agents/<name>.md run in their own context and return a summary.

Use them for code search, security review, and test analysis. Your main session keeps only the conclusion, not the forty files.

For example:- before changing an authentication flow, you could ask a subagent to trace how sessions are created and another to inspect the existing tests. Have them report the relevant files, potential risks, and missing test coverage. Then use those findings in the main session instead of loading every investigation detail into one conversation.

The goal is not to create a subagent for every small task. It is to delegate work when the investigation is large enough to justify the extra coordination.

For setup instructions, see the official Claude Code subagents documentation.

Part 3: Keep Sessions Sharp

Pattern 7: One Task Per Session, and Clear Often

Long sessions rot. Old debugging detours, abandoned approaches, and stale assumptions all sit in context and quietly steer Claude wrong.

  • Use /clear when you switch tasks.
  • Use /compact when the task is the same but the history is heavy.
  • Start a fresh session when Claude repeats an error you already corrected twice.

Clearing feels wasteful. It is the opposite.

Pattern 8: Always Give Claude a Way to Verify Its Work

Claude performs far better when it can check itself. Include the test command, the expected output, or the screenshot to match. “Make the tests pass” beats “fix this function” because success is now observable.

For anything without tests, ask Claude to write one first. A failing test is the clearest specification you can give.

For the pagination example, verification should cover more than whether the endpoint returns a response. Check that the requested page size is respected, the next page contains different records, an empty page is handled correctly, and existing response fields remain unchanged. Ask Claude to run the relevant tests and show the results. A successful edit is not the same as a verified fix.

Part 4: Trust It, But Keep an Exit

Pattern 9: Commit Small and Rewind Freely

Before letting Claude attempt a risky refactor, check git status and commit or otherwise preserve your existing work. After the change, inspect git diff before accepting it. If Claude changes files outside the task, you can identify the unexpected edits instead of discovering them after several more steps.

Treat git as your undo button and commit after every working step. Claude Code also keeps checkpoints you can rewind to, so a bad direction costs seconds instead of an afternoon.

This changes how you prompt. When undoing is cheap, you can let Claude try bolder approaches.

Pattern 10: Set Permissions Deliberately

Clicking approve on every command trains you to stop reading them. Allowlist the safe, repetitive commands like your test runner and linter, and keep prompts for anything destructive. Pair this with hooks that guard sensitive files.

Once a plan is approved, cycling to accept edits mode with Shift+Tab lets the agent work without a prompt on every step, and a solid plan means less backtracking. That is the right order. Plan first, then loosen permissions.

Consider the difference between running a test command and deleting a directory. Both are terminal operations, but the consequences are not the same. Give routine commands only the permissions they need, review unfamiliar commands before approving them, and keep destructive actions behind stronger checks. A good plan reduces uncertainty; it does not remove the need to review permissions.

Part 5: Scale Beyond One Terminal

Pattern 11: Run Claude Code Headless in Scripts and CI

Headless mode with the -p flag turns Claude Code into a non interactive CLI tool for automation pipelines. That means you can pipe in a diff, ask for a review, or generate a changelog from a script, and the same CLAUDE.md rules apply.

Start small. A pre push review script is a great first project.

Pattern 12: Run Parallel Sessions With Git Worktrees

Once your plans are good, the bottleneck becomes waiting. Create separate worktrees with git worktree add, open one Claude Code session per worktree, and run independent tasks side by side. Each session gets its own files and its own clean context.

Keep the tasks truly independent. Two sessions editing the same module is how you invent merge conflicts.

The 12 Patterns at a Glance

Which Pattern Should You Adopt First?

Do not adopt all twelve this week. Start with patterns 1, 2, and 8. Plan mode, a lean CLAUDE.md, and a way to verify results will fix most of the frustration. Add hooks and subagents once those feel natural.

Frequently Asked Questions

What is the best way to use Claude Code?

Explore in plan mode, review the plan, then implement against it with a way to verify the result. Keep each session focused on one task and clear it between tasks.

What should go in a CLAUDE.md file?

Include build and test commands, code style rules that differ from defaults, and non obvious gotchas. Leave out anything Claude can learn by reading your code.

What is the difference between CLAUDE.md and hooks?

CLAUDE.md instructions are advisory, so Claude may skip them. Hooks are scripts that run automatically at set points, so the action always happens.

When should I use a subagent?

Use one when a task needs heavy reading, such as code search or review, and you only want the conclusion in your main session.

Can I run Claude Code in CI?

Yes. Headless mode with the -p flag runs Claude Code non interactively, which suits scripts and automated review.

Build a Workflow, Not Just a Prompt

The biggest improvement in Claude Code does not come from finding one magic command. It comes from building a workflow in which each step has a purpose.

Plan before complex changes. Keep project rules short and specific. Use hooks for repeatable checks, delegate heavy investigations when needed, and verify the code before trusting the result. Keep Git available as a recovery path, especially when a task touches multiple files.

You do not need all twelve patterns on day one. Start with plan mode, a focused CLAUDE.md, and a reliable verification step. Once those become habits, add the other patterns where they solve a real problem.

The goal is not to make Claude write more code. It is to spend less time correcting code you never wanted in the first place.

Which Claude Code pattern has made the biggest difference in your workflow? Share it in the comments.