Claude Code · Advanced · Part 5 of 8

Working with Claude Code day to day: prompts, git, and fixing things when they go wrong

Khairul Alam·October 2026·~19 min read
AdvancedPromptingGitPull requestsTroubleshooting

Parts 1 to 4 got you installed, safe, and set up with memory and cost control. This is where the advanced level starts. You can run Claude Code; now the question is how to get good results from it every day: what to type, how to ship a change with git, how to steer when it goes the wrong way, and what to do when something breaks. Everything here follows the official best-practices, common-workflows and troubleshooting pages, with my own advice marked as such.

Part 5 in 60 seconds
  • Claude works in a loop: gather context, take action, verify the result. You can interrupt at any point.
  • Most good habits come from one fact: the context window fills up fast and quality drops as it fills.
  • Work in four phases: explore, plan, implement, commit. Skip the plan only when you could describe the change in one sentence.
  • Be specific, point at files with @, and give Claude a check it can run (tests, a build, a screenshot).
  • Ask Claude to branch, commit and open pull requests, then review the result yourself.
  • Correct early. After two failed corrections, /clear and write a better first prompt.

1. How Claude actually works: the loop

The official docs describe three phases that blend together: gather context, take action and verify results. A question about your code might need only the first. A bug fix cycles through all three repeatedly. Claude decides what each step needs from what it learned in the previous one, and you can step in at any moment.

Your promptwhat you want 1. Gathersearch, read files,check git state 2. Actedit files, runcommands 3. Verifyrun tests, read theresult, try again repeat until the task is done You can press Esc and steer at any point Tools do the acting: file edits, search, shell commands, web, code intelligence.
The agentic loop, as the official docs describe it. Models reason and tools act; Claude Code is the layer that connects them.

One constraint explains most of the advice in this post. Per the official best-practices guide: Claude's context window fills up fast, and performance degrades as it fills. Everything in the conversation counts: every message, every file Claude reads, every command output. A single debugging session can use tens of thousands of tokens. Keeping that window clean is the skill to build.

2. Explore, plan, implement, commit

Letting Claude jump straight to code can produce a neat solution to the wrong problem. The recommended workflow separates thinking from doing, using plan mode (Part 1) for the first two steps:

1. Exploreplan mode on:read and ask,change nothing 2. Planask for a plan,edit it withCtrl+G 3. Implementleave plan mode,code, run the tests,fix failures 4. Commitcommit message,open a PR,you review When to skip steps 1 and 2If you could describe the diff in one sentence (a typo, a log line, a rename), just ask for it directly.
Planning has a cost. It pays off when the approach is uncertain, several files change, or the code is unfamiliar.

Here are the four steps with the example prompts the docs use. The first two run in plan mode (press Shift+Tab until the status bar says plan mode, or start with claude --permission-mode plan):

# 1. Explore (plan mode)
read /src/auth and understand how we handle sessions and login.
also look at how we manage environment variables for secrets.

# 2. Plan (plan mode)
I want to add Google OAuth. What files need to change?
What's the session flow? Create a plan.

# 3. Implement (approve the plan, or press Shift+Tab to leave plan mode)
implement the OAuth flow from your plan. write tests for the
callback handler, run the test suite and fix any failures.

# 4. Commit
commit with a descriptive message and open a PR

In step 2, press Ctrl+G to open the plan in your text editor and change it before Claude proceeds. A wrong assumption fixed in the plan costs one sentence; the same assumption fixed after twenty edited files costs a lot more.

3. Writing prompts that work

Claude can infer intent, but it cannot read your mind. The more precise the instruction, the fewer corrections you need. These before-and-after pairs come straight from the official guide:

StrategyWeak promptStronger prompt
Scope the taskadd tests for foo.pywrite a test for foo.py covering the edge case where the user is logged out. avoid mocks.
Point to sourceswhy does ExecutionFactory have such a weird api?look through ExecutionFactory's git history and summarize how its api came to be
Reference existing patternsadd a calendar widgetlook at how existing widgets are implemented on the home page. HotDogWidget.php is a good example. follow the pattern to implement a new calendar widget… build from scratch without libraries other than the ones already used
Describe the symptomfix the login bugusers report that login fails after session timeout. check the auth flow in src/auth/, especially token refresh. write a failing test that reproduces the issue, then fix it

A pattern worth copying from the last row: symptom, likely location, and what “fixed” looks like. Vague prompts are fine when you are exploring and can afford to course-correct; “what would you improve in this file?” can surface things you would not have asked about.

Give Claude richer context

Tip from the docs: Claude is good at learning command-line tools it does not know. Try Use 'foo-cli-tool --help' to learn about foo tool, then use it to solve A, B, C. And install the gh CLI if you use GitHub: it is the most context-efficient way to work with issues and pull requests.

4. Prompt recipes for everyday tasks

