Commands, flags, and memory files for a Claude Code session in a real repo. Repeated workflows belong in custom slash commands. Work that should stay out of the main chat belongs in a subagent. Actions that must run every time belong in hooks.
Install and start a session
The native installers place a claude binary on your PATH and update themselves in the background. Homebrew, WinGet, and Linux package installs stay on the version you installed until you upgrade them.
| Command | What it does | Example |
|---|---|---|
| Native install, macOS or Linux | Downloads the binary | curl -fsSL https://claude.ai/install.sh \| bash |
| Native install, PowerShell | Same installer for Windows PowerShell | irm https://claude.ai/install.ps1 \| iex |
| Native install, CMD | Use this when irm is not a CMD command |
curl -fsSL https://claude.ai/install.cmd -o install.cmd && install.cmd && del install.cmd |
| Homebrew cask | Stable channel, about a week behind latest | brew install --cask claude-code |
| WinGet | Manual upgrades | winget install Anthropic.ClaudeCode |
| npm global package | Requires Node.js 22 or later; the claude you run is still a native binary |
npm install -g @anthropic-ai/claude-code |
| Check the binary | Prints a version after a new terminal | claude --version |
| Sign in | Claude subscription by default | claude auth login |
| Sign in for API billing | Anthropic Console instead of a subscription | claude auth login --console |
| Update a native install | Also works when background updates are disabled | claude update |
| Start | Interactive session in the current directory | claude |
| Start with a prompt | Session opens on that first message | claude "explain this project" |
On native Windows, install Git for Windows so the shell tool can use Git Bash. Without it, Claude Code uses PowerShell. Homebrew and WinGet stay put until you run brew upgrade claude-code or winget upgrade Anthropic.ClaudeCode, unless CLAUDE_CODE_PACKAGE_MANAGER_AUTO_UPDATE=1. claude install stable reinstalls the native binary on the stable channel.
Slash commands
Type / at the start of a message. Letters after the slash filter the menu. Text after the command name is the argument. A slash command in the middle of a sentence is ordinary text.
/review aliases the bundled /code-review skill. A project skill named code-review replaces /code-review and leaves /review on the bundled skill. A custom checklist belongs at /team:review, as in custom slash commands.
| Command | What it does | Example |
|---|---|---|
/help |
Lists commands available in this session | /help |
/clear [name] |
New conversation, empty context. Aliases: /reset, /new |
/clear auth-refactor |
/compact [instructions] |
Summarizes the current conversation to free context | /compact Keep the failing test names |
/model [model] |
Switches model and saves it as the default for new sessions. No argument opens a picker. In -p, a model argument applies to that run only |
/model sonnet |
/init |
Writes a starter CLAUDE.md from the repo. If one exists, suggests edits |
/init |
/review |
Alias of /code-review. Effort words include low, medium, high |
/review |
/memory |
Edits CLAUDE.md files and auto memory |
/memory |
/config [key=value] |
Settings UI. Alias: /settings. Direct writes skip the panel |
/config theme=dark |
/permissions |
Allow, ask, and deny rules. Alias: /allowed-tools |
/permissions |
/cost |
Alias of /usage: session cost, plan limits, activity |
/cost |
/agents |
Reminder to edit .claude/agents/ or ~/.claude/agents/. On v2.1.197 and earlier this opened a manager UI |
/agents |
/hooks |
Lists configured hooks grouped by event | /hooks |
/mcp |
MCP server list, OAuth, enable, disable, reconnect | /mcp |
/context shows what fills the window. /tasks lists background work, including finished subagents. /doctor checks the setup. /vim was removed in v2.1.92. Editor mode is under /config.
Set CLAUDE_CODE_NEW_INIT=1 before /init for the flow that also offers skills, hooks, and a personal memory file. /init will not overwrite an existing CLAUDE.md.
Keyboard shortcuts
Bindings depend on the terminal. In the transcript viewer, ? lists that view’s shortcuts.
| Shortcut | What it does | Example |
|---|---|---|
Enter |
Sends the prompt | Type the task, then Enter |
Ctrl+J |
New line without sending. \ then Enter does the same |
A multi-line prompt |
Esc |
Stops the current response or closes a dialog. On a permission prompt it declines | Esc while a long command runs |
Esc then Esc |
Clears a draft, or opens rewind when the input is empty | Double Esc on an empty prompt |
Ctrl+C |
Interrupts a running turn. If nothing is running, the first press clears input and a second press exits | Ctrl+C, Ctrl+C |
Ctrl+D |
Second press within 800 ms exits. With text in the prompt it deletes the next character | Ctrl+D, Ctrl+D |
Ctrl+L |
Redraws the terminal and keeps history | After a garbled render |
Ctrl+O |
Transcript viewer: tool calls, timestamps, model on each reply | Ctrl+O, then q to leave |
Ctrl+R |
Reverse-search prompt history | Ctrl+R, then test |
Ctrl+B |
Backgrounds a running shell or agent. In tmux, press it twice | During a long test run |
Ctrl+G |
Opens the prompt in your editor. Ctrl+X Ctrl+E is the same binding |
A prompt you want to rewrite |
Shift+Tab |
Cycles permission modes. The indicator labels default as Manual, then acceptEdits, plan, and when available bypassPermissions and auto |
Shift+Tab until you see plan |
Ctrl+S |
Stashes the draft, including shell mode. Press again on an empty prompt to restore | Park a prompt mid-thought |
@ |
File-path autocomplete | @src/api/server.ts |
! |
Shell mode, described below | ! npm test |
Ctrl+J inserts a newline in every terminal. Shift+Enter only works where the emulator sends it.
CLI flags
Print mode (-p, --print) runs the prompt and exits. That is the form CI and scripts should call. Interactive flags such as --continue still apply.
| Flag | What it does | Example |
|---|---|---|
-p, --print |
One shot, no interactive UI | claude -p "explain this function" |
--continue, -c |
Most recent conversation in this directory. Skips previous -p sessions unless you also pass -p |
claude -c |
--resume, -r |
Session by id, name, or transcript path. No value opens a picker | claude -r auth-refactor "Finish the PR" |
--model |
Alias (sonnet, opus, haiku, fable) or a full model id. Overrides the settings model and ANTHROPIC_MODEL |
claude --model sonnet |
--allowedTools, --allowed-tools |
Those tools run without a prompt, except reads of network paths. This does not remove other tools. Use --tools to restrict the set |
claude -p --allowedTools "Read" "Bash(git diff *)" "Summarize the diff" |
--output-format |
Print mode only: text, json, or stream-json |
claude -p "query" --output-format json |
cat logs.txt | claude -p "Explain the errors" feeds a file to print mode. claude -n "auth-refactor" names the session for --resume. --fork-session copies a resumed conversation onto a new id. --permission-mode plan starts in plan mode. --dangerously-skip-permissions is --permission-mode bypassPermissions. Leave it off on a repository you do not trust.
Memory files
Claude reads CLAUDE.md at the start of every session. The text is instructions, not a hard policy: short, specific lines are followed more reliably than a long style guide. Aim for under 200 lines per file. Check what actually loaded with /context and look under Memory files.
Load order, broadest first:
| Scope | Location | Who it applies to |
|---|---|---|
| Managed policy | macOS: /Library/Application Support/ClaudeCode/CLAUDE.md. Linux and WSL: /etc/claude-code/CLAUDE.md. Windows: C:\Program Files\ClaudeCode\CLAUDE.md |
Everyone the admin deployed it to |
| User | ~/.claude/CLAUDE.md |
All of your projects. On Windows, ~/.claude is %USERPROFILE%\.claude |
| Project | ./CLAUDE.md or ./.claude/CLAUDE.md |
The repo. Commit it |
| Local | ./CLAUDE.local.md |
You, this checkout. Add it to .gitignore |
CLAUDE.md and CLAUDE.local.md in directories above the working directory load in full at launch. A CLAUDE.md sitting in a subdirectory loads when Claude reads files in that directory.
Keep build commands, test commands, and layout here. Put a multi-step procedure in a slash command so it loads only when you invoke it.
Imports use @path inside CLAUDE.md. Relative paths resolve from the file that contains the import, and imports can nest four levels. A path inside backticks is literal, so `@README` does not import README. The first time a project file imports something outside the working directory, Claude Code asks you to approve it.
See @README for the layout and @docs/test-commands.md for how CI runs tests.
/memory edits these files and auto memory, which is Claude’s own notes under the project memory directory in ~/.claude. If the repo has AGENTS.md, import it from CLAUDE.md. Claude Code reads CLAUDE.md. Path-scoped rules in .claude/rules/ load with the files they match.
Refer files with @
In the prompt, @ opens file-path autocomplete. That mention is not the @import used inside CLAUDE.md. @ also pins a subagent. See the subagents guide.
@src/auth/session.ts Explain why the cookie is rewritten on every request.
Bash mode with !
Start a message with ! and Claude Code runs your shell directly. The command and its output land in the transcript, and Claude replies to that output. ! npm test is enough to get an explanation of the failures. The reply costs the same as a normal prompt.
! git status
! git diff --stat
! npm test
Output streams as the command runs. Ctrl+B backgrounds it. Tab completes earlier ! commands in this project, and a token containing / completes paths. Leave shell mode with Escape, Backspace, or Ctrl+U on an empty prompt. Pasting a line that starts with ! enters shell mode.
These commands run outside the sandbox. The sandbox applies to commands Claude chooses. Set respondToBashCommands to false in settings.json to keep the output without an automatic reply. A ! line inside a command file is a different feature, covered in custom slash commands.
Patterns you’ll reuse
# Inside the session: /init then /permissions
claude -p --model haiku --allowedTools "Read" "Bash(git diff *)" --output-format json "Summarize risk in the diff"
claude -c -p "Are the type errors from yesterday still present?"
claude -n "billing-webhook"
claude --resume billing-webhook
/compact Keep the webhook payload schema
/cost
! npm test
@deploy/helm/values.yaml What breaks if replicaCount goes from 2 to 1?
/mcp connects external tools. Setup is in MCP servers explained. A model that calls tools until the task is done is the loop agentic AI describes outside this CLI.
FAQ
How do I install Claude Code?
On macOS or Linux run the native installer from claude.ai/install.sh. On Windows use the PowerShell installer, WinGet, or the CMD script. npm install -g @anthropic-ai/claude-code also works and downloads the same native binary. Then run claude --version and claude auth login.
What is the difference between /clear and /compact?
/clear starts a new conversation with an empty context. You can pass a name so the old thread shows up in the /resume picker. /compact stays in the same conversation and replaces earlier turns with a summary so the window has room again. Pass optional focus text to /compact when the summary should keep one topic.
Where does Claude Code read CLAUDE.md?
It loads managed policy, then ~/.claude/CLAUDE.md, then the project file at ./CLAUDE.md or ./.claude/CLAUDE.md, then ./CLAUDE.local.md. Files in parent directories of your working directory load at launch. A CLAUDE.md in a subdirectory loads when Claude reads files there.
How do I resume yesterday’s Claude Code session?
From the project directory run claude --resume or claude -r to open a picker. Pass a session id or the name you set with claude -n or /clear. claude --continue (or -c) reopens the most recent conversation in that directory without a picker.
What does the ! prefix do in Claude Code?
A prompt that starts with ! runs in shell mode. Claude Code executes the command, puts the output in the transcript, and answers it. You do not wait for Claude to decide to call the shell. Set respondToBashCommands to false in settings.json if you want the output in context without an automatic reply.
How this guide was verified
Written by hand from the official documentation, every command re-checked, and reviewed a second time before publishing. Last reviewed on .
Official sources read for this article

