CMD Master
Back to Blog
Arnošt Havelka

How to Get Better Results from Claude Code

Get more reliable Claude Code results with scoped context, analysis before edits, explicit constraints, focused tests, and incremental changes.

How to Get Better Results from Claude Code

Get better results from Claude Code by treating each request as an engineering brief: give it the relevant context, ask it to inspect before changing code, constrain the solution, and require evidence that the result works. The same approach improves bug fixes, refactors, tests, and documentation.

Claude Code’s documented common workflows cover exploring codebases, debugging, refactoring, testing, and planning before edits—when your environment supports them. Use those capabilities to reduce uncertainty, not to skip the reasoning a teammate would need.

Start with the problem, not the proposed patch

“Replace this hook with a global store” is an implementation-first prompt. It preselects a solution before the assistant has examined the ownership and failure mode.

Start this way:

Problem: A lesson completion indicator sometimes disappears after navigation.

Observed: The completion event is recorded, but the next screen starts without
the celebratory state.
Expected: A completion event remains available through the navigation that
follows it, then clears at the appropriate boundary.

Scope: Inspect the lesson store, the completion handler, and the next-screen
transition. Do not change unrelated dashboard progress code.

Before editing, trace the event from write to render. State the current owner
of the flag, the likely reset points, and the evidence for each hypothesis.

The request asks for a model of the existing behavior before it asks for a change.

Provide only the context that changes the decision

For a focused task, include:

  • the failing command, test, screenshot, or error;
  • the files or subsystem that should be examined first;
  • relevant project rules or architectural constraints;
  • recent changes that could have introduced the regression;
  • behavior that must stay unchanged.

Do not paste a whole repository into the prompt. If more context becomes necessary, ask the assistant to name the next file or boundary it needs and why.

Use an analysis-first checkpoint

For work with non-obvious risk, ask for a read-only analysis before implementation:

Inspect the current subscription-gating flow and answer these questions before
editing:

1. Where is access decided?
2. Which loading state prevents a premature redirect?
3. Which route and CTA call sites use the decision?
4. What regression test would prove a paid user is not sent to pricing?

Do not write code yet. Separate observed behavior from assumptions.

An analysis checkpoint is valuable for permissions, payments, data migrations, navigation, and shared state. It also gives you a small document to review before a large diff exists.

Define constraints as engineering contracts

The assistant cannot reliably infer every contract from nearby code. State the ones that matter:

Constraints:
- keep the application compatible with static export;
- preserve the active locale in internal navigation;
- do not add server-only runtime behavior;
- keep the existing client writer as the single source of truth;
- do not change public route or event names;
- do not broaden the change outside this feature without explaining why.

Specific constraints make review sharper because a proposed change can be compared with a written boundary.

Request incremental refactoring

Break a risky refactor into small, testable steps:

Step 1: Identify the duplicated state transition and explain the current tests.
Step 2: Extract only the shared transition behind the same public API.
Step 3: Run the focused tests and show the changed behavior.
Step 4: Propose, but do not implement, any broader cleanup.

Incremental work protects you from a patch that changes rendering, state ownership, and tests at the same time. If step 2 fails, the cause is easier to isolate.

Ask for evidence during debugging

Use an evidence chain:

Evidence: [logs, stack trace, failing test, command output, or user steps]
Hypotheses: List the smallest plausible causes in priority order.
Verification: State the observation that would confirm or rule out each cause.
Fix: Propose the smallest change supported by the evidence.
Validation: Add a regression test and a manual check where necessary.

Do not ask an assistant to patch production behavior from a vague symptom. A confident-looking fix is not evidence.

Make tests part of “done”

Acceptance criteria:
- the reported failure is covered by a focused regression test;
- the successful existing workflow still passes;
- type checking and the relevant test command pass;
- the diff stays within the agreed scope;
- the final explanation names any behavior that could not be verified locally.

This helps Claude Code stop at a reviewable endpoint rather than treating compilation as the only signal of correctness.

For the broader prompt framework, start with how to write better AI prompts. For task-focused patterns, use prompt engineering for developers and the production debugging prompt templates.

If the task changes a script or command-based workflow, reproduce the relevant input and output before asking for a fix. Practice terminal workflows in the browser to make validation concrete.

References

These documentation links provide authoritative details for the commands used in this article.