These are prompts from the official common-workflows page, grouped by task. Adapt the wording to your project.

TaskPrompts to try, in order
Understand a new codebasegive me an overview of this codebase
explain the main architecture patterns used here
what are the key data models?
how is authentication handled?
Tip: start broad, then narrow; ask for a glossary of project terms.
Find the right codefind the files that handle user authentication
how do these authentication files work together?
trace the login process from front-end to database
Fix a bugI'm seeing an error when I run npm test
suggest a few ways to fix the @ts-ignore in user.ts
update user.ts to add the null check you suggested
Tip: give the reproduce command, the steps, and whether it is intermittent.
Refactorfind deprecated API usage in our codebase
refactor utils.js to use ES2024 features while maintaining the same behavior
run tests for the refactored code
Tip: do it in small, testable increments.
Write testsfind functions in NotificationsService.swift that are not covered by tests
add tests for the notification service
add test cases for edge conditions in the notification service
run the new tests and fix any failures
Document codefind functions without proper JSDoc comments in the auth module
add JSDoc comments to the undocumented functions in auth.js
Ask about a designPaste a screenshot, then: Generate CSS to match this design mockup or This is our current database schema. How should we modify it for the new feature?

Notice how every recipe is a short conversation, not one giant prompt. You are not expected to get it perfect the first time: ask, read, refine. The docs also recommend asking Claude the questions you would ask a senior engineer (“How does logging work?”, “What edge cases does this class handle?”). That alone is an effective way to onboard onto a codebase.

5. Give Claude a way to check its work

The official guide calls this the highest-leverage habit. Claude stops when the work looks done. Without a check it can run, looking done is the only signal, and you become the verification loop. Give it something that returns pass or fail and it iterates by itself.

StrategyBeforeAfter
Provide criteriaimplement a function that validates email addresseswrite a validateEmail function. example test cases: user@example.com is true, invalid is false, user@.com is false. run the tests after implementing
Check UI visuallymake the dashboard look better[paste screenshot] implement this design. take a screenshot of the result and compare it to the original. list differences and fix them
Fix root causesthe build is failingthe build fails with this error: [paste error]. fix it and verify the build succeeds. address the root cause, don't suppress the error

6. Big feature? Let Claude interview you

For larger work, start with a minimal prompt and have Claude question you before it writes anything. This prompt is from the official guide (replace the bracketed part):

I want to build [brief description]. Interview me in detail using the AskUserQuestion tool.

Ask about technical implementation, UI/UX, edge cases, concerns, and tradeoffs. Don't ask obvious questions, dig into the hard parts I might not have considered.

Keep interviewing until we've covered everything, then write a complete spec to SPEC.md.

When the spec is done, start a fresh session to build it. The new session has clean context focused on implementation, and the written spec is the shared reference. The most useful specs name the files and interfaces involved, state what is out of scope, and end with an end-to-end verification step. This pairs naturally with the feature notes and handoff notes from Part 3.

7. Git with Claude: branch, commit, pull request

Claude Code works directly with git. The official quickstart shows that you can drive it conversationally:

