6 6
7> Step-by-step guides for exploring codebases, fixing bugs, refactoring, testing, and other everyday tasks with Claude Code.7> Step-by-step guides for exploring codebases, fixing bugs, refactoring, testing, and other everyday tasks with Claude Code.
8 8
9This page covers practical workflows for everyday development: exploring unfamiliar code, debugging, refactoring, writing tests, creating PRs, and managing sessions. Each section includes example prompts you can adapt to your own projects. For higher-level patterns and tips, see [Best practices](/en/best-practices).9This page collects short recipes for everyday development. For higher-level guidance on prompting and context management, see [Best practices](/en/best-practices).
10 10
11## Understand new codebases11This page covers:
12 12
13### Get a quick codebase overview13* [Prompt recipes](#prompt-recipes) for exploring code, fixing bugs, refactoring, testing, PRs, and documentation
14* [Resume previous conversations](#resume-previous-conversations) so a task can span multiple sittings
15* [Run parallel sessions with worktrees](#run-parallel-sessions-with-worktrees) so concurrent edits don't collide
16* [Plan before editing](#plan-before-editing) to review changes before they touch disk
17* [Delegate research to subagents](#delegate-research-to-subagents) to keep your main context clean
18* [Pipe Claude into scripts](#pipe-claude-into-scripts) for CI and batch processing
19
20## Prompt recipes
21
22These are prompt patterns for everyday tasks like exploring unfamiliar code, debugging, refactoring, writing tests, and creating PRs. Each works in any Claude Code surface; adapt the wording to your project.
23
24### Understand new codebases
25
26#### Get a quick codebase overview
14 27
15Suppose you've just joined a new project and need to understand its structure quickly.28Suppose you've just joined a new project and need to understand its structure quickly.
16 29
56 * Request a glossary of project-specific terms69 * Request a glossary of project-specific terms
57</Tip>70</Tip>
58 71
59### Find relevant code72#### Find relevant code
60 73
61Suppose you need to locate code related to a specific feature or functionality.74Suppose you need to locate code related to a specific feature or functionality.
62 75
90 103
91***104***
92 105
93## Fix bugs efficiently106### Fix bugs efficiently
94 107
95Suppose you've encountered an error message and need to find and fix its source.108Suppose you've encountered an error message and need to find and fix its source.
96 109
124 137
125***138***
126 139
127## Refactor code140### Refactor code
128 141
129Suppose you need to update old code to use modern patterns and practices.142Suppose you need to update old code to use modern patterns and practices.
130 143
164 177
165***178***
166 179
167## Use specialized subagents180### Work with tests
168
169Suppose you want to use specialized AI subagents to handle specific tasks more effectively.
170
171<Steps>
172 <Step title="View available subagents">
173 ```text theme={null}
174 /agents
175 ```
176
177 This shows all available subagents and lets you create new ones.
178 </Step>
179
180 <Step title="Use subagents automatically">
181 Claude Code automatically delegates appropriate tasks to specialized subagents:
182
183 ```text theme={null}
184 review my recent code changes for security issues
185 ```
186
187 ```text theme={null}
188 run all tests and fix any failures
189 ```
190 </Step>
191
192 <Step title="Explicitly request specific subagents">
193 ```text theme={null}
194 use the code-reviewer subagent to check the auth module
195 ```
196
197 ```text theme={null}
198 have the debugger subagent investigate why users can't log in
199 ```
200 </Step>
201
202 <Step title="Create custom subagents for your workflow">
203 ```text theme={null}
204 /agents
205 ```
206
207 Then select "Create New subagent" and follow the prompts to define:
208
209 * A unique identifier that describes the subagent's purpose (for example, `code-reviewer`, `api-designer`).
210 * When Claude should use this agent
211 * Which tools it can access
212 * A system prompt describing the agent's role and behavior
213 </Step>
214</Steps>
215
216<Tip>
217 Tips:
218
219 * Create project-specific subagents in `.claude/agents/` for team sharing
220 * Use descriptive `description` fields to enable automatic delegation
221 * Limit tool access to what each subagent actually needs
222 * Check the [subagents documentation](/en/sub-agents) for detailed examples
223</Tip>
224
225***
226
227## Use Plan Mode for safe code analysis
228
229Plan Mode instructs Claude to create a plan by analyzing the codebase with read-only operations, perfect for exploring codebases, planning complex changes, or reviewing code safely. In Plan Mode, Claude uses [`AskUserQuestion`](/en/tools-reference) to gather requirements and clarify your goals before proposing a plan.
230
231### When to use Plan Mode
232
233* **Multi-step implementation**: When your feature requires making edits to many files
234* **Code exploration**: When you want to research the codebase thoroughly before changing anything
235* **Interactive development**: When you want to iterate on the direction with Claude
236
237### How to use Plan Mode
238
239**Turn on Plan Mode during a session**
240
241You can switch into Plan Mode during a session using **Shift+Tab** to cycle through permission modes.
242
243If you are in Normal Mode, **Shift+Tab** first switches into Auto-Accept Mode, indicated by `⏵⏵ accept edits on` at the bottom of the terminal. A subsequent **Shift+Tab** will switch into Plan Mode, indicated by `⏸ plan mode on`.
244
245**Start a new session in Plan Mode**
246
247To start a new session in Plan Mode, use the `--permission-mode plan` flag:
248
249```bash theme={null}
250claude --permission-mode plan
251```
252
253**Run "headless" queries in Plan Mode**
254
255You can also run a query in Plan Mode directly with `-p` (that is, in ["headless mode"](/en/headless)):
256
257```bash theme={null}
258claude --permission-mode plan -p "Analyze the authentication system and suggest improvements"
259```
260
261### Example: Planning a complex refactor
262
263```bash theme={null}
264claude --permission-mode plan
265```
266
267```text theme={null}
268I need to refactor our authentication system to use OAuth2. Create a detailed migration plan.
269```
270
271Claude analyzes the current implementation and create a comprehensive plan. Refine with follow-ups:
272
273```text theme={null}
274What about backward compatibility?
275```
276
277```text theme={null}
278How should we handle database migration?
279```
280
281<Tip>Press `Ctrl+G` to open the plan in your default text editor, where you can edit it directly before Claude proceeds.</Tip>
282
283When you accept a plan, Claude automatically names the session from the plan content. The name appears on the prompt bar and in the session picker. If you've already set a name with `--name` or `/rename`, accepting a plan won't overwrite it.
284
285### Configure Plan Mode as default
286
287```json theme={null}
288// .claude/settings.json
289{
290 "permissions": {
291 "defaultMode": "plan"
292 }
293}
294```
295
296See [settings documentation](/en/settings#available-settings) for more configuration options.
297
298***
299
300## Work with tests
301 181
302Suppose you need to add tests for uncovered code.182Suppose you need to add tests for uncovered code.
303 183
333 213
334***214***
335 215
336## Create pull requests216### Create pull requests
337 217
338You can create pull requests by asking Claude directly ("create a pr for my changes"), or guide Claude through it step-by-step:218You can create pull requests by asking Claude directly ("create a pr for my changes"), or guide Claude through it step-by-step:
339 219
357 </Step>237 </Step>
358</Steps>238</Steps>
359 239
360When you create a PR using `gh pr create`, the session is automatically linked to that PR. To return to it later, run `claude --from-pr <number>` or paste the PR URL into the [`/resume` picker](#use-the-session-picker) search.240When you create a PR using `gh pr create`, the session is automatically linked to that PR. To return to it later, run `claude --from-pr <number>` or paste the PR URL into the [`/resume` picker](/en/sessions#use-the-session-picker) search.
361 241
362<Tip>242<Tip>
363 Review Claude's generated PR before submitting and ask Claude to highlight potential risks or considerations.243 Review Claude's generated PR before submitting and ask Claude to highlight potential risks or considerations.
364</Tip>244</Tip>
365 245
366## Handle documentation246### Handle documentation
367 247
368Suppose you need to add or update documentation for your code.248Suppose you need to add or update documentation for your code.
369 249
403 283
404***284***
405 285
406## Work in notes and non-code folders286### Work in notes and non-code folders
407 287
408Claude Code works in any directory. Run it inside a notes vault, a documentation folder, or any collection of markdown files to search, edit, and reorganize content the same way you would code.288Claude Code works in any directory. Run it inside a notes vault, a documentation folder, or any collection of markdown files to search, edit, and reorganize content the same way you would code.
409 289
411 291
412***292***
413 293
414## Work with images294### Work with images
415 295
416Suppose you need to work with images in your codebase, and you want Claude's help analyzing image content.296Suppose you need to work with images in your codebase, and you want Claude's help analyzing image content.
417 297
471 351
472***352***
473 353
474## Reference files and directories354### Reference files and directories
475 355
476Use @ to quickly include files or directories without waiting for Claude to read them.356Use @ to quickly include files or directories without waiting for Claude to read them.
477 357
512 392
513***393***
514 394
515## Use extended thinking (thinking mode)395### Run Claude on a schedule
516
517[Extended thinking](https://platform.claude.com/docs/en/build-with-claude/extended-thinking) is enabled by default, giving Claude space to reason through complex problems step-by-step before responding. This reasoning is visible in verbose mode, which you can toggle on with `Ctrl+O`. During extended thinking, the spinner shows inline progress hints such as "still thinking" and "almost done thinking" to indicate Claude is actively working.
518
519Additionally, [models that support effort](/en/model-config#adjust-effort-level) use adaptive reasoning: instead of a fixed thinking token budget, the model dynamically decides whether and how much to think based on your effort level setting and the task at hand. Adaptive reasoning lets Claude respond faster to routine prompts and reserve deeper thinking for steps that benefit from it.
520
521Extended thinking is particularly valuable for complex architectural decisions, challenging bugs, multi-step implementation planning, and evaluating tradeoffs between different approaches.
522
523<Note>
524 Phrases like "think", "think hard", and "think more" are interpreted as regular prompt instructions and don't allocate thinking tokens.
525</Note>
526
527### Configure thinking mode
528
529Thinking is enabled by default, but you can adjust or disable it.
530
531| Scope | How to configure | Details |
532| ------------------------ | ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
533| **Effort level** | Run `/effort`, adjust in `/model`, or set [`CLAUDE_CODE_EFFORT_LEVEL`](/en/env-vars) | Control thinking depth on [supported models](/en/model-config#adjust-effort-level) |
534| **`ultrathink` keyword** | Include "ultrathink" anywhere in your prompt | Adds an in-context instruction telling the model to reason more on that turn. Does not change the effort level itself; see [Adjust effort level](/en/model-config#adjust-effort-level) for that |
535| **Toggle shortcut** | Press `Option+T` (macOS) or `Alt+T` (Windows/Linux) | Toggle thinking on/off for the current session (all models). May require [terminal configuration](/en/terminal-config) to enable Option key shortcuts |
536| **Global default** | Use `/config` to toggle thinking mode | Sets your default across all projects (all models).<br />Saved as `alwaysThinkingEnabled` in `~/.claude/settings.json` |
537| **Limit token budget** | Set [`MAX_THINKING_TOKENS`](/en/env-vars) environment variable | Limit the thinking budget to a specific number of tokens. On models with adaptive reasoning, only `0` applies unless adaptive reasoning is disabled. Example: `export MAX_THINKING_TOKENS=10000` |
538
539To view Claude's thinking process, press `Ctrl+O` to toggle verbose mode and see the internal reasoning displayed as gray italic text.
540
541### How extended thinking works
542
543Extended thinking controls how much internal reasoning Claude performs before responding. More thinking provides more space to explore solutions, analyze edge cases, and self-correct mistakes.
544
545On [models that support effort](/en/model-config#adjust-effort-level), thinking uses adaptive reasoning: the model dynamically allocates thinking tokens based on the effort level you select. This is the recommended way to tune the tradeoff between speed and reasoning depth. If you want Claude to think more or less often than your effort level would otherwise produce, you can also say so directly in your prompt or in `CLAUDE.md`.
546
547With older models, thinking uses a fixed token budget drawn from your output allocation. The budget varies by model; see [`MAX_THINKING_TOKENS`](/en/env-vars) for per-model ceilings. You can limit the budget with that environment variable, or disable thinking entirely via `/config` or the `Option+T`/`Alt+T` toggle.
548
549On models with adaptive reasoning, `MAX_THINKING_TOKENS` only applies when set to `0` to disable thinking, or when `CLAUDE_CODE_DISABLE_ADAPTIVE_THINKING=1` reverts the model to the fixed budget. `CLAUDE_CODE_DISABLE_ADAPTIVE_THINKING` applies to Opus 4.6 and Sonnet 4.6 only. Opus 4.7 always uses adaptive reasoning and does not support a fixed thinking budget. See [environment variables](/en/env-vars).
550
551<Warning>
552 You're charged for all thinking tokens used even when thinking summaries are redacted. In interactive mode, thinking appears as a collapsed stub by default. Set `showThinkingSummaries: true` in `settings.json` to show full summaries.
553</Warning>
554
555***
556
557## Resume previous conversations
558
559When starting Claude Code, you can resume a previous session:
560
561* `claude --continue` continues the most recent conversation in the current directory
562* `claude --resume` opens a conversation picker or resumes by name
563* `claude --from-pr 123` resumes sessions linked to a specific pull request
564
565From inside an active session, use `/resume` to switch to a different conversation.
566
567When the selected session is old and large enough that re-reading it would consume a substantial share of your usage limits, `--resume`, `--continue`, and `/resume` offer to resume from a summary instead of loading the full transcript. This prompt is not available on Amazon Bedrock, Google Cloud Vertex AI, or Microsoft Foundry.
568
569Sessions are stored per project directory. By default, the `/resume` picker shows interactive sessions from the current worktree, with keyboard shortcuts to widen the list to other worktrees or projects, search, preview, and rename. Sessions started elsewhere that added the current directory with `/add-dir` are also included by default. See [Use the session picker](#use-the-session-picker) below for the full shortcut reference.
570
571When you select a session from another worktree of the same repository, Claude Code resumes it directly without requiring you to switch directories first. Selecting a session from an unrelated project copies a `cd` and resume command to your clipboard instead.
572
573Resuming by name resolves across the current repository and its worktrees. Both `claude --resume <name>` and `/resume <name>` look for an exact match and resume it directly, even if the session lives in a different worktree.
574
575When the name is ambiguous, `claude --resume <name>` opens the picker with the name pre-filled as a search term. `/resume <name>` from inside a session reports an error instead, so run `/resume` with no argument to open the picker and choose.
576
577Sessions created by `claude -p` or SDK invocations do not appear in the picker, but you can still resume one by passing its session ID directly to `claude --resume <session-id>`.
578
579### Name your sessions
580
581Give sessions descriptive names to find them later. This is a best practice when working on multiple tasks or features.
582
583<Steps>
584 <Step title="Name the session">
585 Name a session at startup with `-n`:
586
587 ```bash theme={null}
588 claude -n auth-refactor
589 ```
590
591 Or use `/rename` during a session, which also shows the name on the prompt bar:
592
593 ```text theme={null}
594 /rename auth-refactor
595 ```
596
597 You can also rename any session from the picker: run `/resume`, navigate to a session, and press `Ctrl+R`.
598 </Step>
599
600 <Step title="Resume by name later">
601 From the command line:
602
603 ```bash theme={null}
604 claude --resume auth-refactor
605 ```
606
607 Or from inside an active session:
608
609 ```text theme={null}
610 /resume auth-refactor
611 ```
612 </Step>
613</Steps>
614
615### Use the session picker
616
617The `/resume` command (or `claude --resume` without arguments) opens an interactive session picker with these features:
618
619**Keyboard shortcuts in the picker:**
620
621| Shortcut | Action |
622| :------------------------------------------------ | :----------------------------------------------------------------------------------------------------------------------------------------------------------- |
623| `↑` / `↓` | Navigate between sessions |
624| `→` / `←` | Expand or collapse grouped sessions |
625| `Enter` | Select and resume the highlighted session |
626| `Space` | Preview the session content. `Ctrl+V` also works on terminals that do not capture it as paste |
627| `Ctrl+R` | Rename the highlighted session |
628| `/` or any printable character other than `Space` | Enter search mode and filter sessions. Paste a GitHub, GitHub Enterprise, GitLab, or Bitbucket pull or merge request URL to find the session that created it |
629| `Ctrl+A` | Show sessions from all projects on this machine. Press again to restore the current repository |
630| `Ctrl+W` | Show sessions from all worktrees of the current repository. Press again to restore the current worktree. Only shown in multi-worktree repositories |
631| `Ctrl+B` | Filter to sessions from your current git branch. Press again to show sessions from all branches |
632| `Esc` | Exit the picker or search mode |
633
634**Session organization:**
635
636The picker displays sessions with helpful metadata:
637
638* Session name if set, otherwise the conversation summary or first user prompt
639* Time elapsed since last activity
640* Message count
641* Git branch (if applicable)
642* Project path, shown after widening to all projects with `Ctrl+A`
643
644Forked sessions (created with `/branch`, `/rewind`, or `--fork-session`) are grouped together under their root session, making it easier to find related conversations.
645
646<Tip>
647 Tips:
648
649 * **Name sessions early**: Use `/rename` when starting work on a distinct task: it's much easier to find "payment-integration" than "explain this function" later
650 * Use `--continue` for quick access to your most recent conversation in the current directory
651 * Use `--resume session-name` when you know which session you need
652 * Use `--resume` (without a name) when you need to browse and select
653 * For scripts, use `claude --continue --print "prompt"` to resume in non-interactive mode
654 * Press `Space` in the picker to preview a session before resuming it
655 * The resumed conversation starts with the same model and configuration as the original
656
657 How it works:
658
659 1. **Conversation Storage**: All conversations are automatically saved locally with their full message history
660 2. **Message Deserialization**: When resuming, the entire message history is restored to maintain context
661 3. **Tool State**: Tool usage and results from the previous conversation are preserved
662 4. **Context Restoration**: The conversation resumes with all previous context intact
663</Tip>
664
665***
666
667## Run parallel Claude Code sessions with Git worktrees
668
669When working on multiple tasks at once, you need each Claude session to have its own copy of the codebase so changes don't collide. Git worktrees solve this by creating separate working directories that each have their own files and branch, while sharing the same repository history and remote connections. This means you can have Claude working on a feature in one worktree while fixing a bug in another, without either session interfering with the other.
670
671Use the `--worktree` (`-w`) flag to create an isolated worktree and start Claude in it. The value you pass becomes the worktree directory name and branch name:
672
673```bash theme={null}
674# Start Claude in a worktree named "feature-auth"
675# Creates .claude/worktrees/feature-auth/ with a new branch
676claude --worktree feature-auth
677
678# Start another session in a separate worktree
679claude --worktree bugfix-123
680```
681
682If you omit the name, Claude generates a random one automatically:
683
684```bash theme={null}
685# Auto-generates a name like "bright-running-fox"
686claude --worktree
687```
688
689Worktrees are created at `<repo>/.claude/worktrees/<name>` and branch from the default remote branch, which is where `origin/HEAD` points. The worktree branch is named `worktree-<name>`.
690
691The base branch is not configurable through a Claude Code flag or setting. `origin/HEAD` is a reference stored in your local `.git` directory that Git set once when you cloned. If the repository's default branch later changes on GitHub or GitLab, your local `origin/HEAD` keeps pointing at the old one, and worktrees will branch from there. To re-sync your local reference with whatever the remote currently considers its default:
692
693```bash theme={null}
694git remote set-head origin -a
695```
696
697This is a standard Git command that only updates your local `.git` directory. Nothing on the remote server changes. If you want worktrees to base off a specific branch rather than the remote's default, set it explicitly with `git remote set-head origin your-branch-name`.
698
699For full control over how worktrees are created, including choosing a different base per invocation, configure a [WorktreeCreate hook](/en/hooks#worktreecreate). The hook replaces Claude Code's default `git worktree` logic entirely, so you can fetch and branch from whatever ref you need.
700
701You can also ask Claude to "work in a worktree" or "start a worktree" during a session, and it will create one automatically.
702
703### Subagent worktrees
704
705Subagents can also use worktree isolation to work in parallel without conflicts. Ask Claude to "use worktrees for your agents" or configure it in a [custom subagent](/en/sub-agents#supported-frontmatter-fields) by adding `isolation: worktree` to the agent's frontmatter. Each subagent gets its own worktree that is automatically cleaned up when the subagent finishes without changes.
706
707### Worktree cleanup
708
709When you exit a worktree session, Claude handles cleanup based on whether you made changes:
710
711* **No changes**: the worktree and its branch are removed automatically
712* **Changes or commits exist**: Claude prompts you to keep or remove the worktree. Keeping preserves the directory and branch so you can return later. Removing deletes the worktree directory and its branch, discarding all uncommitted changes and commits
713
714Subagent worktrees orphaned by a crash or an interrupted parallel run are removed automatically at startup once they are older than your [`cleanupPeriodDays`](/en/settings#available-settings) setting, provided they have no uncommitted changes, no untracked files, and no unpushed commits. Worktrees you create with `--worktree` are never removed by this sweep.
715
716To clean up worktrees outside of a Claude session, use [manual worktree management](#manage-worktrees-manually).
717
718<Tip>
719 Add `.claude/worktrees/` to your `.gitignore` to prevent worktree contents from appearing as untracked files in your main repository.
720</Tip>
721
722### Copy gitignored files to worktrees
723
724Git worktrees are fresh checkouts, so they don't include untracked files like `.env` or `.env.local` from your main repository. To automatically copy these files when Claude creates a worktree, add a `.worktreeinclude` file to your project root.
725
726The file uses `.gitignore` syntax to list which files to copy. Only files that match a pattern and are also gitignored get copied, so tracked files are never duplicated.
727
728```text .worktreeinclude theme={null}
729.env
730.env.local
731config/secrets.json
732```
733
734This applies to worktrees created with `--worktree`, subagent worktrees, and parallel sessions in the [desktop app](/en/desktop#work-in-parallel-with-sessions).
735
736### Manage worktrees manually
737
738For more control over worktree location and branch configuration, create worktrees with Git directly. This is useful when you need to check out a specific existing branch or place the worktree outside the repository.
739
740```bash theme={null}
741# Create a worktree with a new branch
742git worktree add ../project-feature-a -b feature-a
743
744# Create a worktree with an existing branch
745git worktree add ../project-bugfix bugfix-123
746
747# Start Claude in the worktree
748cd ../project-feature-a && claude
749
750# Clean up when done
751git worktree list
752git worktree remove ../project-feature-a
753```
754
755Learn more in the [official Git worktree documentation](https://git-scm.com/docs/git-worktree).
756
757<Tip>
758 Remember to initialize your development environment in each new worktree according to your project's setup. Depending on your stack, this might include running dependency installation (`npm install`, `yarn`), setting up virtual environments, or following your project's standard setup process.
759</Tip>
760
761### Non-git version control
762
763Worktree isolation works with git by default. For other version control systems like SVN, Perforce, or Mercurial, configure [WorktreeCreate and WorktreeRemove hooks](/en/hooks#worktreecreate) to provide custom worktree creation and cleanup logic. When configured, these hooks replace the default git behavior when you use `--worktree`, so [`.worktreeinclude`](#copy-gitignored-files-to-worktrees) is not processed. Copy any local configuration files inside your hook script instead.
764
765For automated coordination of parallel sessions with shared tasks and messaging, see [agent teams](/en/agent-teams).
766
767***
768
769## Get notified when Claude needs your attention
770
771When you kick off a long-running task and switch to another window, you can set up desktop notifications so you know when Claude finishes or needs your input. This uses the `Notification` [hook event](/en/hooks-guide#get-notified-when-claude-needs-input), which fires whenever Claude is waiting for permission, idle and ready for a new prompt, or completing authentication.
772
773<Steps>
774 <Step title="Add the hook to your settings">
775 Open `~/.claude/settings.json` and add a `Notification` hook that calls your platform's native notification command:
776
777 <Tabs>
778 <Tab title="macOS">
779 ```json theme={null}
780 {
781 "hooks": {
782 "Notification": [
783 {
784 "matcher": "",
785 "hooks": [
786 {
787 "type": "command",
788 "command": "osascript -e 'display notification \"Claude Code needs your attention\" with title \"Claude Code\"'"
789 }
790 ]
791 }
792 ]
793 }
794 }
795 ```
796 </Tab>
797
798 <Tab title="Linux">
799 ```json theme={null}
800 {
801 "hooks": {
802 "Notification": [
803 {
804 "matcher": "",
805 "hooks": [
806 {
807 "type": "command",
808 "command": "notify-send 'Claude Code' 'Claude Code needs your attention'"
809 }
810 ]
811 }
812 ]
813 }
814 }
815 ```
816 </Tab>
817
818 <Tab title="Windows">
819 ```json theme={null}
820 {
821 "hooks": {
822 "Notification": [
823 {
824 "matcher": "",
825 "hooks": [
826 {
827 "type": "command",
828 "command": "powershell.exe -Command \"[System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms'); [System.Windows.Forms.MessageBox]::Show('Claude Code needs your attention', 'Claude Code')\""
829 }
830 ]
831 }
832 ]
833 }
834 }
835 ```
836 </Tab>
837 </Tabs>
838
839 If your settings file already has a `hooks` key, merge the `Notification` entry into it rather than overwriting. You can also ask Claude to write the hook for you by describing what you want in the CLI.
840 </Step>
841
842 <Step title="Optionally narrow the matcher">
843 By default the hook fires on all notification types. To fire only for specific events, set the `matcher` field to one of these values:
844
845 | Matcher | Fires when |
846 | :--------------------- | :----------------------------------------------------- |
847 | `permission_prompt` | Claude needs you to approve a tool use |
848 | `idle_prompt` | Claude is done and waiting for your next prompt |
849 | `auth_success` | Authentication completes |
850 | `elicitation_dialog` | An MCP server opens an elicitation form |
851 | `elicitation_complete` | An MCP elicitation form is submitted or dismissed |
852 | `elicitation_response` | An MCP elicitation response is sent back to the server |
853 </Step>
854
855 <Step title="Verify the hook">
856 Type `/hooks` and select `Notification` to confirm the hook appears. Selecting it shows the command that will run. To test it end-to-end, ask Claude to run a command that requires permission and switch away from the terminal, or ask Claude to trigger a notification directly.
857 </Step>
858</Steps>
859
860For the complete event schema and notification types, see the [Notification reference](/en/hooks#notification).
861
862***
863
864## Use Claude as a unix-style utility
865
866### Add Claude to your verification process
867
868Suppose you want to use Claude Code as a linter or code reviewer.
869
870**Add Claude to your build script:**
871
872```json theme={null}
873// package.json
874{
875 ...
876 "scripts": {
877 ...
878 "lint:claude": "claude -p 'you are a linter. please look at the changes vs. main and report any issues related to typos. report the filename and line number on one line, and a description of the issue on the second line. do not return any other text.'"
879 }
880}
881```
882
883<Tip>
884 Tips:
885
886 * Use Claude for automated code review in your CI/CD pipeline
887 * Customize the prompt to check for specific issues relevant to your project
888 * Consider creating multiple scripts for different types of verification
889</Tip>
890
891### Pipe in, pipe out
892
893Suppose you want to pipe data into Claude, and get back data in a structured format.
894
895**Pipe data through Claude:**
896
897```bash theme={null}
898cat build-error.txt | claude -p 'concisely explain the root cause of this build error' > output.txt
899```
900
901<Tip>
902 Tips:
903
904 * Use pipes to integrate Claude into existing shell scripts
905 * Combine with other Unix tools for powerful workflows
906 * Consider using `--output-format` for structured output
907</Tip>
908
909### Control output format
910
911Suppose you need Claude's output in a specific format, especially when integrating Claude Code into scripts or other tools.
912
913<Steps>
914 <Step title="Use text format (default)">
915 ```bash theme={null}
916 cat data.txt | claude -p 'summarize this data' --output-format text > summary.txt
917 ```
918
919 This outputs just Claude's plain text response (default behavior).
920 </Step>
921
922 <Step title="Use JSON format">
923 ```bash theme={null}
924 cat code.py | claude -p 'analyze this code for bugs' --output-format json > analysis.json
925 ```
926
927 This outputs a JSON array of messages with metadata including cost and duration.
928 </Step>
929
930 <Step title="Use streaming JSON format">
931 ```bash theme={null}
932 cat log.txt | claude -p 'parse this log file for errors' --output-format stream-json
933 ```
934
935 This outputs a series of JSON objects in real-time as Claude processes the request. Each message is a valid JSON object, but the entire output is not valid JSON if concatenated.
936 </Step>
937</Steps>
938
939<Tip>
940 Tips:
941
942 * Use `--output-format text` for simple integrations where you just need Claude's response
943 * Use `--output-format json` when you need the full conversation log
944 * Use `--output-format stream-json` for real-time output of each conversation turn
945</Tip>
946
947***
948
949## Run Claude on a schedule
950 396
951Suppose you want Claude to handle a task automatically on a recurring basis, like reviewing open PRs every morning, auditing dependencies weekly, or checking for CI failures overnight.397Suppose you want Claude to handle a task automatically on a recurring basis, like reviewing open PRs every morning, auditing dependencies weekly, or checking for CI failures overnight.
952 398
965 411
966***412***
967 413
968## Ask Claude about its capabilities414### Ask Claude about its capabilities
969 415
970Claude has built-in access to its documentation and can answer questions about its own features and limitations.416Claude has built-in access to its documentation and can answer questions about its own features and limitations.
971 417
972### Example questions418#### Example questions
973 419
974```text theme={null}420```text theme={null}
975can Claude Code create pull requests?421can Claude Code create pull requests?
1009 455
1010***456***
1011 457
458## Resume previous conversations
459
460When a task spans multiple sittings, pick up where you left off instead of re-explaining context. Claude Code saves every conversation locally.
461
462```bash theme={null}
463claude --continue
464```
465
466This resumes the most recent session in the current directory; if there isn't one yet, it prints `No conversation found to continue` and exits. Use `claude --resume` to choose from a list, or `/resume` from inside a running session. See [Manage sessions](/en/sessions) for naming, branching, and the full picker reference.
467
468## Run parallel sessions with worktrees
469
470Work on a feature in one terminal while Claude fixes a bug in another, without the edits colliding. Each worktree is a separate checkout on its own branch.
471
472```bash theme={null}
473claude --worktree feature-auth
474```
475
476Run the same command with a different name in a second terminal to start an isolated parallel session. See [Worktrees](/en/worktrees) for cleanup, `.worktreeinclude`, and non-git VCS support.
477
478## Plan before editing
479
480For changes you want to review before they touch disk, switch to plan mode. Claude reads files and proposes a plan but makes no edits until you approve.
481
482```bash theme={null}
483claude --permission-mode plan
484```
485
486You can also press `Shift+Tab` mid-session to toggle into plan mode. See [Plan mode](/en/permission-modes#analyze-before-you-edit-with-plan-mode) for the approval flow and editing the plan in your text editor.
487
488## Delegate research to subagents
489
490Exploring a large codebase fills your context with file reads. Delegate the exploration so only the findings come back.
491
492```text theme={null}
493use a subagent to investigate how our auth system handles token refresh
494```
495
496The subagent reads files in its own context window and reports a summary. See [Subagents](/en/sub-agents) for defining custom agents with their own tools and prompts.
497
498## Pipe Claude into scripts
499
500Run Claude non-interactively for CI, pre-commit hooks, or batch processing. Stdin and stdout work like any Unix tool.
501
502```bash theme={null}
503git log --oneline -20 | claude -p "summarize these recent commits"
504```
505
506See [Non-interactive mode](/en/headless) for output formats, permission flags, and fan-out patterns.
507
1012## Next steps508## Next steps
1013 509
1014<CardGroup cols={2}>510<CardGroup cols={2}>
1016 Patterns for getting the most out of Claude Code512 Patterns for getting the most out of Claude Code
1017 </Card>513 </Card>
1018 514
1019 <Card title="How Claude Code works" icon="gear" href="/en/how-claude-code-works">515 <Card title="Manage sessions" icon="rotate-left" href="/en/sessions">
1020 Understand the agentic loop and context management516 Resume, name, and branch conversations
1021 </Card>517 </Card>
1022 518
1023 <Card title="Extend Claude Code" icon="puzzle-piece" href="/en/features-overview">519 <Card title="Worktrees" icon="code-branch" href="/en/worktrees">
1024 Add skills, hooks, MCP, subagents, and plugins520 Run isolated parallel sessions
1025 </Card>521 </Card>
1026 522
1027 <Card title="Reference implementation" icon="code" href="https://github.com/anthropics/claude-code/tree/main/.devcontainer">523 <Card title="Extend Claude Code" icon="puzzle-piece" href="/en/features-overview">
1028 Clone the development container reference implementation524 Add skills, hooks, MCP, subagents, and plugins
1029 </Card>525 </Card>
1030</CardGroup>526</CardGroup>