AI / Cheatsheet
Claude Code commands, flags, and config in one place
Grouped by what you are trying to do: start and resume sessions, run headless in CI, control permissions, pick a model, and wire up the six primitives that make Claude Code configurable - memory files, skills, subagents, hooks, MCP servers, and the plugins that bundle them.
About 11 min read. Every command and flag checked against Anthropic's official documentation in August 2026.
Starting, resuming, and backgrounding sessions
The CLI surface is larger than most people ever see. These are the invocations that come up daily.
| Command | What it does |
|---|---|
| claude | Start an interactive session in the current directory. |
| claude "explain this project" | Start interactive with an opening prompt already sent. |
| claude -c | Continue the most recent conversation in this directory. |
| claude -r "auth-refactor" "finish this" | Resume a specific session by ID or name and send a prompt. |
| claude -n "my-feature-work" | Give the session a display name you can resume by later. |
| claude --resume abc123 --fork-session | Resume into a new session ID instead of reusing the original. |
| claude --bg "investigate the flaky test" | Launch as a background agent and return to your shell immediately. |
| claude agents | Open the agent view to monitor every parallel background session. |
| claude attach 7c5dcf5d | Attach your terminal to a running background session. |
| claude logs 7c5dcf5d | Print recent output from a background session without attaching. |
| claude stop 7c5dcf5d | Stop a background session. Use claude rm to drop it from the list. |
| claude --add-dir ../apps ../lib | Give the session access to directories outside the working directory. |
| claude --ide | Auto-connect to your editor on startup when exactly one is available. |
| claude doctor | Print installation and settings diagnostics. First stop when something is off. |
| claude import codex --dry-run | Preview importing another coding agent's configuration, including AGENTS.md and MCP servers. |
| claude --safe-mode | Start with every customization disabled, to isolate a misbehaving hook or plugin. |
Gotcha: -c is scoped to the current directory, so running it from a subdirectory can resume a conversation you did not expect. Name the sessions you care about with -n and resume those by name instead.
Headless and CI: print mode flags
Print mode is what turns Claude Code from a chat tool into a pipeline step. These flags are the ones that make an unattended run safe and parseable.
| Flag | What it does |
|---|---|
| -p, --print | Run the query, print the response, exit. No interactive UI. |
| --output-format json | Emit a JSON object instead of text. Accepts text, json, stream-json. |
| --input-format stream-json | Feed messages in as a JSON stream rather than a single prompt string. |
| --json-schema '{...}' | Force the output to validate against a JSON Schema you supply. |
| --max-turns 3 | Hard ceiling on agentic turns. Print mode only. Use it on every CI job. |
| --max-budget-usd 5.00 | Stop once the run has spent this much on API calls. Print mode only. |
| --verbose | Required alongside the streaming output formats to see the full event flow. |
| --include-partial-messages | Include partial streaming events, for building a live UI on top of the stream. |
| --include-hook-events | Add hook lifecycle events to the output stream. Useful when debugging a hook in CI. |
| --no-session-persistence | Leave nothing on disk after the run. Print mode only. |
| --bare | Skip auto-discovery for a faster start. Fewer surprises in a container. |
| --append-system-prompt "..." | Append text to the default system prompt. --system-prompt replaces it entirely. |
| --permission-prompt-tool | Name an MCP tool to answer permission prompts in a non-interactive run. |
| claude setup-token | Generate a long-lived OAuth token for CI and scripts. |
A complete, safe CI invocation looks like this - read-only tools, a turn ceiling, a budget ceiling, and machine-readable output:
claude -p "Review the diff against main and list correctness bugs only." \
--output-format json \
--allowedTools "Read" "Grep" "Bash(git diff *)" "Bash(git log *)" \
--max-turns 6 \
--max-budget-usd 2.00 \
--no-session-persistence Gotcha: --max-turns, --max-budget-usd, and --no-session-persistence are print-mode only. Passing them to an interactive session does nothing, which is easy to miss because nothing errors.
Permission modes and tool allowlists
Permission modes set the default posture for a session; allow and deny rules override it per tool and per argument pattern.
| Mode or flag | Behavior |
|---|---|
| --permission-mode default | Standard checking with prompts. manual is an alias for this. |
| --permission-mode plan | Read-only exploration. Nothing is written until you approve the plan. |
| --permission-mode acceptEdits | Auto-accept edits and common filesystem commands inside the working directory. |
| --permission-mode auto | A background classifier reviews commands and protected-directory writes before they run. |
| --permission-mode dontAsk | Auto-deny anything that would prompt. Explicitly allowed tools still run. |
| --permission-mode bypassPermissions | Skip prompts entirely. Same as --dangerously-skip-permissions. |
| --allowedTools "Bash(git log *)" "Read" | Tools and argument patterns that execute without prompting. |
| --disallowedTools "Bash(rm *)" "Edit" | Deny rules. These win over allow rules. |
| --tools "Bash,Edit,Read" | Restrict which built-in tools exist at all for this session. |
| --settings ./settings.json | Load settings from a file or an inline JSON string. |
| --setting-sources user,project | Choose which settings layers apply: user, project, local. |
Gotcha: permission rules are enforcement; a rule in CLAUDE.md is only context. If a thing must never happen, put it in permissions.deny or a PreToolUse hook, not in a markdown bullet.
Model selection, effort, and context
Which model runs by default depends on your plan, so set it explicitly when it matters. As of August 2026 the aliases map to Anthropic's current line-up: Fable 5 at the top, Opus 5 for complex agentic coding, Sonnet 5 for the speed and intelligence balance, and Haiku for cheap mechanical work.
| Flag or command | What it does |
|---|---|
| --model opus | Set the model by alias: sonnet, opus, haiku, fable, or a full ID. |
| --model claude-sonnet-5 | Pin an exact model ID, which is what you want in CI so a default change cannot move under you. |
| --fallback-model sonnet,haiku | Fall back automatically when the primary model is unavailable. |
| --effort high | Set reasoning effort: low, medium, high, xhigh, max, ultracode. Available levels depend on the model. |
| --advisor opus | Enable the advisor tool so the session can consult a second model for guidance. |
| --autocompact 500k | Set the auto-compact window for the session, or pass auto. |
| /model | Switch model mid-session and save the choice as the default for new sessions. |
| /context | Visualize context usage as a grid, including which memory files actually loaded. |
| /compact [instructions] | Summarize the conversation to free context, optionally steering what to keep. |
| /usage | Show usage and costs for the session. /cost is an alias. |
Gotcha: the default model is plan-dependent and has changed more than once during 2026. Run /status to see what you are actually talking to before you draw conclusions about quality.
Slash commands worth memorizing
Type / for the full list. These are the ones that change how a session goes rather than just reporting on it.
| Command | What it does |
|---|---|
| /plan | Switch into plan mode before a large change. The single highest-value command here. |
| /clear | Start a new conversation with empty context. Cheaper and sharper than continuing. |
| /rewind | Roll both the code and the conversation back to an earlier checkpoint. |
| /branch [name] | Branch the conversation to try a different direction without losing this one. |
| /fork [prompt] | Copy the current conversation into a new background session. |
| /diff | Open an interactive viewer for the uncommitted changes. |
| /memory | Edit CLAUDE.md files and manage auto memory. |
| /permissions | Set approval rules for commands and file access from inside the session. |
| /agents | Manage subagent configurations. |
| /hooks | View the hook configuration currently in effect for tool events. |
| /mcp | Manage MCP server connections and OAuth authentication. |
| /tasks | List background tasks, including subagents that have already finished. |
| /background [prompt] | Detach the current session so it keeps running as a background agent. |
| /goal [condition] | Set a condition to keep working toward. Pass clear to drop it. |
| /btw [question] | Ask a side question without polluting the conversation history. |
| /status | Show session status. Runs immediately without interrupting a response. |
Anthropic also bundles a set of skills that behave like commands. The ones that earn their keep:
| Bundled skill | What it does |
|---|---|
| /code-review [--fix] | Review a diff, PR, branch, or path for correctness bugs. Accepts an effort level and can post GitHub inline comments. |
| /security-review | Check the current diff for security vulnerabilities. |
| /simplify [--fix] | Simplify code for readability and maintainability. |
| /batch <instruction> | Decompose a large change into independent units and run them as background subagents in isolated worktrees. |
| /doctor | Setup checkup: diagnoses installation issues, finds unused skills and servers, and proposes trims to a bloated CLAUDE.md. |
| /fewer-permission-prompts | Scan transcripts for repeated read-only calls and propose an allowlist. |
| /loop [interval] [prompt] | Run a prompt repeatedly on a schedule, or omit both arguments for an autonomous maintenance pass. |
| /deep-research <question> | Fan out web searches, cross-check sources, and return a cited report. |
CLAUDE.md memory and project rules
Memory files load at the start of every session, in scope order from broadest to most specific, and all discovered files are concatenated rather than overriding each other.
| Location | Scope |
|---|---|
| /etc/claude-code/CLAUDE.md | Managed policy on Linux and WSL. Cannot be excluded by user settings. macOS and Windows have equivalents. |
| ~/.claude/CLAUDE.md | Your personal preferences, applied to every project on the machine. |
| ./CLAUDE.md or ./.claude/CLAUDE.md | Team-shared project instructions, committed to version control. |
| ./CLAUDE.local.md | Personal project notes. Gitignore it. |
| .claude/rules/*.md | Topic files. Add a paths frontmatter field to load a rule only for matching files. |
| @path/to/file.md | Import syntax. Recursive to a maximum depth of four hops. Backtick a path to keep it literal. |
| /init | Generate a starting CLAUDE.md from the codebase. Suggests improvements rather than overwriting an existing one. |
Claude Code reads CLAUDE.md, not AGENTS.md. If your repo already has AGENTS.md for other agents, bridge them with a one-line import so nothing is duplicated:
@AGENTS.md
## Claude Code
Use plan mode for changes under `src/billing/`.
Never run the deploy script; ask instead. Gotcha: target under 200 lines per file. Anthropic's own guidance is that longer files consume more context and reduce adherence - so a bloated CLAUDE.md costs you money and obedience at the same time. Move procedures into skills and file-specific rules into .claude/rules/.
Skills and subagents
A skill is a procedure that loads only when used, so long reference material costs nothing until you need it. A subagent is a worker with its own context window, tools, and permissions, so exploration never floods your main conversation.
Skills
Create .claude/skills/<name>/SKILL.md with a description in frontmatter and instructions in the body. Custom commands were merged into skills, so an existing .claude/commands/deploy.md and a skill at .claude/skills/deploy/SKILL.md both produce /deploy and behave the same way.
---
description: Run the release checklist. Use when
preparing a version bump or tagging a release.
---
1. Confirm the working tree is clean.
2. Run `npm test` and stop on failure.
3. Update CHANGELOG.md with $ARGUMENTS. Use $ARGUMENTS for whatever the user types after the command. Set disable-model-invocation: true when only you should trigger it.
Subagents
Create .claude/agents/<name>.md for the project or ~/.claude/agents/ for every project. Frontmatter fields worth knowing:
| Field | Purpose |
|---|---|
| name | Required. Lowercase and hyphens; no colons, which are reserved for plugin scoping. |
| description | Required. When Claude should delegate to it. |
| tools | Restrict the toolset. Inherits everything if omitted. |
| model | Route cheap work to Haiku. Defaults to inherit. |
| permissionMode | Give a research agent plan so it physically cannot write. |
| maxTurns | Stop a runaway worker after N agentic turns. |
| isolation | Set to worktree to run in a temporary git worktree, cleaned up if nothing changed. |
| memory | Persistent memory scope for the subagent: user, project, or local. |
| skills | Preload skill content into the subagent at startup. |
Gotcha: your main conversation's auto memory is not loaded into a subagent. A subagent gets a genuinely fresh context plus whatever you preload, which is the entire point - but it also means it does not know what you just told the parent session.
Hooks: the enforcement layer
A hook binds a command, an HTTP call, an MCP tool, a prompt, or a sub-agent check to a lifecycle event. Unlike a CLAUDE.md rule, it runs regardless of what the model decided. There are more than thirty events; these are the ones people actually use.
| Event | Fires when |
|---|---|
| SessionStart | A session begins or resumes. |
| UserPromptSubmit | You submit a prompt, before Claude processes it. |
| PreToolUse | Before a tool call executes. This is where you block things. |
| PostToolUse | After a tool call succeeds. Where formatters and linters belong. |
| PostToolUseFailure | After a tool call fails. |
| PermissionRequest | A tool call needs a permission decision. |
| SubagentStart | A subagent is spawned. Matcher receives the agent type name. |
| SubagentStop | A subagent finishes. |
| Stop | Claude finishes responding. The natural place for a typecheck gate. |
| PreCompact | Before context compaction. |
| InstructionsLoaded | A CLAUDE.md or rules file loads. Best tool for debugging which files were actually read. |
| SessionEnd | A session terminates. |
Hooks live in settings.json under a hooks key. This one formats every file the agent writes:
{
"hooks": {
"PostToolUse": [
{
"matcher": "Write|Edit",
"hooks": [
{
"type": "command",
"command": "jq -r '.tool_input.file_path' | xargs npx prettier --write",
"timeout": 60
}
]
}
]
}
} Gotcha: hook input arrives as JSON on stdin, so a naive command that expects a file path as an argument will silently do nothing. Parse the payload. The if field takes a permission-rule pattern such as Edit(*.ts) if you want to narrow further than the matcher.
MCP servers and plugins
MCP connects Claude Code to your issue tracker, database, or monitoring. Plugins bundle skills, agents, hooks, and MCP servers into one installable unit. Background on the protocol itself is in the MCP explainer.
| Command | What it does |
|---|---|
| claude mcp add --transport http sentry URL | Add a remote HTTP server. The recommended transport for hosted services. |
| claude mcp add --transport stdio db -- npx pkg | Add a local process server. Everything after -- is passed to the server untouched. |
| claude mcp add ... --scope project | Scopes: local (default, just you), project (writes .mcp.json, shared), user (all your projects). |
| claude mcp add-json name '{...}' | Add a server from a raw JSON config, including transports the flag does not accept. |
| claude mcp list | List servers with a health status per entry. |
| claude mcp get sentry | Show one server's resolved configuration and auth state. |
| claude mcp login sentry | Run a server's OAuth flow from the shell. logout clears the credentials. |
| claude mcp reset-project-choices | Reset your approvals for project-scoped servers from .mcp.json. |
| --strict-mcp-config --mcp-config ./mcp.json | Use only the servers in that file and ignore every configured one. The right pairing for CI. |
| @server:protocol://path | Reference an MCP resource in a prompt. Type @ to autocomplete across every connected server. |
| /mcp__servername__promptname | Invoke a prompt exposed by an MCP server as a slash command. |
| claude plugin marketplace add owner/repo | Register a plugin marketplace, including a private repository for internal team plugins. |
| claude plugin install name@marketplace | Install a plugin. Its skills are namespaced as /plugin-name:skill. |
| claude --plugin-dir ./my-plugin | Load a local plugin directory or .zip for development, overriding an installed copy of the same name. |
| claude plugin validate ./my-plugin | Run the same validation the marketplace review pipeline runs. --strict treats warnings as errors. |
| /reload-plugins | Reload plugins, skills, agents, hooks, and plugin MCP and LSP servers without restarting. |
A plugin is a directory. Only plugin.json goes inside .claude-plugin/; everything else sits at the plugin root:
my-plugin/
.claude-plugin/plugin.json # name, description, version
skills/<name>/SKILL.md # slash commands and model-invoked skills
agents/<name>.md # subagent definitions
hooks/hooks.json # lifecycle hooks
.mcp.json # MCP servers the plugin brings with it
.lsp.json # language servers for code intelligence
bin/ # executables added to the Bash tool PATH Gotcha: putting skills/, agents/, or hooks/ inside .claude-plugin/ is the most common plugin bug. They belong at the root, and the plugin root is never ~/.claude/.
Keep going
Commands are the easy part; the process around them is what ships. The AI-assisted development workflow guide covers spec-first prompting, guardrails, review discipline, and cost control across any assistant. To wire Claude Code into your own tools, start with the Model Context Protocol explainer.
Weighing it against the alternatives? Claude Code vs Cursor and Claude Code vs Codex both lead with a verdict, and the full field guide covers the other eight tools. Official documentation lives at code.claude.com/docs.
More quick references are in the cheatsheet index, and the Git cheatsheet pairs well with an agent that commits on your behalf.