AI-Powered Development with Claude Code: Workflow Guide
Posted: April 16, 2026 to Technology.
You have Claude Code installed. You have run a few tasks. Now you want to know how teams actually use it to ship software faster without creating technical debt or burning through API credits. This is that guide.
This is not a feature reference. If you want the full breakdown of installation, model options, hooks, MCP servers, and worktrees, read the Claude Code CLI feature guide. This guide assumes you have the basics working and focuses on patterns: how to structure your sessions, when to dispatch subagents, how to manage cost without sacrificing throughput, and what to avoid.
At Petronella Technology Group, we use Claude Code across engineering, cybersecurity, and content operations. These patterns come from real production use, not theory.
The Mental Model Shift
The developers who get the most out of Claude Code are the ones who stop treating it as an autocomplete engine and start treating it as an autonomous teammate with specific strengths and failure modes.
The chatbot mental model leads to this pattern: ask Claude to write a function, paste it in, fix the linter error, ask Claude to fix it, paste it again. That flow is low-value because you are the bottleneck. Every roundtrip costs you attention and time.
The autonomous teammate model looks different. You give Claude Code a goal, a scope boundary, and the permission to run commands. You come back when it is done or when it surfaces a decision it cannot make alone. For well-scoped tasks, this means Claude Code is running for 5-15 minutes while you are doing something else.
The question to ask before starting any task is: can I fully specify what done looks like? If yes, let Claude Code run autonomously. If not, use plan mode first to surface the ambiguity before any code gets written.
When to pair interactively:
- Architecture decisions where trade-offs depend on context Claude cannot infer
- Tasks that touch production infrastructure where mistakes are expensive
- Anything where the definition of done is genuinely unclear
When to let it run unattended:
- Writing and running tests for a function you just specified
- Refactoring a module to match a new interface you defined
- Generating documentation from existing code
- Fixing a class of lint error across the codebase
- Researching a library and producing a summary with code examples
Workflow 1: TDD with Subagent Verification
Test-driven development maps well to Claude Code's subagent model because you can separate writing tests, implementing code, and reviewing the result into three discrete tasks that do not share conversational state.
The pattern:
- Main session: Describe the function contract in plain English. Ask Claude Code to write the tests first, without implementing the function. Review the tests before moving on.
- Implementer subagent: Spawn a subagent whose only job is to make the tests pass. Give it the test file path and the spec. Do not give it the implementation approach.
- Reviewer subagent: After tests pass, spawn a second subagent with the diff. Ask it to check for correctness, edge cases the tests missed, and any subtle issues the implementer introduced.
Why subagents instead of continuing in the main session? Each subagent starts fresh, without the accumulated context bias of the implementation conversation. The reviewer subagent will catch things the implementer glossed over precisely because it was not involved in writing the code.
Practical prompt for the reviewer subagent:
Review this diff. The goal was to implement [function name] per the spec in [test file].
Do not re-implement anything. Report:
1. Any test cases the tests do not cover that they should
2. Any correctness issues in the implementation
3. Any performance problems for inputs at scale
4. Anything that will cause a maintenance problem in 6 months
Do not praise the code. Only report problems.
The explicit "do not praise" instruction removes the LLM tendency toward affirmation that obscures real feedback.
Workflow 2: Debugging at Speed
Debugging is where plan mode pays off most. The failure mode without it: Claude Code starts modifying code immediately based on the first plausible hypothesis, you get a diff that may or may not fix the issue, and you lose visibility into why.
The better pattern is a two-phase approach:
Phase 1 - Diagnosis (plan mode):
claude --plan
Describe the bug: what you expected, what actually happened, any error output or stack trace. Ask Claude Code to produce a diagnosis before touching any code. Plan mode forces it to lay out its hypothesis, which files it will read, and what it expects to find. You read this plan and either approve it or correct the hypothesis before a single file is modified.
Phase 2 - Implementation and verification:
Once you have agreed on the diagnosis, exit plan mode and let Claude Code implement the fix. Ask it to also write a regression test that would have caught the bug. End the task with a verification step: run the test suite and confirm the specific failure case is now passing.
This pattern reduces the number of incorrect fixes you deploy because you catch bad hypotheses at the cheapest point, before any code changes. It also produces a regression test as a side effect, which makes the codebase incrementally safer on every debugging session.
Workflow 3: Large-Scale Refactors
Large refactors are where the worktree model becomes necessary rather than optional. If you refactor in your working tree and something goes wrong mid-way, you are in a partially modified state that is difficult to recover from cleanly.
The pattern for a refactor that touches more than 10 files:
- Create a worktree for the refactor branch:
git worktree add ../myproject-refactor-auth feature/auth-refactor - Map the scope first: In the main session, ask Claude Code to produce a full list of every file and symbol that will need to change. Review this list before any code is touched. Missing a file means the refactor leaves the codebase in an inconsistent state.
- Split the work across subagents: For a refactor touching, say, the authentication layer plus the API layer plus tests, dispatch three subagents simultaneously: one per area. Give each subagent a clear boundary ("only touch files under /auth/") to prevent conflicts.
- Orchestrate in the main session: The main session monitors completion, runs the test suite after each subagent finishes, and handles merge conflicts if two subagents modified a shared interface.
The worktree isolation means your main branch is always clean. If the refactor goes wrong, you delete the worktree and start over without a messy reset.
Workflow 4: Code Review as a Specialist Subagent
Using Claude Code for code review works well when you treat it as a specialist reviewer with a narrow brief, not a general commenter.
Generate a diff of your PR branch:
git diff main...HEAD > /tmp/pr-diff.txt
Then provide it to Claude Code with a structured brief:
Review this PR diff as a security-focused reviewer.
Scope: only flag issues that could cause a security vulnerability,
a data integrity problem, or a correctness bug.
Do not comment on style, naming, or structure unless it directly
causes one of those three problems.
For each issue: file name, line range, problem description, severity (high/medium/low).
Running multiple review passes with different specialist briefs (security reviewer, performance reviewer, API compatibility reviewer) gives you better coverage than a single "review this code" prompt. Each reviewer starts fresh without the biases of the previous review.
For teams doing async review, this reduces the roundtrip between author and human reviewer. Claude Code catches the mechanical issues; the human reviewer focuses on architecture and intent.
Workflow 5: Documentation Pass
Documentation generation works best as a two-step process: map first, write second.
Step 1 - Codebase map: Ask Claude Code to read the codebase and produce a structured outline of every public API, exported function, and module boundary. This map becomes the skeleton for the docs and surfaces gaps (undocumented functions, inconsistent naming) before writing begins.
Step 2 - Write with constraints: Use the map as input and ask Claude Code to write docs for one module at a time. Give it the constraint that every code example must be executable and every parameter description must reference a concrete type, not "the value".
Human review remains essential at Step 2. Claude Code will sometimes describe what the code does rather than what the caller needs to know. A quick pass from someone who uses the API will catch those cases faster than prompt iteration.
Workflow 6: Researching Unfamiliar Libraries
When your codebase needs to integrate a library you have not used, the typical pattern wastes time: read the README, find an example, adapt it, hit a version-specific difference, search again. Claude Code with the context7 MCP server short-circuits most of that.
The context7 MCP fetches current documentation for libraries at the version you actually have installed. This matters because training data for any LLM has a cutoff, and library APIs change. Asking Claude Code to research a library without context7 means you may get outdated patterns.
Prompt structure that works:
Using context7, fetch the current documentation for [library] version [x.y].
I need to accomplish: [specific task].
Produce a working code example and note any gotchas specific to this version.
If the docs show multiple approaches, recommend one with rationale.
The output is a starting point, not production code. But it is a starting point that matches your actual installed version, which removes the first class of adaptation bugs.
Workflow 7: Session Management
Context window management is one of the most consequential things you control in a Claude Code session. The model's attention degrades as context grows, and token costs grow linearly with context length.
Three tools:
- /clear: Wipes the conversation history entirely. Use this between unrelated tasks in the same session. There is no point carrying context from "add the auth middleware" into "write tests for the payment module". A fresh context is cheaper and produces better output.
- /compact: Produces a compressed summary of the current conversation and replaces the history with it. Use this when a task is long enough that you need continuity but the full history is ballooning. The summary retains decisions and current state without keeping every reasoning step.
- Fresh memory writes: Before clearing, ask Claude Code to write a short memory file summarizing decisions, the current state of the code, and any unresolved questions. Future sessions (or subagents) can read this file instead of re-deriving context. The pattern is particularly useful for multi-day tasks.
A rule of thumb: if the context indicator in your terminal shows you are past 50% of the model's context window and the task is not close to done, use /compact before continuing. Waiting until 90% means the summary has to compress a lot more, and the quality of the summary drops.
Workflow 8: Team Collaboration
Claude Code's collaboration model is different from IDE plugins. The shared artifacts are text files checked into version control, which means the team's workflow investment compounds over time.
Shared CLAUDE.md: The project-level CLAUDE.md is checked into the repo and read by every team member's Claude Code session. Put project conventions here: coding standards, how the test suite works, which directories are off-limits, the deploy process. Every developer benefits from these constraints automatically, and new team members are working with correct project context from their first session.
Shared skills: Skills (reusable slash commands) can be defined at the project level in .claude/commands/ and checked into git. A skill for running the full test suite, generating a code review, or formatting a PR description is available to every team member without individual setup.
Shared hooks: Project-level hooks in .claude/settings.json apply to every team member. A PostToolUse hook that runs the linter after every file edit, or a PreToolUse hook that prevents writes to certain directories, is a team-wide guardrail that does not depend on individual discipline.
Settings.json in git: The project settings file defines allowed tools, denied tools, and permission boundaries. Reviewing changes to settings.json in PR review is how teams maintain hygiene over what Claude Code is allowed to do in the project context.
Measuring Your Efficiency: What Token Metrics Tell You
Claude Code reports cache read tokens and cache write tokens alongside regular input tokens. These numbers tell you something concrete about how efficiently you are working.
Cache hit rate = (cache read tokens) / (cache read tokens + cache input tokens)
A high cache hit rate means you are running similar contexts repeatedly, which is what happens when you structure sessions well: same CLAUDE.md, same files being read, similar task patterns. Anthropic bills cache reads at roughly 10% of the regular input token cost. A session with 80% cache hit rate costs significantly less than the same work done with 0% cache hit rate.
What a low cache hit rate usually means:
- You are starting fresh sessions too often for tasks that should continue
- Your CLAUDE.md is changing frequently (invalidates the cached system prompt)
- You are passing large files as context that change between calls
- You are using many different file paths, preventing context reuse
The goal is not to maximize cache hit rate for its own sake. The goal is to be intentional: clear context when you should, preserve it when it serves you, and know the cost difference between the two choices.
Cost Management Patterns
Model routing is the highest-impact cost control. Claude Opus 4.7 (1M context) is the most capable model but costs significantly more per token than Sonnet 4.6 or Haiku 4.5. Matching model to task complexity reduces costs without sacrificing quality on the tasks that matter.
A practical routing approach:
- Opus 4.7: Complex architecture decisions, multi-file refactors requiring reasoning about system-level trade-offs, tasks where getting the wrong answer has high cost
- Sonnet 4.6: Most implementation tasks, code review, documentation, debugging with a clear error message
- Haiku 4.5: Simple edits, formatting, extracting information from a file, generating test data
Subagent overhead math: each subagent call carries its own context initialization cost. Dispatching 10 subagents to make 10 single-line edits costs more than making those 10 edits in one session with a list. Subagents pay off when the tasks are genuinely independent, take 5+ minutes each, and benefit from parallel execution. They do not pay off for small tasks that could be batched.
Prompt caching strategies for long sessions:
- Keep your CLAUDE.md stable during a session. Every change invalidates the system prompt cache.
- Pass large reference files at the beginning of a conversation and keep them at the front of context, where they are more likely to be cached.
- Use /compact before context grows very large. The compressed summary is cheaper to re-read than the full history.
Anti-Patterns That Waste Time
The subagent-for-one-line-change trap: Spawning a subagent to change a single variable name or add one import. The overhead of context initialization exceeds the time saved. Batch small changes in the main session or give the implementer a list of 20 small changes to handle together.
The "explain the plan again" loop: Asking Claude Code to explain what it is about to do, then asking it to confirm, then asking it to proceed. This consumes context and tokens without improving the output. If you need to understand the plan, use actual plan mode (claude --plan). If you trust the scope, skip the explanation and read the diff.
The reading-too-much-of-a-file trap: Claude Code will sometimes read entire files when it needs one function. You can reduce this by asking it to identify the specific function it needs before reading, or by structuring your codebase so that the relevant entry points are at the top of files. Large context reads slow sessions and increase cost without proportional benefit.
The vague task trap: "Improve this code" produces inconsistent results because the success criterion is undefined. Claude Code performs better with measurable done conditions: "this function should pass all tests in test_auth.py", "the lint check should report zero warnings", "the response time should be under 200ms on the included benchmark".
The implicit assumption trap: Asking Claude Code to "fix the bug" without providing the error output or reproduction steps. It will make a plausible attempt, which is usually wrong. Always provide the exact error, the input that triggers it, and the expected vs. actual behavior.
Safety Patterns
Never skip pre-commit hooks: Claude Code can be instructed to run with --no-verify to bypass hooks. Do not allow this. Pre-commit hooks exist precisely for the cases where automated tooling writes something that passes review but fails your safety checks. This is especially true when Claude Code is making large batches of changes.
Commit first, then refactor: Before asking Claude Code to make any significant change, ensure the current state is committed. If something goes wrong, you have a clean rollback point. Do not rely on the diff alone for recovery.
Worktrees for risky changes: Any change that touches production configuration, infrastructure definitions, or database migrations should happen in a worktree on a feature branch. Never experiment with risky changes in the main working tree.
Plan mode for destructive operations: Before running any task that involves deleting files, dropping tables, or modifying production data, always use plan mode to see exactly what Claude Code intends to do. Approve each step explicitly. A misunderstood scope on a destructive operation cannot be easily undone.
Scope boundaries in the CLAUDE.md: List directories that Claude Code should never modify. Production configuration directories, infrastructure-as-code directories, and credential storage paths belong in the deny list in your project settings.json, not just mentioned in conversation.
When to Use Other Tools Instead
Claude Code is not always the right tool. Knowing when to reach for something else reduces friction rather than adding to it.
Type-heavy editing in statically typed languages: When you are working on a file with complex generics or deeply nested types and you need fast inline type feedback, a full IDE with a language server (VS Code, JetBrains) gives you type information Claude Code cannot match without reading the entire type hierarchy. Use the IDE for the type-intensive editing, then bring Claude Code in for the reasoning.
Different cost profile: Aider runs against the same Anthropic API but uses a different context management strategy. Some developers find it costs less for certain narrow tasks. The comparison is task-specific, not categorical.
Raw terminal for fast search: If you know what you are looking for and just need to find it, grep -r, rg, or fd are faster than asking Claude Code to search the codebase. Claude Code adds value when you need reasoning about what you find, not for the mechanical search itself.
Git operations directly: Complex rebase sequences, cherry-picks across branches, bisect runs. Claude Code can assist with the reasoning, but interactive git operations are faster and less error-prone when you run them directly and understand each step.
Building a Practice
The patterns above compound. A team that has a well-maintained CLAUDE.md, a set of project-level skills, consistent session hygiene, and clear model routing guidelines will get more out of Claude Code than a team using it ad-hoc, even if individual skill is equivalent.
Start with three things: write tests before asking Claude Code to implement anything, use plan mode before any task that touches more than five files, and commit before every Claude Code task. These three habits catch the most common failure modes and build the discipline that makes the other patterns work.
For teams evaluating AI-assisted development tooling or wanting to build these workflows into their engineering practice, Petronella Technology Group offers AI development consulting for engineering and cybersecurity teams. Contact us at (919) 348-4912 or through our contact page.
For background on Claude Code's features and configuration, see our Claude Code CLI feature reference. For broader AI agent patterns, the OpenClaw AI agent guide and Hermes agent AI guide cover complementary approaches.