modified
--- a/common-workflows.md +++ b/common-workflows.md @@ -351,7 +351,7 @@ [Cloud scheduled tasks](</docs/en/routines>)| Cloud, Anthropic-managed by default| Tasks that should run even when your computer is off. Can also trigger on API calls or GitHub events in addition to a schedule. Configure at [claude.ai/code/routines](<https://claude.ai/code/routines>). [Desktop scheduled tasks](</docs/en/desktop-scheduled-tasks>)| Your machine, via the desktop app| Tasks that need direct access to local files, tools, or uncommitted changes. [GitHub Actions](</docs/en/github-actions>)| Your CI pipeline| Tasks tied to repo events like opened PRs, or cron schedules that should live alongside your workflow config. -[`/loop`](</docs/en/scheduled-tasks>)| The current CLI session| Quick polling while a session is open. `--resume` and `--continue` restore unexpired fixed-interval loops. +[`/loop`](</docs/en/scheduled-tasks>)| The current CLI session| Quick polling while a session is open. When writing prompts for scheduled tasks, be explicit about what success looks like and what to do with results. The task runs autonomously, so it can’t ask clarifying questions. For example: “Review open PRs labeled `needs-review`, leave inline comments on any issues, and post a summary in the `#eng-reviews` Slack channel.”
modified
--- a/common-workflows.md +++ b/common-workflows.md @@ -325,7 +325,7 @@ Show me the data from @github:repos/owner/repo/issues -This fetches data from connected MCP servers using the format @server:resource. See [MCP resources](</docs/en/mcp#use-mcp-resources>) for details. +See [MCP resources](</docs/en/mcp#use-mcp-resources>) for details. Tips: @@ -418,7 +418,7 @@ ## Pipe Claude into scripts -Run Claude non-interactively for CI, pre-commit hooks, or batch processing. Stdin and stdout work like any Unix tool. +Run Claude non-interactively for CI, pre-commit hooks, or batch processing. git log --oneline -20 | claude -p "summarize these recent commits"
modified
Show diff (261 lines)
--- a/common-workflows.md +++ b/common-workflows.md @@ -7,27 +7,15 @@ * Delegate research to subagents to keep your main context clean * Pipe Claude into scripts for CI and batch processing -## - -​ - -Prompt recipes +## Prompt recipes These 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. -### - -​ - -Understand new codebases +### Understand new codebases For configuring Claude Code in a monorepo or large codebase, see [Monorepos and large repos](</docs/en/large-codebases>). -#### - -​ - -Get a quick codebase overview +#### Get a quick codebase overview Suppose you’ve just joined a new project and need to understand its structure quickly. @@ -67,11 +55,7 @@ * Ask about coding conventions and patterns used in the project * Request a glossary of project-specific terms -#### - -​ - -Find relevant code +#### Find relevant code Suppose you need to locate code related to a specific feature or functionality. @@ -101,11 +85,7 @@ * * * -### - -​ - -Fix bugs efficiently +### Fix bugs efficiently Suppose you’ve encountered an error message and need to find and fix its source. @@ -135,11 +115,7 @@ * * * -### - -​ - -Refactor code +### Refactor code Suppose you need to update old code to use modern patterns and practices. For porting an entire codebase to a new language, see [how Anthropic runs large-scale code migrations with Claude Code](<https://claude.com/blog/ai-code-migration>) on the blog. @@ -175,11 +151,7 @@ * * * -### - -​ - -Work with tests +### Work with tests Suppose you need to add tests for uncovered code. @@ -211,11 +183,7 @@ * * * -### - -​ - -Create pull requests +### Create pull requests You can create pull requests by asking Claude directly (“create a pr for my changes”), or guide Claude through it step-by-step: @@ -241,11 +209,7 @@ Review Claude’s generated PR before submitting and ask Claude to highlight potential risks or considerations. -### - -​ - -Handle documentation +### Handle documentation Suppose you need to add or update documentation for your code. @@ -281,21 +245,13 @@ * * * -### - -​ - -Work in notes and non-code folders +### Work in notes and non-code folders Claude 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. The `.claude/` directory and `CLAUDE.md` sit alongside other tools’ config directories without conflict. Claude reads files fresh on each tool call, so it sees edits you make in another application the next time it reads that file. * * * -### - -​ - -Work with images +### Work with images Suppose you need to work with images in your codebase, and you want Claude’s help analyzing image content. @@ -345,11 +301,7 @@ * * * -### - -​ - -Reference files and directories +### Reference files and directories Use @ to quickly include files or directories without waiting for Claude to read them. @@ -390,11 +342,7 @@ * * * -### - -​ - -Run Claude on a schedule +### Run Claude on a schedule Suppose 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. Pick a scheduling option based on where you want the task to run: @@ -409,19 +357,11 @@ * * * -### - -​ - -Ask Claude about its capabilities +### Ask Claude about its capabilities Claude can answer questions about its own features and limitations. It looks up the answers in the current Claude Code documentation, so they aren’t limited to the version you’re running. -#### - -​ - -Example questions +#### Example questions can Claude Code create pull requests? @@ -444,11 +384,7 @@ * * * -## - -​ - -Resume previous conversations +## Resume previous conversations When a task spans multiple sittings, pick up where you left off instead of re-explaining context. Claude Code saves every conversation locally. @@ -456,11 +392,7 @@ This 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](</docs/en/sessions>) for naming, branching, and the full picker reference. -## - -​ - -Run parallel sessions with worktrees +## Run parallel sessions with worktrees Work on a feature in one terminal while Claude fixes a bug in another, without the edits colliding. Each [git worktree](<https://git-scm.com/docs/git-worktree>) is a separate checkout on its own branch, created from an existing commit, so the repository needs at least one commit first. @@ -468,11 +400,7 @@ Run the same command with a different name in a second terminal to start an isolated parallel session. See [Worktrees](</docs/en/worktrees>) for cleanup, `.worktreeinclude`, and non-git VCS support. To monitor parallel sessions from one screen instead of separate terminals, see [background agents](</docs/en/agent-view>). -## - -​ - -Plan before editing +## Plan before editing For 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. The status bar shows `⏸ plan mode on` while plan mode is active. @@ -480,11 +408,7 @@ You can also press `Shift+Tab` mid-session until the status bar shows `⏸ plan mode on`. See [Plan mode](</docs/en/permission-modes#analyze-before-you-edit-with-plan-mode>) for the approval flow and editing the plan in your text editor. -## - -​ - -Delegate research to subagents +## Delegate research to subagents Exploring a large codebase fills your context with file reads. Delegate the exploration so only the findings come back. @@ -492,11 +416,7 @@ The subagent reads files in its own context window and reports a summary. See [Subagents](</docs/en/sub-agents>) for defining custom agents with their own tools and prompts. -## - -​ - -Pipe Claude into scripts +## Pipe Claude into scripts Run Claude non-interactively for CI, pre-commit hooks, or batch processing. Stdin and stdout work like any Unix tool. @@ -504,11 +424,7 @@ See [Non-interactive mode](</docs/en/headless>) for output formats, permission flags, and fan-out patterns. -## - -​ - -Next steps +## Next steps ## Best practices
modified
--- a/common-workflows.md +++ b/common-workflows.md @@ -466,7 +466,7 @@ claude --worktree feature-auth -Run the same command with a different name in a second terminal to start an isolated parallel session. In a repository with no commits, the command fails with `Failed to resolve base branch "HEAD": git rev-parse failed`. See [Worktrees](</docs/en/worktrees>) for cleanup, `.worktreeinclude`, and non-git VCS support. To monitor parallel sessions from one screen instead of separate terminals, see [background agents](</docs/en/agent-view>). +Run the same command with a different name in a second terminal to start an isolated parallel session. See [Worktrees](</docs/en/worktrees>) for cleanup, `.worktreeinclude`, and non-git VCS support. To monitor parallel sessions from one screen instead of separate terminals, see [background agents](</docs/en/agent-view>). ##
modified
--- a/common-workflows.md +++ b/common-workflows.md @@ -383,7 +383,10 @@ * Directory references show file listings, not contents * You can reference multiple files in a single message (for example, “@file1.js and @file2.js”) -To stop `@` references from including file contents and directory listings in your message, set [`CLAUDE_CODE_DISABLE_FILE_MENTIONS=1`](</docs/en/env-vars#variables>) in your shell or user settings. Claude then receives the paths you referenced with a note to read them using its file tools. The variable requires Claude Code v2.1.299 or later, and Claude Code ignores it in project and local settings. +To stop `@` references from including file contents and directory listings, set [`CLAUDE_CODE_DISABLE_FILE_MENTIONS`](</docs/en/env-vars#variables>) to `1` in your shell or in the [`env` block](</docs/en/env-vars#set-variables-in-settings-files>) of user settings or [managed settings](</docs/en/managed-settings>). Claude then receives the paths you referenced with a note to read them using its file tools. The variable requires Claude Code v2.1.299 or later, and Claude Code ignores it in project and local settings. Your [`PreToolUse` hooks](</docs/en/hooks#pretooluse>) don’t run when Claude Code includes a file you reference with `@`, because it makes no tool call. If you rely on those hooks to control what Claude reads, block specific paths or stop `@` references from including files: + + * **Block specific paths** : add a [`Read` deny rule](</docs/en/permissions#read-and-edit>) for them. Claude Code doesn’t include a file that the rule matches. + * **Stop`@` references from including files**: set `CLAUDE_CODE_DISABLE_FILE_MENTIONS=1`, which stops `@` file and directory references in your messages from including content, even for paths your hooks don’t check. Your matching hooks then run before Claude opens a referenced path with a tool such as `Read`. * * *
modified
--- a/common-workflows.md +++ b/common-workflows.md @@ -397,7 +397,7 @@ Option| Where it runs| Best for ---|---|--- -[Routines](</docs/en/routines>)| Cloud, Anthropic-managed by default| Tasks that should run even when your computer is off. Can also trigger on API calls or GitHub events in addition to a schedule. Configure at [claude.ai/code/routines](<https://claude.ai/code/routines>). +[Cloud scheduled tasks](</docs/en/routines>)| Cloud, Anthropic-managed by default| Tasks that should run even when your computer is off. Can also trigger on API calls or GitHub events in addition to a schedule. Configure at [claude.ai/code/routines](<https://claude.ai/code/routines>). [Desktop scheduled tasks](</docs/en/desktop-scheduled-tasks>)| Your machine, via the desktop app| Tasks that need direct access to local files, tools, or uncommitted changes. [GitHub Actions](</docs/en/github-actions>)| Your CI pipeline| Tasks tied to repo events like opened PRs, or cron schedules that should live alongside your workflow config. [`/loop`](</docs/en/scheduled-tasks>)| The current CLI session| Quick polling while a session is open. `--resume` and `--continue` restore unexpired fixed-interval loops.
modified
--- a/common-workflows.md +++ b/common-workflows.md @@ -383,6 +383,8 @@ * Directory references show file listings, not contents * You can reference multiple files in a single message (for example, “@file1.js and @file2.js”) +To stop `@` references from including file contents and directory listings in your message, set [`CLAUDE_CODE_DISABLE_FILE_MENTIONS=1`](</docs/en/env-vars#variables>) in your shell or user settings. Claude then receives the paths you referenced with a note to read them using its file tools. The variable requires Claude Code v2.1.299 or later, and Claude Code ignores it in project and local settings. + * * * ###
modified
--- a/common-workflows.md +++ b/common-workflows.md @@ -410,7 +410,7 @@ Ask Claude about its capabilities -Claude has built-in access to its documentation and can answer questions about its own features and limitations. +Claude can answer questions about its own features and limitations. It looks up the answers in the current Claude Code documentation, so they aren’t limited to the version you’re running. #### @@ -434,7 +434,6 @@ Tips: - * Claude always has access to the latest Claude Code documentation, regardless of the version you’re using * Ask specific questions to get detailed answers * Claude can explain complex features like MCP integration, enterprise configurations, and advanced workflows
modified
--- a/common-workflows.md +++ b/common-workflows.md @@ -359,7 +359,7 @@ Explain the logic in @src/utils/auth.js -This includes the full content of the file in the conversation. +This includes the content of the file in the conversation when it fits the [Read tool](</docs/en/tools-reference#read-tool-behavior>)’s token limit, 25,000 tokens by default. A text file larger than 256KB isn’t included. 2
modified
--- a/common-workflows.md +++ b/common-workflows.md @@ -207,7 +207,7 @@ run the new tests and fix any failures -Claude can generate tests that follow your project’s existing patterns and conventions. When asking for tests, be specific about what behavior you want to verify. Claude examines your existing test files to match the style, frameworks, and assertion patterns already in use. For comprehensive coverage, ask Claude to identify edge cases you might have missed. Claude can analyze your code paths and suggest tests for error conditions, boundary values, and unexpected inputs that are easy to overlook. +Claude can generate tests that follow your project’s existing patterns and conventions. When asking for tests, be specific about what behavior you want to verify. Claude examines your existing test files to match the style, frameworks, and assertion patterns already in use. To improve coverage, ask Claude to identify edge cases you might have missed. Claude can analyze your code paths and suggest tests for error conditions, boundary values, and unexpected inputs that are often overlooked. * * *
modified
--- a/common-workflows.md +++ b/common-workflows.md @@ -97,7 +97,7 @@ * Be specific about what you’re looking for * Use domain language from the project - * Install a [code intelligence plugin](</docs/en/discover-plugins#code-intelligence>) for your language to give Claude precise “go to definition” and “find references” navigation + * Install a [code intelligence plugin](</docs/en/plugins/code-intelligence>) for your language to give Claude precise “go to definition” and “find references” navigation * * *
modified
--- a/common-workflows.md +++ b/common-workflows.md @@ -307,7 +307,7 @@ 1. Drag and drop an image into the Claude Code window 2. Copy an image and paste it into the CLI with `Ctrl+V`, or with [`Alt+V` on Windows and WSL](</docs/en/interactive-mode#general-controls>) - 3. Provide an image path to Claude. E.g., “Analyze this image: /path/to/your/image.png” + 3. Provide an image path to Claude, for example “Analyze this image: /path/to/your/image.png” 2
modified
--- a/common-workflows.md +++ b/common-workflows.md @@ -398,7 +398,7 @@ [Routines](</docs/en/routines>)| Cloud, Anthropic-managed by default| Tasks that should run even when your computer is off. Can also trigger on API calls or GitHub events in addition to a schedule. Configure at [claude.ai/code/routines](<https://claude.ai/code/routines>). [Desktop scheduled tasks](</docs/en/desktop-scheduled-tasks>)| Your machine, via the desktop app| Tasks that need direct access to local files, tools, or uncommitted changes. [GitHub Actions](</docs/en/github-actions>)| Your CI pipeline| Tasks tied to repo events like opened PRs, or cron schedules that should live alongside your workflow config. -[`/loop`](</docs/en/scheduled-tasks>)| The current CLI session| Quick polling while a session is open. Tasks stop when you start a new conversation; `--resume` and `--continue` restore unexpired ones. +[`/loop`](</docs/en/scheduled-tasks>)| The current CLI session| Quick polling while a session is open. `--resume` and `--continue` restore unexpired fixed-interval loops. When writing prompts for scheduled tasks, be explicit about what success looks like and what to do with results. The task runs autonomously, so it can’t ask clarifying questions. For example: “Review open PRs labeled `needs-review`, leave inline comments on any issues, and post a summary in the `#eng-reviews` Slack channel.”
modified
--- a/common-workflows.md +++ b/common-workflows.md @@ -237,7 +237,7 @@ enhance the PR description with more context about the security improvements -When you create a PR using `gh pr create`, the session is automatically linked to that PR. To find it later, run `claude --from-pr 1234` with your own PR number, which opens the session picker filtered to sessions linked to that PR, or paste the PR URL into the [`/resume` picker](</docs/en/sessions#use-the-session-picker>) search. +To find the session later, run `claude --from-pr 1234` with your own PR number, which opens the session picker filtered to sessions linked to that PR, or paste the PR URL into the [`/resume` picker](</docs/en/sessions#use-the-session-picker>) search. Claude Code links the session to the PR when Claude creates it with `gh pr create` or `glab mr create`, and when Claude [works on an existing PR](</docs/en/agent-view#pull-request-status>). Review Claude’s generated PR before submitting and ask Claude to highlight potential risks or considerations. @@ -306,7 +306,7 @@ You can use any of these methods: 1. Drag and drop an image into the Claude Code window - 2. Copy an image and paste it into the CLI with Ctrl+V. On macOS, Cmd+V also works in iTerm2. + 2. Copy an image and paste it into the CLI with `Ctrl+V`, or with [`Alt+V` on Windows and WSL](</docs/en/interactive-mode#general-controls>) 3. Provide an image path to Claude. E.g., “Analyze this image: /path/to/your/image.png” 2 @@ -366,8 +366,6 @@ Reference a directory What's the structure of @src/components? - -This provides a directory listing with file information. 3
modified
--- a/common-workflows.md +++ b/common-workflows.md @@ -476,7 +476,7 @@ claude --permission-mode plan -You can also press `Shift+Tab` mid-session to cycle to plan mode. The cycle runs `default` → `acceptEdits` → `plan`. See [Plan mode](</docs/en/permission-modes#analyze-before-you-edit-with-plan-mode>) for the approval flow and editing the plan in your text editor. +You can also press `Shift+Tab` mid-session until the status bar shows `⏸ plan mode on`. See [Plan mode](</docs/en/permission-modes#analyze-before-you-edit-with-plan-mode>) for the approval flow and editing the plan in your text editor. ##
modified
--- a/common-workflows.md +++ b/common-workflows.md @@ -397,7 +397,7 @@ Option| Where it runs| Best for ---|---|--- -[Routines](</docs/en/routines>)| Anthropic-managed infrastructure| Tasks that should run even when your computer is off. Can also trigger on API calls or GitHub events in addition to a schedule. Configure at [claude.ai/code/routines](<https://claude.ai/code/routines>). +[Routines](</docs/en/routines>)| Cloud, Anthropic-managed by default| Tasks that should run even when your computer is off. Can also trigger on API calls or GitHub events in addition to a schedule. Configure at [claude.ai/code/routines](<https://claude.ai/code/routines>). [Desktop scheduled tasks](</docs/en/desktop-scheduled-tasks>)| Your machine, via the desktop app| Tasks that need direct access to local files, tools, or uncommitted changes. [GitHub Actions](</docs/en/github-actions>)| Your CI pipeline| Tasks tied to repo events like opened PRs, or cron schedules that should live alongside your workflow config. [`/loop`](</docs/en/scheduled-tasks>)| The current CLI session| Quick polling while a session is open. Tasks stop when you start a new conversation; `--resume` and `--continue` restore unexpired ones.
modified
--- a/common-workflows.md +++ b/common-workflows.md @@ -141,7 +141,7 @@ Refactor code -Suppose you need to update old code to use modern patterns and practices. +Suppose you need to update old code to use modern patterns and practices. For porting an entire codebase to a new language, see [how Anthropic runs large-scale code migrations with Claude Code](<https://claude.com/blog/ai-code-migration>) on the blog. 1
modified
--- a/common-workflows.md +++ b/common-workflows.md @@ -37,6 +37,8 @@ cd /path/to/project +Replace `/path/to/project` with the path to your project. + 2 Start Claude Code @@ -235,7 +237,7 @@ enhance the PR description with more context about the security improvements -When 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 123`, replacing 123 with the PR number, or paste the PR URL into the [`/resume` picker](</docs/en/sessions#use-the-session-picker>) search. +When you create a PR using `gh pr create`, the session is automatically linked to that PR. To find it later, run `claude --from-pr 1234` with your own PR number, which opens the session picker filtered to sessions linked to that PR, or paste the PR URL into the [`/resume` picker](</docs/en/sessions#use-the-session-picker>) search. Review Claude’s generated PR before submitting and ask Claude to highlight potential risks or considerations. @@ -378,6 +380,7 @@ Tips: * File paths can be relative or absolute + * Type `@` to open a path suggestion menu, then press Enter or Tab to accept the highlighted path and Enter again to send the message * @ file references add `CLAUDE.md` in the file’s directory and parent directories to context * Directory references show file listings, not contents * You can reference multiple files in a single message (for example, “@file1.js and @file2.js”) @@ -457,11 +460,11 @@ Run parallel sessions with worktrees -Work 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. +Work on a feature in one terminal while Claude fixes a bug in another, without the edits colliding. Each [git worktree](<https://git-scm.com/docs/git-worktree>) is a separate checkout on its own branch, created from an existing commit, so the repository needs at least one commit first. claude --worktree feature-auth -Run the same command with a different name in a second terminal to start an isolated parallel session. See [Worktrees](</docs/en/worktrees>) for cleanup, `.worktreeinclude`, and non-git VCS support. To monitor parallel sessions from one screen instead of separate terminals, see [background agents](</docs/en/agent-view>). +Run the same command with a different name in a second terminal to start an isolated parallel session. In a repository with no commits, the command fails with `Failed to resolve base branch "HEAD": git rev-parse failed`. See [Worktrees](</docs/en/worktrees>) for cleanup, `.worktreeinclude`, and non-git VCS support. To monitor parallel sessions from one screen instead of separate terminals, see [background agents](</docs/en/agent-view>). ## @@ -469,11 +472,11 @@ Plan before editing -For 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. +For 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. The status bar shows `⏸ plan mode on` while plan mode is active. claude --permission-mode plan -You can also press `Shift+Tab` mid-session to toggle into plan mode. See [Plan mode](</docs/en/permission-modes#analyze-before-you-edit-with-plan-mode>) for the approval flow and editing the plan in your text editor. +You can also press `Shift+Tab` mid-session to cycle to plan mode. The cycle runs `default` → `acceptEdits` → `plan`. See [Plan mode](</docs/en/permission-modes#analyze-before-you-edit-with-plan-mode>) for the approval flow and editing the plan in your text editor. ##
modified
--- a/common-workflows.md +++ b/common-workflows.md @@ -304,7 +304,7 @@ You can use any of these methods: 1. Drag and drop an image into the Claude Code window - 2. Copy an image and paste it into the CLI with ctrl+v (Do not use cmd+v) + 2. Copy an image and paste it into the CLI with Ctrl+V. On macOS, Cmd+V also works in iTerm2. 3. Provide an image path to Claude. E.g., “Analyze this image: /path/to/your/image.png” 2
modified
--- a/common-workflows.md +++ b/common-workflows.md @@ -235,7 +235,7 @@ enhance the PR description with more context about the security improvements -When 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](</docs/en/sessions#use-the-session-picker>) search. +When 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 123`, replacing 123 with the PR number, or paste the PR URL into the [`/resume` picker](</docs/en/sessions#use-the-session-picker>) search. Review Claude’s generated PR before submitting and ask Claude to highlight potential risks or considerations.
modified
--- a/common-workflows.md +++ b/common-workflows.md @@ -1,9 +1,3 @@ -> ## Documentation Index -> -> Fetch the complete documentation index at: <https://code.claude.com/docs/llms.txt> -> -> Use this file to discover all available pages before exploring further. - This page collects short recipes for everyday development. For higher-level guidance on prompting and context management, see [Best practices](</docs/en/best-practices>). This page covers: * Prompt recipes for exploring code, fixing bugs, refactoring, testing, PRs, and documentation
modified
--- a/common-workflows.md +++ b/common-workflows.md @@ -27,6 +27,8 @@ Understand new codebases +For configuring Claude Code in a monorepo or large codebase, see [Monorepos and large repos](</docs/en/large-codebases>). + #### ​
modified
--- a/common-workflows.md +++ b/common-workflows.md @@ -465,7 +465,7 @@ claude --worktree feature-auth -Run the same command with a different name in a second terminal to start an isolated parallel session. See [Worktrees](</docs/en/worktrees>) for cleanup, `.worktreeinclude`, and non-git VCS support. +Run the same command with a different name in a second terminal to start an isolated parallel session. See [Worktrees](</docs/en/worktrees>) for cleanup, `.worktreeinclude`, and non-git VCS support. To monitor parallel sessions from one screen instead of separate terminals, see [background agents](</docs/en/agent-view>). ##
modified
Show diff (833 lines)
--- a/common-workflows.md +++ b/common-workflows.md @@ -4,15 +4,30 @@ > > Use this file to discover all available pages before exploring further. -This 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](</docs/en/best-practices>). - -## +This page collects short recipes for everyday development. For higher-level guidance on prompting and context management, see [Best practices](</docs/en/best-practices>). This page covers: + + * Prompt recipes for exploring code, fixing bugs, refactoring, testing, PRs, and documentation + * Resume previous conversations so a task can span multiple sittings + * Run parallel sessions with worktrees so concurrent edits don’t collide + * Plan before editing to review changes before they touch disk + * Delegate research to subagents to keep your main context clean + * Pipe Claude into scripts for CI and batch processing + +## + +​ + +Prompt recipes + +These 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. + +### ​ Understand new codebases -### +#### ​ @@ -54,7 +69,7 @@ * Ask about coding conventions and patterns used in the project * Request a glossary of project-specific terms -### +#### ​ @@ -88,7 +103,7 @@ * * * -## +### ​ @@ -122,7 +137,7 @@ * * * -## +### ​ @@ -162,159 +177,34 @@ * * * -## - -​ - -Use specialized subagents - -Suppose you want to use specialized AI subagents to handle specific tasks more effectively. - -1 - -View available subagents - - /agents - -This shows all available subagents and lets you create new ones. - -2 - -Use subagents automatically - -Claude Code automatically delegates appropriate tasks to specialized subagents: - - review my recent code changes for security issues - - run all tests and fix any failures - -3 - -Explicitly request specific subagents - - use the code-reviewer subagent to check the auth module - - have the debugger subagent investigate why users can't log in +### + +​ + +Work with tests + +Suppose you need to add tests for uncovered code. + +1 + +Identify untested code + + find functions in NotificationsService.swift that are not covered by tests + +2 + +Generate test scaffolding + + add tests for the notification service + +3 + +Add meaningful test cases + + add test cases for edge conditions in the notification service 4 -Create custom subagents for your workflow - - /agents - -Then select “Create New subagent” and follow the prompts to define: - - * A unique identifier that describes the subagent’s purpose (for example, `code-reviewer`, `api-designer`). - * When Claude should use this agent - * Which tools it can access - * A system prompt describing the agent’s role and behavior - -Tips: - - * Create project-specific subagents in `.claude/agents/` for team sharing - * Use descriptive `description` fields to enable automatic delegation - * Limit tool access to what each subagent actually needs - * Check the [subagents documentation](</docs/en/sub-agents>) for detailed examples - -* * * - -## - -​ - -Use Plan Mode for safe code analysis - -Plan 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`](</docs/en/tools-reference>) to gather requirements and clarify your goals before proposing a plan. - -### - -​ - -When to use Plan Mode - - * **Multi-step implementation** : When your feature requires making edits to many files - * **Code exploration** : When you want to research the codebase thoroughly before changing anything - * **Interactive development** : When you want to iterate on the direction with Claude - -### - -​ - -How to use Plan Mode - -**Turn on Plan Mode during a session** You can switch into Plan Mode during a session using **Shift+Tab** to cycle through permission modes. If 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`. **Start a new session in Plan Mode** To start a new session in Plan Mode, use the `--permission-mode plan` flag: - - claude --permission-mode plan - -**Run “headless” queries in Plan Mode** You can also run a query in Plan Mode directly with `-p` (that is, in [“headless mode”](</docs/en/headless>)): - - claude --permission-mode plan -p "Analyze the authentication system and suggest improvements" - -### - -​ - -Example: Planning a complex refactor - - claude --permission-mode plan - - I need to refactor our authentication system to use OAuth2. Create a detailed migration plan. - -Claude analyzes the current implementation and create a comprehensive plan. Refine with follow-ups: - - What about backward compatibility? - - How should we handle database migration? - -Press `Ctrl+G` to open the plan in your default text editor, where you can edit it directly before Claude proceeds. - -When 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. - -### - -​ - -Configure Plan Mode as default - - // .claude/settings.json - { - "permissions": { - "defaultMode": "plan" - } - } - -See [settings documentation](</docs/en/settings#available-settings>) for more configuration options. - -* * * - -## - -​ - -Work with tests - -Suppose you need to add tests for uncovered code. - -1 - -Identify untested code - - find functions in NotificationsService.swift that are not covered by tests - -2 - -Generate test scaffolding - - add tests for the notification service - -3 - -Add meaningful test cases - - add test cases for edge conditions in the notification service - -4 - Run and verify tests run the new tests and fix any failures @@ -323,7 +213,7 @@ * * * -## +### ​ @@ -349,11 +239,11 @@ enhance the PR description with more context about the security improvements -When 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 search. +When 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](</docs/en/sessions#use-the-session-picker>) search. Review Claude’s generated PR before submitting and ask Claude to highlight potential risks or considerations. -## +### ​ @@ -393,7 +283,7 @@ * * * -## +### ​ @@ -403,7 +293,7 @@ * * * -## +### ​ @@ -457,7 +347,7 @@ * * * -## +### ​ @@ -498,426 +388,7 @@ * * * -## - -​ - -Use extended thinking (thinking mode) - -[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. Additionally, [models that support effort](</docs/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. Extended thinking is particularly valuable for complex architectural decisions, challenging bugs, multi-step implementation planning, and evaluating tradeoffs between different approaches. - -Phrases like “think”, “think hard”, and “think more” are interpreted as regular prompt instructions and don’t allocate thinking tokens. - -### - -​ - -Configure thinking mode - -Thinking is enabled by default, but you can adjust or disable it. - -Scope| How to configure| Details ----|---|--- -**Effort level**| Run `/effort`, adjust in `/model`, or set [`CLAUDE_CODE_EFFORT_LEVEL`](</docs/en/env-vars>)| Control thinking depth on [supported models](</docs/en/model-config#adjust-effort-level>) -**`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](</docs/en/model-config#adjust-effort-level>) for that -**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](</docs/en/terminal-config>) to enable Option key shortcuts -**Global default**| Use `/config` to toggle thinking mode| Sets your default across all projects (all models). -Saved as `alwaysThinkingEnabled` in `~/.claude/settings.json` -**Limit token budget**| Set [`MAX_THINKING_TOKENS`](</docs/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` - -To view Claude’s thinking process, press `Ctrl+O` to toggle verbose mode and see the internal reasoning displayed as gray italic text. - -### - -​ - -How extended thinking works - -Extended 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. On [models that support effort](</docs/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`. With older models, thinking uses a fixed token budget drawn from your output allocation. The budget varies by model; see [`MAX_THINKING_TOKENS`](</docs/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. On 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](</docs/en/env-vars>). - -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. - -* * * - -## - -​ - -Resume previous conversations - -When starting Claude Code, you can resume a previous session: - - * `claude --continue` continues the most recent conversation in the current directory - * `claude --resume` opens a conversation picker or resumes by name - * `claude --from-pr 123` resumes sessions linked to a specific pull request - -From inside an active session, use `/resume` to switch to a different conversation. When 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. Sessions 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 below for the full shortcut reference. When 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. Resuming 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. When 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. Sessions 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>`. - -### - -​ - -Name your sessions - -Give sessions descriptive names to find them later. This is a best practice when working on multiple tasks or features. - -1 - -Name the session - -Name a session at startup with `-n`: - - claude -n auth-refactor - -Or use `/rename` during a session, which also shows the name on the prompt bar: - - /rename auth-refactor - -You can also rename any session from the picker: run `/resume`, navigate to a session, and press `Ctrl+R`. - -2 - -Resume by name later - -From the command line: - - claude --resume auth-refactor - -Or from inside an active session: - - /resume auth-refactor - -### - -​ - -Use the session picker - -The `/resume` command (or `claude --resume` without arguments) opens an interactive session picker with these features: **Keyboard shortcuts in the picker:** - -Shortcut| Action ----|--- -`↑` / `↓`| Navigate between sessions -`→` / `←`| Expand or collapse grouped sessions -`Enter`| Select and resume the highlighted session -`Space`| Preview the session content. `Ctrl+V` also works on terminals that do not capture it as paste -`Ctrl+R`| Rename the highlighted session -`/` 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 -`Ctrl+A`| Show sessions from all projects on this machine. Press again to restore the current repository -`Ctrl+W`| Show sessions from all worktrees of the current repository. Press again to restore the current worktree. Only shown in multi-worktree repositories -`Ctrl+B`| Filter to sessions from your current git branch. Press again to show sessions from all branches -`Esc`| Exit the picker or search mode - -**Session organization:** The picker displays sessions with helpful metadata: - - * Session name if set, otherwise the conversation summary or first user prompt - * Time elapsed since last activity - * Message count - * Git branch (if applicable) - * Project path, shown after widening to all projects with `Ctrl+A` - -Forked sessions (created with `/branch`, `/rewind`, or `--fork-session`) are grouped together under their root session, making it easier to find related conversations. - -Tips: - - * **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 - * Use `--continue` for quick access to your most recent conversation in the current directory - * Use `--resume session-name` when you know which session you need - * Use `--resume` (without a name) when you need to browse and select - * For scripts, use `claude --continue --print "prompt"` to resume in non-interactive mode - * Press `Space` in the picker to preview a session before resuming it - * The resumed conversation starts with the same model and configuration as the original - -How it works: - - 1. **Conversation Storage** : All conversations are automatically saved locally with their full message history - 2. **Message Deserialization** : When resuming, the entire message history is restored to maintain context - 3. **Tool State** : Tool usage and results from the previous conversation are preserved - 4. **Context Restoration** : The conversation resumes with all previous context intact - -* * * - -## - -​ - -Run parallel Claude Code sessions with Git worktrees - -When 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. Use 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: - - # Start Claude in a worktree named "feature-auth" - # Creates .claude/worktrees/feature-auth/ with a new branch - claude --worktree feature-auth - - # Start another session in a separate worktree - claude --worktree bugfix-123 - -If you omit the name, Claude generates a random one automatically: - - # Auto-generates a name like "bright-running-fox" - claude --worktree - -Worktrees 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>`. The 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: - - git remote set-head origin -a - -This 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`. For full control over how worktrees are created, including choosing a different base per invocation, configure a [WorktreeCreate hook](</docs/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. You can also ask Claude to “work in a worktree” or “start a worktree” during a session, and it will create one automatically. - -### - -​ - -Subagent worktrees - -Subagents 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](</docs/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. - -### - -​ - -Worktree cleanup - -When you exit a worktree session, Claude handles cleanup based on whether you made changes: - - * **No changes** : the worktree and its branch are removed automatically - * **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 - -Subagent worktrees orphaned by a crash or an interrupted parallel run are removed automatically at startup once they are older than your [`cleanupPeriodDays`](</docs/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. To clean up worktrees outside of a Claude session, use manual worktree management. - -Add `.claude/worktrees/` to your `.gitignore` to prevent worktree contents from appearing as untracked files in your main repository. - -### - -​ - -Copy gitignored files to worktrees - -Git 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. The 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. - -.worktreeinclude - - .env - .env.local - config/secrets.json - -This applies to worktrees created with `--worktree`, subagent worktrees, and parallel sessions in the [desktop app](</docs/en/desktop#work-in-parallel-with-sessions>). - -### - -​ - -Manage worktrees manually - -For 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. - - # Create a worktree with a new branch - git worktree add ../project-feature-a -b feature-a - - # Create a worktree with an existing branch - git worktree add ../project-bugfix bugfix-123 - - # Start Claude in the worktree - cd ../project-feature-a && claude - - # Clean up when done - git worktree list - git worktree remove ../project-feature-a - -Learn more in the [official Git worktree documentation](<https://git-scm.com/docs/git-worktree>). - -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. - -### - -​ - -Non-git version control - -Worktree isolation works with git by default. For other version control systems like SVN, Perforce, or Mercurial, configure [WorktreeCreate and WorktreeRemove hooks](</docs/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` is not processed. Copy any local configuration files inside your hook script instead. For automated coordination of parallel sessions with shared tasks and messaging, see [agent teams](</docs/en/agent-teams>). - -* * * - -## - -​ - -Get notified when Claude needs your attention - -When 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](</docs/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. - -1 - -Add the hook to your settings - -Open `~/.claude/settings.json` and add a `Notification` hook that calls your platform’s native notification command: - - * macOS - - * Linux - - * Windows - - { - "hooks": { - "Notification": [ - { - "matcher": "", - "hooks": [ - { - "type": "command", - "command": "osascript -e 'display notification \"Claude Code needs your attention\" with title \"Claude Code\"'" - } - ] - } - ] - } - } - - { - "hooks": { - "Notification": [ - { - "matcher": "", - "hooks": [ - { - "type": "command", - "command": "notify-send 'Claude Code' 'Claude Code needs your attention'" - } - ] - } - ] - } - } - - { - "hooks": { - "Notification": [ - { - "matcher": "", - "hooks": [ - { - "type": "command", - "command": "powershell.exe -Command \"[System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms'); [System.Windows.Forms.MessageBox]::Show('Claude Code needs your attention', 'Claude Code')\"" - } - ] - } - ] - } - } - -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. - -2 - -Optionally narrow the matcher - -By default the hook fires on all notification types. To fire only for specific events, set the `matcher` field to one of these values: - -Matcher| Fires when ----|--- -`permission_prompt`| Claude needs you to approve a tool use -`idle_prompt`| Claude is done and waiting for your next prompt -`auth_success`| Authentication completes -`elicitation_dialog`| An MCP server opens an elicitation form -`elicitation_complete`| An MCP elicitation form is submitted or dismissed -`elicitation_response`| An MCP elicitation response is sent back to the server - -3 - -Verify the hook - -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. - -For the complete event schema and notification types, see the [Notification reference](</docs/en/hooks#notification>). - -* * * - -## - -​ - -Use Claude as a unix-style utility - -### - -​ - -Add Claude to your verification process - -Suppose you want to use Claude Code as a linter or code reviewer. **Add Claude to your build script:** - - // package.json - { - ... - "scripts": { - ... - "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.'" - } - } - -Tips: - - * Use Claude for automated code review in your CI/CD pipeline - * Customize the prompt to check for specific issues relevant to your project - * Consider creating multiple scripts for different types of verification - -### - -​ - -Pipe in, pipe out - -Suppose you want to pipe data into Claude, and get back data in a structured format. **Pipe data through Claude:** - - cat build-error.txt | claude -p 'concisely explain the root cause of this build error' > output.txt - -Tips: - - * Use pipes to integrate Claude into existing shell scripts - * Combine with other Unix tools for powerful workflows - * Consider using `--output-format` for structured output - -### - -​ - -Control output format - -Suppose you need Claude’s output in a specific format, especially when integrating Claude Code into scripts or other tools. - -1 - -Use text format (default) - - cat data.txt | claude -p 'summarize this data' --output-format text > summary.txt - -This outputs just Claude’s plain text response (default behavior). - -2 - -Use JSON format - - cat code.py | claude -p 'analyze this code for bugs' --output-format json > analysis.json - -This outputs a JSON array of messages with metadata including cost and duration. - -3 - -Use streaming JSON format - - cat log.txt | claude -p 'parse this log file for errors' --output-format stream-json - -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. - -Tips: - - * Use `--output-format text` for simple integrations where you just need Claude’s response - * Use `--output-format json` when you need the full conversation log - * Use `--output-format stream-json` for real-time output of each conversation turn - -* * * - -## +### ​ @@ -936,7 +407,7 @@ * * * -## +### ​ @@ -944,7 +415,7 @@ Claude has built-in access to its documentation and can answer questions about its own features and limitations. -### +#### ​ @@ -976,20 +447,80 @@ ​ +Resume previous conversations + +When a task spans multiple sittings, pick up where you left off instead of re-explaining context. Claude Code saves every conversation locally. + + claude --continue + +This 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](</docs/en/sessions>) for naming, branching, and the full picker reference. + +## + +​ + +Run parallel sessions with worktrees + +Work 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. + + claude --worktree feature-auth + +Run the same command with a different name in a second terminal to start an isolated parallel session. See [Worktrees](</docs/en/worktrees>) for cleanup, `.worktreeinclude`, and non-git VCS support. + +## + +​ + +Plan before editing + +For 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. + + claude --permission-mode plan + +You can also press `Shift+Tab` mid-session to toggle into plan mode. See [Plan mode](</docs/en/permission-modes#analyze-before-you-edit-with-plan-mode>) for the approval flow and editing the plan in your text editor. + +## + +​ + +Delegate research to subagents + +Exploring a large codebase fills your context with file reads. Delegate the exploration so only the findings come back. + + use a subagent to investigate how our auth system handles token refresh + +The subagent reads files in its own context window and reports a summary. See [Subagents](</docs/en/sub-agents>) for defining custom agents with their own tools and prompts. + +## + +​ + +Pipe Claude into scripts + +Run Claude non-interactively for CI, pre-commit hooks, or batch processing. Stdin and stdout work like any Unix tool. + + git log --oneline -20 | claude -p "summarize these recent commits" + +See [Non-interactive mode](</docs/en/headless>) for output formats, permission flags, and fan-out patterns. + +## + +​ + Next steps ## Best practices Patterns for getting the most out of Claude Code -## How Claude Code works - -Understand the agentic loop and context management +## Manage sessions + +Resume, name, and branch conversations + +## Worktrees + +Run isolated parallel sessions ## Extend Claude Code Add skills, hooks, MCP, subagents, and plugins - -## Reference implementation - -Clone the development container reference implementation
modified
--- a/common-workflows.md +++ b/common-workflows.md @@ -1,3 +1,9 @@ +> ## Documentation Index +> +> Fetch the complete documentation index at: <https://code.claude.com/docs/llms.txt> +> +> Use this file to discover all available pages before exploring further. + This 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](</docs/en/best-practices>). ## @@ -343,7 +349,7 @@ enhance the PR description with more context about the security improvements -When you create a PR using `gh pr create`, the session is automatically linked to that PR. You can resume it later with `claude --from-pr <number>`. +When 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 search. Review Claude’s generated PR before submitting and ask Claude to highlight potential risks or considerations. @@ -596,7 +602,7 @@ `Enter`| Select and resume the highlighted session `Space`| Preview the session content. `Ctrl+V` also works on terminals that do not capture it as paste `Ctrl+R`| Rename the highlighted session -`/` or any printable character other than `Space`| Enter search mode and filter sessions +`/` 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 `Ctrl+A`| Show sessions from all projects on this machine. Press again to restore the current repository `Ctrl+W`| Show sessions from all worktrees of the current repository. Press again to restore the current worktree. Only shown in multi-worktree repositories `Ctrl+B`| Filter to sessions from your current git branch. Press again to show sessions from all branches @@ -812,7 +818,9 @@ `permission_prompt`| Claude needs you to approve a tool use `idle_prompt`| Claude is done and waiting for your next prompt `auth_success`| Authentication completes -`elicitation_dialog`| Claude is asking you a question +`elicitation_dialog`| An MCP server opens an elicitation form +`elicitation_complete`| An MCP elicitation form is submitted or dismissed +`elicitation_response`| An MCP elicitation response is sent back to the server 3
modified
--- a/common-workflows.md +++ b/common-workflows.md @@ -545,7 +545,7 @@ * `claude --resume` opens a conversation picker or resumes by name * `claude --from-pr 123` resumes sessions linked to a specific pull request -From inside an active session, use `/resume` to switch to a different conversation. When 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. Sessions 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. See Use the session picker below for the full shortcut reference. When 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. Resuming 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. When 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. Sessions 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>`. +From inside an active session, use `/resume` to switch to a different conversation. When 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. Sessions 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 below for the full shortcut reference. When 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. Resuming 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. When 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. Sessions 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>`. ###
modified
--- a/common-workflows.md +++ b/common-workflows.md @@ -545,7 +545,7 @@ * `claude --resume` opens a conversation picker or resumes by name * `claude --from-pr 123` resumes sessions linked to a specific pull request -From inside an active session, use `/resume` to switch to a different conversation. Sessions 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. See Use the session picker below for the full shortcut reference. When 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. Resuming 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. When 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. Sessions 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>`. +From inside an active session, use `/resume` to switch to a different conversation. When 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. Sessions 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. See Use the session picker below for the full shortcut reference. When 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. Resuming 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. When 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. Sessions 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>`. ###
modified
--- a/common-workflows.md +++ b/common-workflows.md @@ -498,7 +498,7 @@ Use extended thinking (thinking mode) -[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, progress hints appear below the indicator to show that Claude is actively working. Additionally, [models that support effort](</docs/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. Extended thinking is particularly valuable for complex architectural decisions, challenging bugs, multi-step implementation planning, and evaluating tradeoffs between different approaches. +[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. Additionally, [models that support effort](</docs/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. Extended thinking is particularly valuable for complex architectural decisions, challenging bugs, multi-step implementation planning, and evaluating tradeoffs between different approaches. Phrases like “think”, “think hard”, and “think more” are interpreted as regular prompt instructions and don’t allocate thinking tokens.
modified
--- a/common-workflows.md +++ b/common-workflows.md @@ -384,6 +384,16 @@ * Specify the documentation style you want (JSDoc, docstrings, etc.) * Ask for examples in the documentation * Request documentation for public APIs, interfaces, and complex logic + +* * * + +## + +​ + +Work in notes and non-code folders + +Claude 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. The `.claude/` directory and `CLAUDE.md` sit alongside other tools’ config directories without conflict. Claude reads files fresh on each tool call, so it sees edits you make in another application the next time it reads that file. * * *
modified
--- a/common-workflows.md +++ b/common-workflows.md @@ -488,7 +488,7 @@ Use extended thinking (thinking mode) -[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, progress hints appear below the indicator to show that Claude is actively working. Additionally, Opus 4.6 and Sonnet 4.6 support adaptive reasoning: instead of a fixed thinking token budget, the model dynamically allocates thinking based on your [effort level](</docs/en/model-config#adjust-effort-level>) setting. Extended thinking and adaptive reasoning work together to give you control over how deeply Claude reasons before responding. Extended thinking is particularly valuable for complex architectural decisions, challenging bugs, multi-step implementation planning, and evaluating tradeoffs between different approaches. +[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, progress hints appear below the indicator to show that Claude is actively working. Additionally, [models that support effort](</docs/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. Extended thinking is particularly valuable for complex architectural decisions, challenging bugs, multi-step implementation planning, and evaluating tradeoffs between different approaches. Phrases like “think”, “think hard”, and “think more” are interpreted as regular prompt instructions and don’t allocate thinking tokens. @@ -502,12 +502,12 @@ Scope| How to configure| Details ---|---|--- -**Effort level**| Run `/effort`, adjust in `/model`, or set [`CLAUDE_CODE_EFFORT_LEVEL`](</docs/en/env-vars>)| Control thinking depth for Opus 4.6 and Sonnet 4.6. See [Adjust effort level](</docs/en/model-config#adjust-effort-level>) -**`ultrathink` keyword**| Include “ultrathink” anywhere in your prompt| Sets effort to high for that turn on Opus 4.6 and Sonnet 4.6. Useful for one-off tasks requiring deep reasoning without permanently changing your effort setting +**Effort level**| Run `/effort`, adjust in `/model`, or set [`CLAUDE_CODE_EFFORT_LEVEL`](</docs/en/env-vars>)| Control thinking depth on [supported models](</docs/en/model-config#adjust-effort-level>) +**`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](</docs/en/model-config#adjust-effort-level>) for that **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](</docs/en/terminal-config>) to enable Option key shortcuts **Global default**| Use `/config` to toggle thinking mode| Sets your default across all projects (all models). Saved as `alwaysThinkingEnabled` in `~/.claude/settings.json` -**Limit token budget**| Set [`MAX_THINKING_TOKENS`](</docs/en/env-vars>) environment variable| Limit the thinking budget to a specific number of tokens. On Opus 4.6 and Sonnet 4.6, only `0` applies unless adaptive reasoning is disabled. Example: `export MAX_THINKING_TOKENS=10000` +**Limit token budget**| Set [`MAX_THINKING_TOKENS`](</docs/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` To view Claude’s thinking process, press `Ctrl+O` to toggle verbose mode and see the internal reasoning displayed as gray italic text. @@ -517,7 +517,7 @@ How extended thinking works -Extended 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. **With Opus 4.6 and Sonnet 4.6** , thinking uses adaptive reasoning: the model dynamically allocates thinking tokens based on the [effort level](</docs/en/model-config#adjust-effort-level>) you select. This is the recommended way to tune the tradeoff between speed and reasoning depth. **With older models** , thinking uses a fixed token budget drawn from your output allocation. The budget varies by model; see [`MAX_THINKING_TOKENS`](</docs/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. On Opus 4.6 and Sonnet 4.6, [adaptive reasoning](</docs/en/model-config#adjust-effort-level>) controls thinking depth, so `MAX_THINKING_TOKENS` only applies when set to `0` to disable thinking, or when `CLAUDE_CODE_DISABLE_ADAPTIVE_THINKING=1` reverts these models to the fixed budget. See [environment variables](</docs/en/env-vars>). +Extended 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. On [models that support effort](</docs/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`. With older models, thinking uses a fixed token budget drawn from your output allocation. The budget varies by model; see [`MAX_THINKING_TOKENS`](</docs/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. On 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](</docs/en/env-vars>). 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. @@ -535,7 +535,7 @@ * `claude --resume` opens a conversation picker or resumes by name * `claude --from-pr 123` resumes sessions linked to a specific pull request -From inside an active session, use `/resume` to switch to a different conversation. Sessions are stored per project directory. The `/resume` picker shows interactive sessions from the same git repository, including worktrees. When you select a session from another worktree of the same repository, Claude Code resumes it directly without requiring you to switch directories first. Sessions created by `claude -p` or SDK invocations do not appear in the picker, but you can still resume one by passing its session ID or custom name to `claude --resume <session-id-or-name>`. Custom names set with `--name` or `/rename` are accepted in addition to session IDs. +From inside an active session, use `/resume` to switch to a different conversation. Sessions 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. See Use the session picker below for the full shortcut reference. When 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. Resuming 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. When 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. Sessions 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>`. ### @@ -557,7 +557,7 @@ /rename auth-refactor -You can also rename any session from the picker: run `/resume`, navigate to a session, and press `R`. +You can also rename any session from the picker: run `/resume`, navigate to a session, and press `Ctrl+R`. 2 @@ -584,19 +584,21 @@ `↑` / `↓`| Navigate between sessions `→` / `←`| Expand or collapse grouped sessions `Enter`| Select and resume the highlighted session -`P`| Preview the session content -`R`| Rename the highlighted session -`/`| Search to filter sessions -`A`| Toggle between current directory and all projects -`B`| Filter to sessions from your current git branch +`Space`| Preview the session content. `Ctrl+V` also works on terminals that do not capture it as paste +`Ctrl+R`| Rename the highlighted session +`/` or any printable character other than `Space`| Enter search mode and filter sessions +`Ctrl+A`| Show sessions from all projects on this machine. Press again to restore the current repository +`Ctrl+W`| Show sessions from all worktrees of the current repository. Press again to restore the current worktree. Only shown in multi-worktree repositories +`Ctrl+B`| Filter to sessions from your current git branch. Press again to show sessions from all branches `Esc`| Exit the picker or search mode **Session organization:** The picker displays sessions with helpful metadata: - * Session name or initial prompt + * Session name if set, otherwise the conversation summary or first user prompt * Time elapsed since last activity * Message count * Git branch (if applicable) + * Project path, shown after widening to all projects with `Ctrl+A` Forked sessions (created with `/branch`, `/rewind`, or `--fork-session`) are grouped together under their root session, making it easier to find related conversations. @@ -607,7 +609,7 @@ * Use `--resume session-name` when you know which session you need * Use `--resume` (without a name) when you need to browse and select * For scripts, use `claude --continue --print "prompt"` to resume in non-interactive mode - * Press `P` in the picker to preview a session before resuming it + * Press `Space` in the picker to preview a session before resuming it * The resumed conversation starts with the same model and configuration as the original How it works: @@ -910,7 +912,7 @@ [Routines](</docs/en/routines>)| Anthropic-managed infrastructure| Tasks that should run even when your computer is off. Can also trigger on API calls or GitHub events in addition to a schedule. Configure at [claude.ai/code/routines](<https://claude.ai/code/routines>). [Desktop scheduled tasks](</docs/en/desktop-scheduled-tasks>)| Your machine, via the desktop app| Tasks that need direct access to local files, tools, or uncommitted changes. [GitHub Actions](</docs/en/github-actions>)| Your CI pipeline| Tasks tied to repo events like opened PRs, or cron schedules that should live alongside your workflow config. -[`/loop`](</docs/en/scheduled-tasks>)| The current CLI session| Quick polling while a session is open. Tasks are cancelled when you exit. +[`/loop`](</docs/en/scheduled-tasks>)| The current CLI session| Quick polling while a session is open. Tasks stop when you start a new conversation; `--resume` and `--continue` restore unexpired ones. When writing prompts for scheduled tasks, be explicit about what success looks like and what to do with results. The task runs autonomously, so it can’t ask clarifying questions. For example: “Review open PRs labeled `needs-review`, leave inline comments on any issues, and post a summary in the `#eng-reviews` Slack channel.”
modified
--- a/common-workflows.md +++ b/common-workflows.md @@ -488,7 +488,7 @@ Use extended thinking (thinking mode) -[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`. Additionally, Opus 4.6 and Sonnet 4.6 support adaptive reasoning: instead of a fixed thinking token budget, the model dynamically allocates thinking based on your [effort level](</docs/en/model-config#adjust-effort-level>) setting. Extended thinking and adaptive reasoning work together to give you control over how deeply Claude reasons before responding. Extended thinking is particularly valuable for complex architectural decisions, challenging bugs, multi-step implementation planning, and evaluating tradeoffs between different approaches. +[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, progress hints appear below the indicator to show that Claude is actively working. Additionally, Opus 4.6 and Sonnet 4.6 support adaptive reasoning: instead of a fixed thinking token budget, the model dynamically allocates thinking based on your [effort level](</docs/en/model-config#adjust-effort-level>) setting. Extended thinking and adaptive reasoning work together to give you control over how deeply Claude reasons before responding. Extended thinking is particularly valuable for complex architectural decisions, challenging bugs, multi-step implementation planning, and evaluating tradeoffs between different approaches. Phrases like “think”, “think hard”, and “think more” are interpreted as regular prompt instructions and don’t allocate thinking tokens. @@ -907,7 +907,7 @@ Option| Where it runs| Best for ---|---|--- -[Cloud scheduled tasks](</docs/en/web-scheduled-tasks>)| Anthropic-managed infrastructure| Tasks that should run even when your computer is off. Configure at [claude.ai/code](<https://claude.ai/code>). +[Routines](</docs/en/routines>)| Anthropic-managed infrastructure| Tasks that should run even when your computer is off. Can also trigger on API calls or GitHub events in addition to a schedule. Configure at [claude.ai/code/routines](<https://claude.ai/code/routines>). [Desktop scheduled tasks](</docs/en/desktop-scheduled-tasks>)| Your machine, via the desktop app| Tasks that need direct access to local files, tools, or uncommitted changes. [GitHub Actions](</docs/en/github-actions>)| Your CI pipeline| Tasks tied to repo events like opened PRs, or cron schedules that should live alongside your workflow config. [`/loop`](</docs/en/scheduled-tasks>)| The current CLI session| Quick polling while a session is open. Tasks are cancelled when you exit.
modified
--- a/common-workflows.md +++ b/common-workflows.md @@ -535,7 +535,7 @@ * `claude --resume` opens a conversation picker or resumes by name * `claude --from-pr 123` resumes sessions linked to a specific pull request -From inside an active session, use `/resume` to switch to a different conversation. Sessions are stored per project directory. The `/resume` picker shows interactive sessions from the same git repository, including worktrees. When you select a session from another worktree of the same repository, Claude Code resumes it directly without requiring you to switch directories first. Sessions 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>`. +From inside an active session, use `/resume` to switch to a different conversation. Sessions are stored per project directory. The `/resume` picker shows interactive sessions from the same git repository, including worktrees. When you select a session from another worktree of the same repository, Claude Code resumes it directly without requiring you to switch directories first. Sessions created by `claude -p` or SDK invocations do not appear in the picker, but you can still resume one by passing its session ID or custom name to `claude --resume <session-id-or-name>`. Custom names set with `--name` or `/rename` are accepted in addition to session IDs. ###
modified
--- a/common-workflows.md +++ b/common-workflows.md @@ -664,7 +664,7 @@ * **No changes** : the worktree and its branch are removed automatically * **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 -Subagent worktrees orphaned by a crash or an interrupted parallel run are removed automatically at startup once they are older than your [`cleanupPeriodDays`](</docs/en/settings#available-settings>) setting, provided they have no modifications to tracked files and no unpushed commits. Untracked files (new files never staged with `git add`) are not checked and do not prevent removal. Worktrees you create with `--worktree` are never removed by this sweep. To clean up worktrees outside of a Claude session, use manual worktree management. +Subagent worktrees orphaned by a crash or an interrupted parallel run are removed automatically at startup once they are older than your [`cleanupPeriodDays`](</docs/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. To clean up worktrees outside of a Claude session, use manual worktree management. Add `.claude/worktrees/` to your `.gitignore` to prevent worktree contents from appearing as untracked files in your main repository.
modified
--- a/common-workflows.md +++ b/common-workflows.md @@ -535,7 +535,7 @@ * `claude --resume` opens a conversation picker or resumes by name * `claude --from-pr 123` resumes sessions linked to a specific pull request -From inside an active session, use `/resume` to switch to a different conversation. Sessions are stored per project directory. The `/resume` picker shows interactive sessions from the same git repository, including worktrees. Sessions 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>`. +From inside an active session, use `/resume` to switch to a different conversation. Sessions are stored per project directory. The `/resume` picker shows interactive sessions from the same git repository, including worktrees. When you select a session from another worktree of the same repository, Claude Code resumes it directly without requiring you to switch directories first. Sessions 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>`. ###
modified
--- a/common-workflows.md +++ b/common-workflows.md @@ -908,7 +908,7 @@ Option| Where it runs| Best for ---|---|--- [Cloud scheduled tasks](</docs/en/web-scheduled-tasks>)| Anthropic-managed infrastructure| Tasks that should run even when your computer is off. Configure at [claude.ai/code](<https://claude.ai/code>). -[Desktop scheduled tasks](</docs/en/desktop#schedule-recurring-tasks>)| Your machine, via the desktop app| Tasks that need direct access to local files, tools, or uncommitted changes. +[Desktop scheduled tasks](</docs/en/desktop-scheduled-tasks>)| Your machine, via the desktop app| Tasks that need direct access to local files, tools, or uncommitted changes. [GitHub Actions](</docs/en/github-actions>)| Your CI pipeline| Tasks tied to repo events like opened PRs, or cron schedules that should live alongside your workflow config. [`/loop`](</docs/en/scheduled-tasks>)| The current CLI session| Quick polling while a session is open. Tasks are cancelled when you exit.
modified
--- a/common-workflows.md +++ b/common-workflows.md @@ -535,7 +535,7 @@ * `claude --resume` opens a conversation picker or resumes by name * `claude --from-pr 123` resumes sessions linked to a specific pull request -From inside an active session, use `/resume` to switch to a different conversation. Sessions are stored per project directory. The `/resume` picker shows sessions from the same git repository, including worktrees. +From inside an active session, use `/resume` to switch to a different conversation. Sessions are stored per project directory. The `/resume` picker shows interactive sessions from the same git repository, including worktrees. Sessions 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>`. ### @@ -664,7 +664,7 @@ * **No changes** : the worktree and its branch are removed automatically * **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 -To clean up worktrees outside of a Claude session, use manual worktree management. +Subagent worktrees orphaned by a crash or an interrupted parallel run are removed automatically at startup once they are older than your [`cleanupPeriodDays`](</docs/en/settings#available-settings>) setting, provided they have no modifications to tracked files and no unpushed commits. Untracked files (new files never staged with `git add`) are not checked and do not prevent removal. Worktrees you create with `--worktree` are never removed by this sweep. To clean up worktrees outside of a Claude session, use manual worktree management. Add `.claude/worktrees/` to your `.gitignore` to prevent worktree contents from appearing as untracked files in your main repository. @@ -942,7 +942,7 @@ what are the limitations of Claude Code? -Claude provides documentation-based answers to these questions. For executable examples and hands-on demonstrations, refer to the specific workflow sections above. +Claude provides documentation-based answers to these questions. For hands-on demonstrations, run `/powerup` for interactive lessons with animated demos, or refer to the specific workflow sections above. Tips:
modified
--- a/common-workflows.md +++ b/common-workflows.md @@ -519,7 +519,7 @@ Extended 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. **With Opus 4.6 and Sonnet 4.6** , thinking uses adaptive reasoning: the model dynamically allocates thinking tokens based on the [effort level](</docs/en/model-config#adjust-effort-level>) you select. This is the recommended way to tune the tradeoff between speed and reasoning depth. **With older models** , thinking uses a fixed token budget drawn from your output allocation. The budget varies by model; see [`MAX_THINKING_TOKENS`](</docs/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. On Opus 4.6 and Sonnet 4.6, [adaptive reasoning](</docs/en/model-config#adjust-effort-level>) controls thinking depth, so `MAX_THINKING_TOKENS` only applies when set to `0` to disable thinking, or when `CLAUDE_CODE_DISABLE_ADAPTIVE_THINKING=1` reverts these models to the fixed budget. See [environment variables](</docs/en/env-vars>). -You’re charged for all thinking tokens used, even though Claude 4 models show summarized thinking +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. * * * @@ -855,7 +855,7 @@ * Use pipes to integrate Claude into existing shell scripts * Combine with other Unix tools for powerful workflows - * Consider using —output-format for structured output + * Consider using `--output-format` for structured output ###
modified
--- a/common-workflows.md +++ b/common-workflows.md @@ -639,7 +639,11 @@ # Auto-generates a name like "bright-running-fox" claude --worktree -Worktrees are created at `<repo>/.claude/worktrees/<name>` and branch from the default remote branch. The worktree branch is named `worktree-<name>`. You can also ask Claude to “work in a worktree” or “start a worktree” during a session, and it will create one automatically. +Worktrees 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>`. The 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: + + git remote set-head origin -a + +This 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`. For full control over how worktrees are created, including choosing a different base per invocation, configure a [WorktreeCreate hook](</docs/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. You can also ask Claude to “work in a worktree” or “start a worktree” during a session, and it will create one automatically. ### @@ -711,7 +715,7 @@ Non-git version control -Worktree isolation works with git by default. For other version control systems like SVN, Perforce, or Mercurial, configure [WorktreeCreate and WorktreeRemove hooks](</docs/en/hooks#worktreecreate>) to provide custom worktree creation and cleanup logic. When configured, these hooks replace the default git behavior when you use `--worktree`. For automated coordination of parallel sessions with shared tasks and messaging, see [agent teams](</docs/en/agent-teams>). +Worktree isolation works with git by default. For other version control systems like SVN, Perforce, or Mercurial, configure [WorktreeCreate and WorktreeRemove hooks](</docs/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` is not processed. Copy any local configuration files inside your hook script instead. For automated coordination of parallel sessions with shared tasks and messaging, see [agent teams](</docs/en/agent-teams>). * * *
modified
Show diff (826 lines)
--- a/common-workflows.md +++ b/common-workflows.md @@ -18,63 +18,27 @@ Navigate to the project root directory -Report incorrect code - -Copy - -Ask AI - cd /path/to/project 2 Start Claude Code -Report incorrect code - -Copy - -Ask AI - claude 3 Ask for a high-level overview -Report incorrect code - -Copy - -Ask AI - give me an overview of this codebase 4 Dive deeper into specific components -Report incorrect code - -Copy - -Ask AI - explain the main architecture patterns used here -Report incorrect code - -Copy - -Ask AI - what are the key data models? - -Report incorrect code - -Copy - -Ask AI how is authentication handled? @@ -96,35 +60,17 @@ Ask Claude to find relevant files -Report incorrect code - -Copy - -Ask AI - find the files that handle user authentication 2 Get context on how components interact -Report incorrect code - -Copy - -Ask AI - how do these authentication files work together? 3 Understand the execution flow - -Report incorrect code - -Copy - -Ask AI trace the login process from front-end to database @@ -148,35 +94,17 @@ Share the error with Claude -Report incorrect code - -Copy - -Ask AI - I'm seeing an error when I run npm test 2 Ask for fix recommendations -Report incorrect code - -Copy - -Ask AI - suggest a few ways to fix the @ts-ignore in user.ts 3 Apply the fix - -Report incorrect code - -Copy - -Ask AI update user.ts to add the null check you suggested @@ -200,47 +128,23 @@ Identify legacy code for refactoring -Report incorrect code - -Copy - -Ask AI - find deprecated API usage in our codebase 2 Get refactoring recommendations -Report incorrect code - -Copy - -Ask AI - suggest how to refactor utils.js to use modern JavaScript features 3 Apply the changes safely -Report incorrect code - -Copy - -Ask AI - refactor utils.js to use ES2024 features while maintaining the same behavior 4 Verify the refactoring - -Report incorrect code - -Copy - -Ask AI run tests for the refactored code @@ -264,12 +168,6 @@ View available subagents -Report incorrect code - -Copy - -Ask AI - /agents This shows all available subagents and lets you create new ones. @@ -280,51 +178,21 @@ Claude Code automatically delegates appropriate tasks to specialized subagents: -Report incorrect code - -Copy - -Ask AI - review my recent code changes for security issues -Report incorrect code - -Copy - -Ask AI - run all tests and fix any failures 3 Explicitly request specific subagents -Report incorrect code - -Copy - -Ask AI - use the code-reviewer subagent to check the auth module -Report incorrect code - -Copy - -Ask AI - have the debugger subagent investigate why users can't log in 4 Create custom subagents for your workflow - -Report incorrect code - -Copy - -Ask AI /agents @@ -370,22 +238,10 @@ **Turn on Plan Mode during a session** You can switch into Plan Mode during a session using **Shift+Tab** to cycle through permission modes. If 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`. **Start a new session in Plan Mode** To start a new session in Plan Mode, use the `--permission-mode plan` flag: -Report incorrect code - -Copy - -Ask AI - claude --permission-mode plan **Run “headless” queries in Plan Mode** You can also run a query in Plan Mode directly with `-p` (that is, in [“headless mode”](</docs/en/headless>)): -Report incorrect code - -Copy - -Ask AI - claude --permission-mode plan -p "Analyze the authentication system and suggest improvements" ### @@ -394,38 +250,14 @@ Example: Planning a complex refactor -Report incorrect code - -Copy - -Ask AI - claude --permission-mode plan -Report incorrect code - -Copy - -Ask AI - I need to refactor our authentication system to use OAuth2. Create a detailed migration plan. Claude analyzes the current implementation and create a comprehensive plan. Refine with follow-ups: -Report incorrect code - -Copy - -Ask AI - What about backward compatibility? -Report incorrect code - -Copy - -Ask AI - How should we handle database migration? Press `Ctrl+G` to open the plan in your default text editor, where you can edit it directly before Claude proceeds. @@ -437,12 +269,6 @@ ​ Configure Plan Mode as default - -Report incorrect code - -Copy - -Ask AI // .claude/settings.json { @@ -467,48 +293,24 @@ Identify untested code -Report incorrect code - -Copy - -Ask AI - find functions in NotificationsService.swift that are not covered by tests 2 Generate test scaffolding -Report incorrect code - -Copy - -Ask AI - add tests for the notification service 3 Add meaningful test cases -Report incorrect code - -Copy - -Ask AI - add test cases for edge conditions in the notification service 4 Run and verify tests -Report incorrect code - -Copy - -Ask AI - run the new tests and fix any failures Claude can generate tests that follow your project’s existing patterns and conventions. When asking for tests, be specific about what behavior you want to verify. Claude examines your existing test files to match the style, frameworks, and assertion patterns already in use. For comprehensive coverage, ask Claude to identify edge cases you might have missed. Claude can analyze your code paths and suggest tests for error conditions, boundary values, and unexpected inputs that are easy to overlook. @@ -527,36 +329,18 @@ Summarize your changes -Report incorrect code - -Copy - -Ask AI - summarize the changes I've made to the authentication module 2 Generate a pull request -Report incorrect code - -Copy - -Ask AI - create a pr 3 Review and refine -Report incorrect code - -Copy - -Ask AI - enhance the PR description with more context about the security improvements When you create a PR using `gh pr create`, the session is automatically linked to that PR. You can resume it later with `claude --from-pr <number>`. @@ -575,47 +359,23 @@ Identify undocumented code -Report incorrect code - -Copy - -Ask AI - find functions without proper JSDoc comments in the auth module 2 Generate documentation -Report incorrect code - -Copy - -Ask AI - add JSDoc comments to the undocumented functions in auth.js 3 Review and enhance -Report incorrect code - -Copy - -Ask AI - improve the generated documentation with more context and examples 4 Verify documentation - -Report incorrect code - -Copy - -Ask AI check if the documentation follows our project standards @@ -649,67 +409,25 @@ Ask Claude to analyze the image -Report incorrect code - -Copy - -Ask AI - What does this image show? -Report incorrect code - -Copy - -Ask AI - Describe the UI elements in this screenshot -Report incorrect code - -Copy - -Ask AI - Are there any problematic elements in this diagram? 3 Use images for context -Report incorrect code - -Copy - -Ask AI - Here's a screenshot of the error. What's causing it? -Report incorrect code - -Copy - -Ask AI - This is our current database schema. How should we modify it for the new feature? 4 Get code suggestions from visual content -Report incorrect code - -Copy - -Ask AI - Generate CSS to match this design mockup - -Report incorrect code - -Copy - -Ask AI What HTML structure would recreate this component? @@ -735,12 +453,6 @@ Reference a single file -Report incorrect code - -Copy - -Ask AI - Explain the logic in @src/utils/auth.js This includes the full content of the file in the conversation. @@ -749,12 +461,6 @@ Reference a directory -Report incorrect code - -Copy - -Ask AI - What's the structure of @src/components? This provides a directory listing with file information. @@ -762,12 +468,6 @@ 3 Reference MCP resources - -Report incorrect code - -Copy - -Ask AI Show me the data from @github:repos/owner/repo/issues @@ -851,22 +551,10 @@ Name a session at startup with `-n`: -Report incorrect code - -Copy - -Ask AI - claude -n auth-refactor Or use `/rename` during a session, which also shows the name on the prompt bar: -Report incorrect code - -Copy - -Ask AI - /rename auth-refactor You can also rename any session from the picker: run `/resume`, navigate to a session, and press `R`. @@ -877,21 +565,9 @@ From the command line: -Report incorrect code - -Copy - -Ask AI - claude --resume auth-refactor Or from inside an active session: - -Report incorrect code - -Copy - -Ask AI /resume auth-refactor @@ -951,12 +627,6 @@ When 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. Use 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: -Report incorrect code - -Copy - -Ask AI - # Start Claude in a worktree named "feature-auth" # Creates .claude/worktrees/feature-auth/ with a new branch claude --worktree feature-auth @@ -966,12 +636,6 @@ If you omit the name, Claude generates a random one automatically: -Report incorrect code - -Copy - -Ask AI - # Auto-generates a name like "bright-running-fox" claude --worktree @@ -1004,15 +668,25 @@ ​ +Copy gitignored files to worktrees + +Git 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. The 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. + +.worktreeinclude + + .env + .env.local + config/secrets.json + +This applies to worktrees created with `--worktree`, subagent worktrees, and parallel sessions in the [desktop app](</docs/en/desktop#work-in-parallel-with-sessions>). + +### + +​ + Manage worktrees manually For 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. - -Report incorrect code - -Copy - -Ask AI # Create a worktree with a new branch git worktree add ../project-feature-a -b feature-a @@ -1060,12 +734,6 @@ * Linux * Windows - -Report incorrect code - -Copy - -Ask AI { "hooks": { @@ -1083,12 +751,6 @@ } } -Report incorrect code - -Copy - -Ask AI - { "hooks": { "Notification": [ @@ -1105,12 +767,6 @@ } } -Report incorrect code - -Copy - -Ask AI - { "hooks": { "Notification": [ @@ -1166,12 +822,6 @@ Suppose you want to use Claude Code as a linter or code reviewer. **Add Claude to your build script:** -Report incorrect code - -Copy - -Ask AI - // package.json { ... @@ -1195,12 +845,6 @@ Suppose you want to pipe data into Claude, and get back data in a structured format. **Pipe data through Claude:** -Report incorrect code - -Copy - -Ask AI - cat build-error.txt | claude -p 'concisely explain the root cause of this build error' > output.txt Tips: @@ -1221,12 +865,6 @@ Use text format (default) -Report incorrect code - -Copy - -Ask AI - cat data.txt | claude -p 'summarize this data' --output-format text > summary.txt This outputs just Claude’s plain text response (default behavior). @@ -1235,12 +873,6 @@ Use JSON format -Report incorrect code - -Copy - -Ask AI - cat code.py | claude -p 'analyze this code for bugs' --output-format json > analysis.json This outputs a JSON array of messages with metadata including cost and duration. @@ -1248,12 +880,6 @@ 3 Use streaming JSON format - -Report incorrect code - -Copy - -Ask AI cat log.txt | claude -p 'parse this log file for errors' --output-format stream-json @@ -1300,51 +926,15 @@ Example questions -Report incorrect code - -Copy - -Ask AI - can Claude Code create pull requests? -Report incorrect code - -Copy - -Ask AI - how does Claude Code handle permissions? -Report incorrect code - -Copy - -Ask AI - what skills are available? -Report incorrect code - -Copy - -Ask AI - how do I use MCP with Claude Code? -Report incorrect code - -Copy - -Ask AI - how do I configure Claude Code for Amazon Bedrock? - -Report incorrect code - -Copy - -Ask AI what are the limitations of Claude Code?
modified
--- a/common-workflows.md +++ b/common-workflows.md @@ -1271,6 +1271,25 @@ ​ +Run Claude on a schedule + +Suppose 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. Pick a scheduling option based on where you want the task to run: + +Option| Where it runs| Best for +---|---|--- +[Cloud scheduled tasks](</docs/en/web-scheduled-tasks>)| Anthropic-managed infrastructure| Tasks that should run even when your computer is off. Configure at [claude.ai/code](<https://claude.ai/code>). +[Desktop scheduled tasks](</docs/en/desktop#schedule-recurring-tasks>)| Your machine, via the desktop app| Tasks that need direct access to local files, tools, or uncommitted changes. +[GitHub Actions](</docs/en/github-actions>)| Your CI pipeline| Tasks tied to repo events like opened PRs, or cron schedules that should live alongside your workflow config. +[`/loop`](</docs/en/scheduled-tasks>)| The current CLI session| Quick polling while a session is open. Tasks are cancelled when you exit. + +When writing prompts for scheduled tasks, be explicit about what success looks like and what to do with results. The task runs autonomously, so it can’t ask clarifying questions. For example: “Review open PRs labeled `needs-review`, leave inline comments on any issues, and post a summary in the `#eng-reviews` Slack channel.” + +* * * + +## + +​ + Ask Claude about its capabilities Claude has built-in access to its documentation and can answer questions about its own features and limitations.
added
Show diff (1365 lines)
--- a/common-workflows.md +++ b/common-workflows.md @@ -0,0 +1,1362 @@ +This 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](</docs/en/best-practices>). + +## + +​ + +Understand new codebases + +### + +​ + +Get a quick codebase overview + +Suppose you’ve just joined a new project and need to understand its structure quickly. + +1 + +Navigate to the project root directory + +Report incorrect code + +Copy + +Ask AI + + cd /path/to/project + +2 + +Start Claude Code + +Report incorrect code + +Copy + +Ask AI + + claude + +3 + +Ask for a high-level overview + +Report incorrect code + +Copy + +Ask AI + + give me an overview of this codebase + +4 + +Dive deeper into specific components + +Report incorrect code + +Copy + +Ask AI + + explain the main architecture patterns used here + +Report incorrect code + +Copy + +Ask AI + + what are the key data models? + +Report incorrect code + +Copy + +Ask AI + + how is authentication handled? + +Tips: + + * Start with broad questions, then narrow down to specific areas + * Ask about coding conventions and patterns used in the project + * Request a glossary of project-specific terms + +### + +​ + +Find relevant code + +Suppose you need to locate code related to a specific feature or functionality. + +1 + +Ask Claude to find relevant files + +Report incorrect code + +Copy + +Ask AI + + find the files that handle user authentication + +2 + +Get context on how components interact + +Report incorrect code + +Copy + +Ask AI + + how do these authentication files work together? + +3 + +Understand the execution flow + +Report incorrect code + +Copy + +Ask AI + + trace the login process from front-end to database + +Tips: + + * Be specific about what you’re looking for + * Use domain language from the project + * Install a [code intelligence plugin](</docs/en/discover-plugins#code-intelligence>) for your language to give Claude precise “go to definition” and “find references” navigation + +* * * + +## + +​ + +Fix bugs efficiently + +Suppose you’ve encountered an error message and need to find and fix its source. + +1 + +Share the error with Claude + +Report incorrect code + +Copy + +Ask AI + + I'm seeing an error when I run npm test + +2 + +Ask for fix recommendations + +Report incorrect code + +Copy + +Ask AI + + suggest a few ways to fix the @ts-ignore in user.ts + +3 + +Apply the fix + +Report incorrect code + +Copy + +Ask AI + + update user.ts to add the null check you suggested + +Tips: + + * Tell Claude the command to reproduce the issue and get a stack trace + * Mention any steps to reproduce the error + * Let Claude know if the error is intermittent or consistent + +* * * + +## + +​ + +Refactor code + +Suppose you need to update old code to use modern patterns and practices. + +1 + +Identify legacy code for refactoring + +Report incorrect code + +Copy + +Ask AI + + find deprecated API usage in our codebase + +2 + +Get refactoring recommendations + +Report incorrect code + +Copy + +Ask AI + + suggest how to refactor utils.js to use modern JavaScript features + +3 + +Apply the changes safely + +Report incorrect code + +Copy + +Ask AI + + refactor utils.js to use ES2024 features while maintaining the same behavior + +4 + +Verify the refactoring + +Report incorrect code + +Copy + +Ask AI + + run tests for the refactored code + +Tips: + + * Ask Claude to explain the benefits of the modern approach + * Request that changes maintain backward compatibility when needed + * Do refactoring in small, testable increments + +* * * + +## + +​ + +Use specialized subagents + +Suppose you want to use specialized AI subagents to handle specific tasks more effectively. + +1 + +View available subagents + +Report incorrect code + +Copy + +Ask AI + + /agents + +This shows all available subagents and lets you create new ones. + +2 + +Use subagents automatically + +Claude Code automatically delegates appropriate tasks to specialized subagents: + +Report incorrect code + +Copy + +Ask AI + + review my recent code changes for security issues + +Report incorrect code + +Copy + +Ask AI + + run all tests and fix any failures + +3 + +Explicitly request specific subagents + +Report incorrect code + +Copy + +Ask AI + + use the code-reviewer subagent to check the auth module + +Report incorrect code + +Copy + +Ask AI + + have the debugger subagent investigate why users can't log in + +4 + +Create custom subagents for your workflow + +Report incorrect code + +Copy + +Ask AI + + /agents + +Then select “Create New subagent” and follow the prompts to define: + + * A unique identifier that describes the subagent’s purpose (for example, `code-reviewer`, `api-designer`). + * When Claude should use this agent + * Which tools it can access + * A system prompt describing the agent’s role and behavior + +Tips: + + * Create project-specific subagents in `.claude/agents/` for team sharing + * Use descriptive `description` fields to enable automatic delegation + * Limit tool access to what each subagent actually needs + * Check the [subagents documentation](</docs/en/sub-agents>) for detailed examples + +* * * + +## + +​ + +Use Plan Mode for safe code analysis + +Plan 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`](</docs/en/tools-reference>) to gather requirements and clarify your goals before proposing a plan. + +### + +​ + +When to use Plan Mode + + * **Multi-step implementation** : When your feature requires making edits to many files + * **Code exploration** : When you want to research the codebase thoroughly before changing anything + * **Interactive development** : When you want to iterate on the direction with Claude + +### + +​ + +How to use Plan Mode + +**Turn on Plan Mode during a session** You can switch into Plan Mode during a session using **Shift+Tab** to cycle through permission modes. If 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`. **Start a new session in Plan Mode** To start a new session in Plan Mode, use the `--permission-mode plan` flag: + +Report incorrect code + +Copy + +Ask AI + + claude --permission-mode plan + +**Run “headless” queries in Plan Mode** You can also run a query in Plan Mode directly with `-p` (that is, in [“headless mode”](</docs/en/headless>)): + +Report incorrect code + +Copy + +Ask AI + + claude --permission-mode plan -p "Analyze the authentication system and suggest improvements" + +### + +​ + +Example: Planning a complex refactor + +Report incorrect code + +Copy + +Ask AI + + claude --permission-mode plan + +Report incorrect code + +Copy + +Ask AI + + I need to refactor our authentication system to use OAuth2. Create a detailed migration plan. + +Claude analyzes the current implementation and create a comprehensive plan. Refine with follow-ups: + +Report incorrect code + +Copy + +Ask AI + + What about backward compatibility? + +Report incorrect code + +Copy + +Ask AI + + How should we handle database migration? + +Press `Ctrl+G` to open the plan in your default text editor, where you can edit it directly before Claude proceeds. + +When 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. + +### + +​ + +Configure Plan Mode as default + +Report incorrect code + +Copy + +Ask AI + + // .claude/settings.json + { + "permissions": { + "defaultMode": "plan" + } + } + +See [settings documentation](</docs/en/settings#available-settings>) for more configuration options. + +* * * + +## + +​ + +Work with tests + +Suppose you need to add tests for uncovered code. + +1 + +Identify untested code + +Report incorrect code + +Copy + +Ask AI + + find functions in NotificationsService.swift that are not covered by tests + +2 + +Generate test scaffolding + +Report incorrect code + +Copy + +Ask AI + + add tests for the notification service + +3 + +Add meaningful test cases + +Report incorrect code + +Copy + +Ask AI + + add test cases for edge conditions in the notification service + +4 + +Run and verify tests + +Report incorrect code + +Copy + +Ask AI + + run the new tests and fix any failures + +Claude can generate tests that follow your project’s existing patterns and conventions. When asking for tests, be specific about what behavior you want to verify. Claude examines your existing test files to match the style, frameworks, and assertion patterns already in use. For comprehensive coverage, ask Claude to identify edge cases you might have missed. Claude can analyze your code paths and suggest tests for error conditions, boundary values, and unexpected inputs that are easy to overlook. + +* * * + +## + +​ + +Create pull requests + +You can create pull requests by asking Claude directly (“create a pr for my changes”), or guide Claude through it step-by-step: + +1 + +Summarize your changes + +Report incorrect code + +Copy + +Ask AI + + summarize the changes I've made to the authentication module + +2 + +Generate a pull request + +Report incorrect code + +Copy + +Ask AI + + create a pr + +3 + +Review and refine + +Report incorrect code + +Copy + +Ask AI + + enhance the PR description with more context about the security improvements + +When you create a PR using `gh pr create`, the session is automatically linked to that PR. You can resume it later with `claude --from-pr <number>`. + +Review Claude’s generated PR before submitting and ask Claude to highlight potential risks or considerations. + +## + +​ + +Handle documentation + +Suppose you need to add or update documentation for your code. + +1 + +Identify undocumented code + +Report incorrect code + +Copy + +Ask AI + + find functions without proper JSDoc comments in the auth module + +2 + +Generate documentation + +Report incorrect code + +Copy + +Ask AI + + add JSDoc comments to the undocumented functions in auth.js + +3 + +Review and enhance + +Report incorrect code + +Copy + +Ask AI + + improve the generated documentation with more context and examples + +4 + +Verify documentation + +Report incorrect code + +Copy + +Ask AI + + check if the documentation follows our project standards + +Tips: + + * Specify the documentation style you want (JSDoc, docstrings, etc.) + * Ask for examples in the documentation + * Request documentation for public APIs, interfaces, and complex logic + +* * * + +## + +​ + +Work with images + +Suppose you need to work with images in your codebase, and you want Claude’s help analyzing image content. + +1 + +Add an image to the conversation + +You can use any of these methods: + + 1. Drag and drop an image into the Claude Code window + 2. Copy an image and paste it into the CLI with ctrl+v (Do not use cmd+v) + 3. Provide an image path to Claude. E.g., “Analyze this image: /path/to/your/image.png” + +2 + +Ask Claude to analyze the image + +Report incorrect code + +Copy + +Ask AI + + What does this image show? + +Report incorrect code + +Copy + +Ask AI + + Describe the UI elements in this screenshot + +Report incorrect code + +Copy + +Ask AI + + Are there any problematic elements in this diagram? + +3 + +Use images for context + +Report incorrect code + +Copy + +Ask AI + + Here's a screenshot of the error. What's causing it? + +Report incorrect code + +Copy + +Ask AI + + This is our current database schema. How should we modify it for the new feature? + +4 + +Get code suggestions from visual content + +Report incorrect code + +Copy + +Ask AI + + Generate CSS to match this design mockup + +Report incorrect code + +Copy + +Ask AI + + What HTML structure would recreate this component? + +Tips: + + * Use images when text descriptions would be unclear or cumbersome + * Include screenshots of errors, UI designs, or diagrams for better context + * You can work with multiple images in a conversation + * Image analysis works with diagrams, screenshots, mockups, and more + * When Claude references images (for example, `[Image #1]`), `Cmd+Click` (Mac) or `Ctrl+Click` (Windows/Linux) the link to open the image in your default viewer + +* * * + +## + +​ + +Reference files and directories + +Use @ to quickly include files or directories without waiting for Claude to read them. + +1 + +Reference a single file + +Report incorrect code + +Copy + +Ask AI + + Explain the logic in @src/utils/auth.js + +This includes the full content of the file in the conversation. + +2 + +Reference a directory + +Report incorrect code + +Copy + +Ask AI + + What's the structure of @src/components? + +This provides a directory listing with file information. + +3 + +Reference MCP resources + +Report incorrect code + +Copy + +Ask AI + + Show me the data from @github:repos/owner/repo/issues + +This fetches data from connected MCP servers using the format @server:resource. See [MCP resources](</docs/en/mcp#use-mcp-resources>) for details. + +Tips: + + * File paths can be relative or absolute + * @ file references add `CLAUDE.md` in the file’s directory and parent directories to context + * Directory references show file listings, not contents + * You can reference multiple files in a single message (for example, “@file1.js and @file2.js”) + +* * * + +## + +​ + +Use extended thinking (thinking mode) + +[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`. Additionally, Opus 4.6 and Sonnet 4.6 support adaptive reasoning: instead of a fixed thinking token budget, the model dynamically allocates thinking based on your [effort level](</docs/en/model-config#adjust-effort-level>) setting. Extended thinking and adaptive reasoning work together to give you control over how deeply Claude reasons before responding. Extended thinking is particularly valuable for complex architectural decisions, challenging bugs, multi-step implementation planning, and evaluating tradeoffs between different approaches. + +Phrases like “think”, “think hard”, and “think more” are interpreted as regular prompt instructions and don’t allocate thinking tokens. + +### + +​ + +Configure thinking mode + +Thinking is enabled by default, but you can adjust or disable it. + +Scope| How to configure| Details +---|---|--- +**Effort level**| Run `/effort`, adjust in `/model`, or set [`CLAUDE_CODE_EFFORT_LEVEL`](</docs/en/env-vars>)| Control thinking depth for Opus 4.6 and Sonnet 4.6. See [Adjust effort level](</docs/en/model-config#adjust-effort-level>) +**`ultrathink` keyword**| Include “ultrathink” anywhere in your prompt| Sets effort to high for that turn on Opus 4.6 and Sonnet 4.6. Useful for one-off tasks requiring deep reasoning without permanently changing your effort setting +**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](</docs/en/terminal-config>) to enable Option key shortcuts +**Global default**| Use `/config` to toggle thinking mode| Sets your default across all projects (all models). +Saved as `alwaysThinkingEnabled` in `~/.claude/settings.json` +**Limit token budget**| Set [`MAX_THINKING_TOKENS`](</docs/en/env-vars>) environment variable| Limit the thinking budget to a specific number of tokens. On Opus 4.6 and Sonnet 4.6, only `0` applies unless adaptive reasoning is disabled. Example: `export MAX_THINKING_TOKENS=10000` + +To view Claude’s thinking process, press `Ctrl+O` to toggle verbose mode and see the internal reasoning displayed as gray italic text. + +### + +​ + +How extended thinking works + +Extended 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. **With Opus 4.6 and Sonnet 4.6** , thinking uses adaptive reasoning: the model dynamically allocates thinking tokens based on the [effort level](</docs/en/model-config#adjust-effort-level>) you select. This is the recommended way to tune the tradeoff between speed and reasoning depth. **With older models** , thinking uses a fixed token budget drawn from your output allocation. The budget varies by model; see [`MAX_THINKING_TOKENS`](</docs/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. On Opus 4.6 and Sonnet 4.6, [adaptive reasoning](</docs/en/model-config#adjust-effort-level>) controls thinking depth, so `MAX_THINKING_TOKENS` only applies when set to `0` to disable thinking, or when `CLAUDE_CODE_DISABLE_ADAPTIVE_THINKING=1` reverts these models to the fixed budget. See [environment variables](</docs/en/env-vars>). + +You’re charged for all thinking tokens used, even though Claude 4 models show summarized thinking + +* * * + +## + +​ + +Resume previous conversations + +When starting Claude Code, you can resume a previous session: + + * `claude --continue` continues the most recent conversation in the current directory + * `claude --resume` opens a conversation picker or resumes by name + * `claude --from-pr 123` resumes sessions linked to a specific pull request + +From inside an active session, use `/resume` to switch to a different conversation. Sessions are stored per project directory. The `/resume` picker shows sessions from the same git repository, including worktrees. + +### + +​ + +Name your sessions + +Give sessions descriptive names to find them later. This is a best practice when working on multiple tasks or features. + +1 + +Name the session + +Name a session at startup with `-n`: + +Report incorrect code + +Copy + +Ask AI + + claude -n auth-refactor + +Or use `/rename` during a session, which also shows the name on the prompt bar: + +Report incorrect code + +Copy + +Ask AI + + /rename auth-refactor + +You can also rename any session from the picker: run `/resume`, navigate to a session, and press `R`. + +2 + +Resume by name later + +From the command line: + +Report incorrect code + +Copy + +Ask AI + + claude --resume auth-refactor + +Or from inside an active session: + +Report incorrect code + +Copy + +Ask AI + + /resume auth-refactor + +### + +​ + +Use the session picker + +The `/resume` command (or `claude --resume` without arguments) opens an interactive session picker with these features: **Keyboard shortcuts in the picker:** + +Shortcut| Action +---|--- +`↑` / `↓`| Navigate between sessions +`→` / `←`| Expand or collapse grouped sessions +`Enter`| Select and resume the highlighted session +`P`| Preview the session content +`R`| Rename the highlighted session +`/`| Search to filter sessions +`A`| Toggle between current directory and all projects +`B`| Filter to sessions from your current git branch +`Esc`| Exit the picker or search mode + +**Session organization:** The picker displays sessions with helpful metadata: + + * Session name or initial prompt + * Time elapsed since last activity + * Message count + * Git branch (if applicable) + +Forked sessions (created with `/branch`, `/rewind`, or `--fork-session`) are grouped together under their root session, making it easier to find related conversations. + +Tips: + + * **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 + * Use `--continue` for quick access to your most recent conversation in the current directory + * Use `--resume session-name` when you know which session you need + * Use `--resume` (without a name) when you need to browse and select + * For scripts, use `claude --continue --print "prompt"` to resume in non-interactive mode + * Press `P` in the picker to preview a session before resuming it + * The resumed conversation starts with the same model and configuration as the original + +How it works: + + 1. **Conversation Storage** : All conversations are automatically saved locally with their full message history + 2. **Message Deserialization** : When resuming, the entire message history is restored to maintain context + 3. **Tool State** : Tool usage and results from the previous conversation are preserved + 4. **Context Restoration** : The conversation resumes with all previous context intact + +* * * + +## + +​ + +Run parallel Claude Code sessions with Git worktrees + +When 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. Use 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: + +Report incorrect code + +Copy + +Ask AI + + # Start Claude in a worktree named "feature-auth" + # Creates .claude/worktrees/feature-auth/ with a new branch + claude --worktree feature-auth + + # Start another session in a separate worktree + claude --worktree bugfix-123 + +If you omit the name, Claude generates a random one automatically: + +Report incorrect code + +Copy + +Ask AI + + # Auto-generates a name like "bright-running-fox" + claude --worktree + +Worktrees are created at `<repo>/.claude/worktrees/<name>` and branch from the default remote branch. The worktree branch is named `worktree-<name>`. You can also ask Claude to “work in a worktree” or “start a worktree” during a session, and it will create one automatically. + +### + +​ + +Subagent worktrees + +Subagents 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](</docs/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. + +### + +​ + +Worktree cleanup + +When you exit a worktree session, Claude handles cleanup based on whether you made changes: + + * **No changes** : the worktree and its branch are removed automatically + * **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 + +To clean up worktrees outside of a Claude session, use manual worktree management. + +Add `.claude/worktrees/` to your `.gitignore` to prevent worktree contents from appearing as untracked files in your main repository. + +### + +​ + +Manage worktrees manually + +For 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. + +Report incorrect code + +Copy + +Ask AI + + # Create a worktree with a new branch + git worktree add ../project-feature-a -b feature-a + + # Create a worktree with an existing branch + git worktree add ../project-bugfix bugfix-123 + + # Start Claude in the worktree + cd ../project-feature-a && claude + + # Clean up when done + git worktree list + git worktree remove ../project-feature-a + +Learn more in the [official Git worktree documentation](<https://git-scm.com/docs/git-worktree>). + +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. + +### + +​ + +Non-git version control + +Worktree isolation works with git by default. For other version control systems like SVN, Perforce, or Mercurial, configure [WorktreeCreate and WorktreeRemove hooks](</docs/en/hooks#worktreecreate>) to provide custom worktree creation and cleanup logic. When configured, these hooks replace the default git behavior when you use `--worktree`. For automated coordination of parallel sessions with shared tasks and messaging, see [agent teams](</docs/en/agent-teams>). + +* * * + +## + +​ + +Get notified when Claude needs your attention + +When 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](</docs/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. + +1 + +Add the hook to your settings + +Open `~/.claude/settings.json` and add a `Notification` hook that calls your platform’s native notification command: + + * macOS + + * Linux + + * Windows + +Report incorrect code + +Copy + +Ask AI + + { + "hooks": { + "Notification": [ + { + "matcher": "", + "hooks": [ + { + "type": "command", + "command": "osascript -e 'display notification \"Claude Code needs your attention\" with title \"Claude Code\"'" + } + ] + } + ] + } + } + +Report incorrect code + +Copy + +Ask AI + + { + "hooks": { + "Notification": [ + { + "matcher": "", + "hooks": [ + { + "type": "command", + "command": "notify-send 'Claude Code' 'Claude Code needs your attention'" + } + ] + } + ] + } + } + +Report incorrect code + +Copy + +Ask AI + + { + "hooks": { + "Notification": [ + { + "matcher": "", + "hooks": [ + { + "type": "command", + "command": "powershell.exe -Command \"[System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms'); [System.Windows.Forms.MessageBox]::Show('Claude Code needs your attention', 'Claude Code')\"" + } + ] + } + ] + } + } + +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. + +2 + +Optionally narrow the matcher + +By default the hook fires on all notification types. To fire only for specific events, set the `matcher` field to one of these values: + +Matcher| Fires when +---|--- +`permission_prompt`| Claude needs you to approve a tool use +`idle_prompt`| Claude is done and waiting for your next prompt +`auth_success`| Authentication completes +`elicitation_dialog`| Claude is asking you a question + +3 + +Verify the hook + +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. + +For the complete event schema and notification types, see the [Notification reference](</docs/en/hooks#notification>). + +* * * + +## + +​ + +Use Claude as a unix-style utility + +### + +​ + +Add Claude to your verification process + +Suppose you want to use Claude Code as a linter or code reviewer. **Add Claude to your build script:** + +Report incorrect code + +Copy + +Ask AI + + // package.json + { + ... + "scripts": { + ... + "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.'" + } + } + +Tips: + + * Use Claude for automated code review in your CI/CD pipeline + * Customize the prompt to check for specific issues relevant to your project + * Consider creating multiple scripts for different types of verification + +### + +​ + +Pipe in, pipe out + +Suppose you want to pipe data into Claude, and get back data in a structured format. **Pipe data through Claude:** + +Report incorrect code + +Copy + +Ask AI + + cat build-error.txt | claude -p 'concisely explain the root cause of this build error' > output.txt + +Tips: + + * Use pipes to integrate Claude into existing shell scripts + * Combine with other Unix tools for powerful workflows + * Consider using —output-format for structured output + +### + +​ + +Control output format + +Suppose you need Claude’s output in a specific format, especially when integrating Claude Code into scripts or other tools. + +1 + +Use text format (default) + +Report incorrect code + +Copy + +Ask AI + + cat data.txt | claude -p 'summarize this data' --output-format text > summary.txt + +This outputs just Claude’s plain text response (default behavior). + +2 + +Use JSON format + +Report incorrect code + +Copy + +Ask AI + + cat code.py | claude -p 'analyze this code for bugs' --output-format json > analysis.json + +This outputs a JSON array of messages with metadata including cost and duration. + +3 + +Use streaming JSON format + +Report incorrect code + +Copy + +Ask AI + + cat log.txt | claude -p 'parse this log file for errors' --output-format stream-json + +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. + +Tips: + + * Use `--output-format text` for simple integrations where you just need Claude’s response + * Use `--output-format json` when you need the full conversation log + * Use `--output-format stream-json` for real-time output of each conversation turn + +* * * + +## + +​ + +Ask Claude about its capabilities + +Claude has built-in access to its documentation and can answer questions about its own features and limitations. + +### + +​ + +Example questions + +Report incorrect code + +Copy + +Ask AI + + can Claude Code create pull requests? + +Report incorrect code + +Copy + +Ask AI + + how does Claude Code handle permissions? + +Report incorrect code + +Copy + +Ask AI + + what skills are available? + +Report incorrect code + +Copy + +Ask AI + + how do I use MCP with Claude Code? + +Report incorrect code + +Copy + +Ask AI + + how do I configure Claude Code for Amazon Bedrock? + +Report incorrect code + +Copy + +Ask AI + + what are the limitations of Claude Code? + +Claude provides documentation-based answers to these questions. For executable examples and hands-on demonstrations, refer to the specific workflow sections above. + +Tips: + + * Claude always has access to the latest Claude Code documentation, regardless of the version you’re using + * Ask specific questions to get detailed answers + * Claude can explain complex features like MCP integration, enterprise configurations, and advanced workflows + +* * * + +## + +​ + +Next steps + +## Best practices + +Patterns for getting the most out of Claude Code + +## How Claude Code works + +Understand the agentic loop and context management + +## Extend Claude Code + +Add skills, hooks, MCP, subagents, and plugins + +## Reference implementation + +Clone the development container reference implementation