Branchnew branch ChangeClaude edits Verifytests pass Commitclear message Pull requestgh pr create Reviewyou decide Where you stay in charge • Read git diff before you accept a commit. • Read the pull request description Claude writes. • Never let a session push straight to a protected branch (my advice: use branch protection). • Checkpoints are not a replacement for git: they only track Claude's file edits.
Claude can do the middle of the flow. The first and last steps are yours.
You want to…Say this
See what changedwhat files have I changed?
Start a branchcreate a new branch called feature/quickstart
Look at historyshow me the last 5 commits
Commitcommit my changes with a descriptive message
Resolve conflictshelp me resolve merge conflicts
Open a pull requestcreate a pr (or first: summarize the changes I've made to the authentication module)
Improve the descriptionenhance the PR description with more context about the security improvements
Find the session behind a PRRun claude --from-pr 1234 (use your own number) or paste the PR URL into the /resume search. Claude Code links a session to a PR when it creates one with gh pr create.

Tips that make this smoother:

Two changes at once: worktrees

If you want one session on a feature and another fixing a bug without their edits colliding, use a git worktree, a separate checkout on its own branch:

claude --worktree feature-auth

Run the same command with a different name in a second terminal for a second isolated session. The repository needs at least one commit first. The docs also describe a Writer/Reviewer pattern: one session writes the code and a fresh session reviews it, so the reviewer is not biased toward code it just wrote.

8. Steering: correct early, rewind, start clean

Conversations are persistent and reversible. The docs recommend tight feedback loops: correct Claude as soon as you notice it drifting.

Do thisWhat happens
EscStops Claude mid-action. Context is kept, so you can redirect.
Esc twice, or /rewindOpens the rewind menu to restore the conversation, the code, or both to an earlier checkpoint, or to summarise from a chosen message.
“Undo that”Asks Claude to revert its changes.
Type while it works, then EnterQueues a correction. Claude reads it when its current tool calls finish and adjusts.
/clearResets the context between unrelated tasks.
/btwAsks a side question whose answer never enters the conversation history.

Every prompt that starts a turn creates a checkpoint, and Claude snapshots files before it edits them. That means you can let Claude try something risky and rewind if it fails. The limits matter, though: checkpoints cover only edits made through Claude's file tools, not changes made by shell commands, and they are not a substitute for git.

Five failure patterns to recognise

PatternFix
The kitchen-sink session: unrelated tasks pile up in one conversation./clear between unrelated tasks.
Correcting over and over: failed approaches pollute the context.After two failed corrections, /clear and write a better first prompt using what you learned.
An over-specified CLAUDE.md: rules get lost in the noise.Prune it. If Claude already does something right, delete the line.
Trust, then verify gap: plausible code that misses edge cases.Always provide tests, scripts or screenshots.
Infinite exploration: “investigate X” with no scope fills the window.Scope it narrowly, or use a subagent so the reading stays out of your main context (Part 6).

The docs end this topic with a reminder worth quoting: these are starting points, not rules. Sometimes you should let context accumulate because you are deep in one hard problem, and sometimes a vague prompt is exactly right. Notice what works and build your own intuition.

9. When something goes wrong

Install and login problems were covered in Part 1. These are the problems you can hit once Claude Code is running. Start with the built-in checkups: run /doctor inside a session for an automated check of your installation, settings, extensions and context usage, or claude doctor from your shell if claude will not start. /mcp shows MCP server status, and /feedback reports a problem to Anthropic.

SymptomWhat to try
Permission prompts keep appearing for safe commandsAdd a narrow allow rule (Part 1, section 8), or review rules with /permissions. If you are in Manual mode this is expected for anything not pre-approved.
Claude edits or runs things without askingCheck the status bar. Recent versions may start in auto mode (Part 1, section 6). Press Shift+Tab to cycle to Manual.
The wrong model is being usedRun /model to see and switch it, and /status to see what is active. The priority order is /model, then --model, then ANTHROPIC_MODEL, then your settings (Part 1, section 7).
Settings, rules or MCP servers are not taking effectUse the official Debug your configuration page. /context shows what loaded, and claude --safe-mode starts with all customisations off so you can tell whether a plugin or server is the cause.
High CPU or memory, slow responsesRun /compact regularly, restart between big tasks, and add large build folders to .gitignore. If a critical memory warning appears (heap past 2.5 GB), restart and run claude --continue to resume in a fresh process.
It hangs or freezesPress Ctrl+C to cancel. If it is unresponsive, close the terminal. Restarting does not lose your conversation: run claude --resume in the same folder.
“Autocompact is thrashing” errorA file or tool output keeps refilling the window. Ask Claude to read big files in smaller chunks, run /compact with a focus that drops the large output, move the work to a subagent, or /clear.
Search or @file mentions find nothingThe bundled ripgrep may not run on your system. Install ripgrep and set USE_BUILTIN_RIPGREP to 0, then check claude doctor. On WSL, keep the project on the Linux filesystem for better search.
Garbled characters in an editor's terminalRun /terminal-setup in Claude Code, which turns off the terminal's GPU renderer setting.
Errors like 429, 529 or “model not found”See the official error reference.
A general rule for debugging a bad session

If Claude is going in circles, the cause is usually context, not intelligence. Run /context, look at what is using the space, then either /compact with a focus, move noisy work to a subagent, or /clear and restate the task with what you learned. A clean session with a better prompt almost always beats a long session full of corrections.

10. Wrap-up and glossary

  1. Work in a loop you can interrupt, and keep the context window clean.
  2. Explore and plan before you implement, unless the change is one sentence.
  3. Be specific, use @ for files, and always give Claude a check to run.
  4. Let Claude handle branching, commits and pull requests, then review the result yourself.
  5. Correct early, rewind when needed, and /clear after two failed corrections.
  6. When something breaks, run /doctor and /context first.

Next, Part 6 extends Claude Code: connecting external tools with MCP, delegating to subagents, installing plugins, and using it from your editor, the desktop app or the web.

TermIn plain words
Agentic loopGather context, act, verify, repeat, with you able to interrupt.
CheckpointA snapshot of your files before Claude edits them, so you can rewind. Not a substitute for git.
@ referenceTyping @ and a path to put a file or folder listing into the conversation.
WorktreeA separate checkout of a git repository on its own branch, for parallel work.
Pull request (PR)A request to merge your branch, with a description and review.
SpecA written description of what to build, which a fresh session can implement.
/doctorA built-in checkup for your install, settings and context.
← Back to all writing