Claude Code · Advanced · Part 5 of 8
Working with Claude Code day to day: prompts, git, and fixing things when they go wrong
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.
- 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,
/clearand 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.
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:
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:
| Strategy | Weak prompt | Stronger prompt |
|---|---|---|
| Scope the task | add tests for foo.py | write a test for foo.py covering the edge case where the user is logged out. avoid mocks. |
| Point to sources | why does ExecutionFactory have such a weird api? | look through ExecutionFactory's git history and summarize how its api came to be |
| Reference existing patterns | add a calendar widget | look 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 symptom | fix the login bug | users 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
- Reference files with
@.Explain the logic in @src/utils/auth.jsincludes the file's content when it fits the Read tool's limit (25,000 tokens by default). Type@to open a path menu. A directory reference shows a listing, not contents, and you can mention several files in one message. - Paste or drag in images. Copy and paste with Ctrl+V (on Windows and WSL use Alt+V), drag a file into the window, or give an image path. Useful for error screenshots, designs and diagrams.
- Give URLs for docs or API references. Use
/permissionsto allow domains you use often. - Pipe data in:
cat error.log | claude -p "explain this error". - Let Claude fetch what it needs with shell commands, MCP tools or by reading files (Part 6).
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.
| Task | Prompts to try, in order |
|---|---|
| Understand a new codebase | give me an overview of this codebaseexplain the main architecture patterns used herewhat are the key data models?how is authentication handled?Tip: start broad, then narrow; ask for a glossary of project terms. |
| Find the right code | find the files that handle user authenticationhow do these authentication files work together?trace the login process from front-end to database |
| Fix a bug | I'm seeing an error when I run npm testsuggest a few ways to fix the @ts-ignore in user.tsupdate user.ts to add the null check you suggestedTip: give the reproduce command, the steps, and whether it is intermittent. |
| Refactor | find deprecated API usage in our codebaserefactor utils.js to use ES2024 features while maintaining the same behaviorrun tests for the refactored codeTip: do it in small, testable increments. |
| Write tests | find functions in NotificationsService.swift that are not covered by testsadd tests for the notification serviceadd test cases for edge conditions in the notification servicerun the new tests and fix any failures |
| Document code | find functions without proper JSDoc comments in the auth moduleadd JSDoc comments to the undocumented functions in auth.js |
| Ask about a design | Paste 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.
| Strategy | Before | After |
|---|---|---|
| Provide criteria | implement a function that validates email addresses | write 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 visually | make 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 causes | the build is failing | the build fails with this error: [paste error]. fix it and verify the build succeeds. address the root cause, don't suppress the error |
- Ask for evidence, not claims: the test output, the command it ran and what it returned, or a screenshot. Reviewing evidence is faster than re-running the check yourself.
- A second opinion: have a fresh subagent review the diff (Part 6), or run the bundled
/code-reviewskill. A reviewer that did not write the code is not biased toward it. The docs warn that a reviewer told to find gaps will usually find some, so ask for correctness and requirement gaps only, not style preferences. - If you cannot verify it, do not ship it. This is the “trust-then-verify gap” the docs list as a classic failure.
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:
| You want to… | Say this |
|---|---|
| See what changed | what files have I changed? |
| Start a branch | create a new branch called feature/quickstart |
| Look at history | show me the last 5 commits |
| Commit | commit my changes with a descriptive message |
| Resolve conflicts | help me resolve merge conflicts |
| Open a pull request | create a pr (or first: summarize the changes I've made to the authentication module) |
| Improve the description | enhance the PR description with more context about the security improvements |
| Find the session behind a PR | Run 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:
- Install the GitHub CLI (
gh) and sign in withgh auth login. Without it Claude can still use the GitHub API, but unauthenticated requests often hit rate limits. - Put your repository etiquette in CLAUDE.md (Part 2): branch naming, commit message style, PR conventions. The docs list “repository etiquette” as something worth writing down.
- Pre-approve safe git commands instead of clicking through prompts. The docs' own example for scripts is
Bash(git diff *),Bash(git log *),Bash(git status *)andBash(git commit *). Notice they do not allowgit push. - Ask Claude to highlight risks in a pull request it wrote before you submit it, and review the result yourself.
- Review before merging. The bundled
/code-reviewskill reviews the current diff for bugs, and/security-reviewruns an on-demand security pass over the changes on your branch.
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 this | What happens |
|---|---|
| Esc | Stops Claude mid-action. Context is kept, so you can redirect. |
Esc twice, or /rewind | Opens 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 Enter | Queues a correction. Claude reads it when its current tool calls finish and adjusts. |
/clear | Resets the context between unrelated tasks. |
/btw | Asks 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
| Pattern | Fix |
|---|---|
| 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.
| Symptom | What to try |
|---|---|
| Permission prompts keep appearing for safe commands | Add 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 asking | Check 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 used | Run /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 effect | Use 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 responses | Run /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 freezes | Press 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” error | A 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 nothing | The 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 terminal | Run /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. |
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
- Work in a loop you can interrupt, and keep the context window clean.
- Explore and plan before you implement, unless the change is one sentence.
- Be specific, use
@for files, and always give Claude a check to run. - Let Claude handle branching, commits and pull requests, then review the result yourself.
- Correct early, rewind when needed, and
/clearafter two failed corrections. - When something breaks, run
/doctorand/contextfirst.
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.
| Term | In plain words |
|---|---|
| Agentic loop | Gather context, act, verify, repeat, with you able to interrupt. |
| Checkpoint | A snapshot of your files before Claude edits them, so you can rewind. Not a substitute for git. |
@ reference | Typing @ and a path to put a file or folder listing into the conversation. |
| Worktree | A 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. |
| Spec | A written description of what to build, which a fresh session can implement. |
/doctor | A built-in checkup for your install, settings and context. |