Claude Code Cheat Sheet: CLI Flags, Slash Commands and Config
Checked against Claude Code 2.1.332 on 28 November 2026. Each section links to the official docs it was checked against.
A quick reference for developers who use Claude Code every day and keep forgetting which flag or file does what. It was checked against Claude Code 2.1.332, the latest npm release on 28 November 2026 (published 24 November). Claude Code ships several releases a week, so check claude --version and the version notes below before you rely on a newer flag.
When to use what
Run plain claude for interactive work and claude -p for anything a script or CI job calls. Print mode skips the trust dialog and the UI, so pair it with --output-format json when another program reads the result, and with --max-turns or --max-budget-usd so a confused run cannot loop forever.
For instructions, use CLAUDE.md when you want Claude to follow a rule and a hook when the rule must always hold. Claude reads CLAUDE.md as guidance and can still drift from it; a PreToolUse hook that exits 2 actually blocks the tool call. Keep each CLAUDE.md under about 200 lines as the docs suggest, and move rules that apply to one folder into .claude/rules/ with a paths list so they load only when needed.
For permissions, put team rules in .claude/settings.json, your own exceptions in .claude/settings.local.json, and global taste in ~/.claude/settings.json. Lists such as permissions.allow merge across those files, while single values follow the precedence order: managed, then --settings, then local, project and user. Reach for --dangerously-skip-permissions only inside a throwaway container; acceptEdits or auto mode cover most of the same ground with far less risk. For MCP servers, claude mcp add is quicker than hand-editing JSON, and the MCP config cheat sheet covers the file formats if you need to share them with other clients.
We ran npm view @anthropic-ai/claude-code version to confirm 2.1.332; the commands themselves are from the CLI reference and were not run for this sheet.
claude "explain this repo"Open an interactive session that starts with your prompt
claude -p "query"Print mode: answer once and exit, for scripts and CI
cat logs.txt | claude -p "explain"Pipe a file in as context for a one-shot answer
claude -cContinue the most recent conversation in this directory
claude -r "auth-refactor" "finish this PR"Resume a session by ID or name and send it a new prompt
claude -n "my-feature"Name the session so --resume my-feature can find it later
claude -w feature-authStart in an isolated git worktree under .claude/worktrees/feature-auth
claude update / claude install stableUpdate to the latest release, or reinstall the native binary on the stable channel
--max-turns, --max-budget-usd and --json-schema work in print mode only. --json-schema takes a JSON Schema; build one from a sample object with our JSON Schema generator.
--model opusPick the model by alias (sonnet, opus, haiku, fable) or full name for this session
--permission-mode planStart in a mode: default, acceptEdits, plan, auto, dontAsk or bypassPermissions
--allowedTools "Bash(npm run test *)" "Read"Let matching tool calls run without a prompt
--disallowedTools "mcp__*"Remove every MCP tool from Claude's context; a scoped rule like Bash(rm *) denies only matching calls
--add-dir ../shared-libGive Claude file access to another directory (most of its .claude/ config is not picked up)
-p --output-format jsonReturn the result as JSON; stream-json emits events as they happen
-p --max-turns 3 --max-budget-usd 2Cap agentic turns and estimated API spend for an unattended run
--append-system-prompt "Always use TypeScript"Add to the default system prompt; --system-prompt replaces all of it
--mcp-config ./ci-mcp.json --strict-mcp-configLoad only the MCP servers in that file, ignoring .mcp.json and ~/.claude.json
--effort highSet effort for the session: low, medium, high, xhigh, max or ultracode
-p --json-schema '<schema>'Get validated JSON output that matches your schema when the run finishes
/initWrite a starter CLAUDE.md for the project from what Claude finds in the repo
/memoryEdit CLAUDE.md files and turn auto memory on or off
/compact focus on the API changesSummarise the conversation to free context, keeping what your instruction names
/clearStart a fresh conversation with empty context; the old one stays in /resume
/contextShow context usage as a grid, with hints about what is eating it
/rewindRoll the conversation and/or file edits back to an earlier checkpoint (aliases /undo, /checkpoint)
/model /effort highSwitch model (saved as your default) or change effort mid-session
/permissionsView and edit allow, ask and deny rules by scope
/plan fix the auth bugEnter plan mode and start planning that task right away
/usageShow session cost and plan limits (/cost is an alias)
/btw what does this regex do?Ask a side question without adding it to the main conversation
/statusShow version, model, account and which settings files loaded
Settings files are strict JSON: a trailing comma or // comment turns into a Settings Error at the next start. Run the file through the JSON formatter if you are unsure. CLAUDE.md details come from the memory docs.
./CLAUDE.md or ./.claude/CLAUDE.mdProject instructions every teammate gets; files above the working directory load at launch, subfolder files load on demand
~/.claude/CLAUDE.md ./CLAUDE.local.mdYour instructions for all projects, and your private notes for this one (gitignore the local file)
@docs/architecture.mdImport another file from CLAUDE.md; relative to the importing file, up to four hops deep
.claude/rules/api.md with `paths:` frontmatterRules that load only when Claude touches matching files
~/.claude/settings.jsonUser settings for every project: default model, theme, personal permission rules
.claude/settings.json / .claude/settings.local.jsonShared team settings to commit, and your personal overrides that stay out of git
"permissions": {"allow": ["Bash(npm run lint)"], "deny": ["Read(./.env)"]}Allow one command without prompts and block reading the env file
.claude/agents/ ~/.claude/agents/Where project and personal subagent definitions live
~/.claude.jsonState Claude Code writes itself: account, local and user MCP servers, trust decisions; do not hand-edit
Exit code 1 is not a block. Only exit 2 stops a blockable action (with stderr as the reason); any other non-zero code is reported and the action goes ahead.
"hooks": {"PreToolUse": [{"matcher": "Bash", "hooks": [{"type": "command", "command": "..."}]}]}Run a script before every Bash call; event, then matcher group, then handlers
exit 2Block the tool call from a PreToolUse hook and feed stderr back to Claude as the reason
PostToolUse with matcher "Edit|Write"Run a formatter or linter after Claude edits a file
SessionStart / Stop / NotificationLoad context at start, check work when Claude finishes, or alert you when it needs input
jq -r '.tool_input.command'Read the Bash command a hook received as JSON on stdin
/hooksBrowse configured hooks read-only, with the file each one came from
claude mcp add --transport http notion https://mcp.notion.com/mcpAdd a remote Streamable HTTP server in local scope
claude mcp add -s project fs -- npx -y @modelcontextprotocol/server-filesystem .Add a stdio server to the committed .mcp.json for the whole team
claude mcp listShow every configured MCP server and whether it connects
claude mcp login <name>Run a server's OAuth sign-in from the shell; add --no-browser over SSH
/mcpCheck status, sign in, and enable or disable servers from inside a session
Worked example: Block edits to .env files with a hook, then prove it works
A CLAUDE.md line saying "never touch .env" is a request. This hook makes it a rule. Save the script as .claude/hooks/protect-env.sh and make it executable:
#!/usr/bin/env bash
file=$(jq -r '.tool_input.file_path // empty')
case "$file" in
*.env|*.env.*) echo "Blocked: $file holds secrets" >&2; exit 2 ;;
esac
exit 0
Register it in .claude/settings.json so the whole team gets it:
{
"hooks": {
"PreToolUse": [
{
"matcher": "Edit|Write",
"hooks": [{ "type": "command", "command": "${CLAUDE_PROJECT_DIR}/.claude/hooks/protect-env.sh" }]
}
]
}
}
Test the script without Claude by piping in the JSON a hook receives:
$ echo '{"tool_input":{"file_path":"/app/.env"}}' | .claude/hooks/protect-env.sh; echo "exit=$?"
Blocked: /app/.env holds secrets
exit=2
$ echo '{"tool_input":{"file_path":"/app/src/x.ts"}}' | .claude/hooks/protect-env.sh; echo "exit=$?"
exit=0
We checked the jq filter locally (it prints /app/.env for the first input); the exit codes shown follow from the script and the hooks docs, since our sandbox would not run shell scripts. Exit 2 is what matters: Claude Code stops the Edit or Write call and shows Claude the stderr line, so it explains the refusal and moves on. If you had used exit 1, the docs say the edit would go ahead with only a hook error notice. Settings files reload on save, so /hooks should list the new entry right away. The jq filter is a plain field lookup; our JSONPath evaluator is handy for working out paths in bigger hook payloads.
Common mistakes
Using
exit 1in a hook meant to enforce a policy.Exit with 2. Claude Code treats 1 like any other non-blocking error, logs it and lets the tool call run.
Setting
"defaultMode": "bypassPermissions"in the committed.claude/settings.jsonand wondering why it does nothing.Since 2.1.257 that value only applies from user or managed settings. Pass
--permission-modefor one session, or set it in~/.claude/settings.jsonif you really mean it.Growing one CLAUDE.md past several hundred lines.
Long files use more context and get followed less. Keep the root file short and move folder-specific rules into
.claude/rules/with apathslist.Running
claude -pin CI with no limits.Add
--max-turnsand--max-budget-usd, and use--output-format jsonso the pipeline can read the result and fail cleanly.Adding a personal MCP server with
-s projectand committing a token in.mcp.json.Use the default local scope or
-s userfor personal servers. In the project file, reference secrets as${VAR}and keep the value in your shell.Adding a trailing comma to
settings.json.Settings files are strict JSON, so the whole file fails with a Settings Error. Run
/statusafter editing, andclaude doctorto see which entries were rejected.
Related cheat sheets
Sources
- https://code.claude.com/docs/en/cli-reference
- https://code.claude.com/docs/en/commands
- https://code.claude.com/docs/en/settings
- https://code.claude.com/docs/en/memory
- https://code.claude.com/docs/en/hooks
- https://code.claude.com/docs/en/mcp
- https://github.com/anthropics/claude-code/releases
- https://www.npmjs.com/package/@anthropic-ai/claude-code
How we research: where our facts come from, how often we re-check them, and why no one can pay for a review or a verdict.