← All posts

Claude Code: A Practical Command Handbook

Jun 14, 2026#Claude Code790 words · 4 min read阅读中文原文 ↗

The short version

From slash commands to pipe scripts, the Claude Code commands that actually earn their keep every day, collected into a handbook you can copy from.

TestedClaude Code

After the better part of a year with Claude Code, the commands I actually type every day come down to a handful of categories. This is my cheat sheet for them, split into four parts — startup, slash commands, CLI scripting, config — with snippets you can copy as-is.

1. Startup and sessions

claude                              # open the interactive REPL
claude "take a look at this error"  # start with one line, then keep talking
claude -c                           # resume the last session (--continue)
claude --resume                     # list past sessions, pick one to continue

The one I use most is claude -c. A request I didn’t finish in the morning picks its context back up in the afternoon with one command, no re-explaining the background.

2. Slash commands (in the REPL)

Once you’re in a conversation, anything starting with / is a control command and never gets sent to the model:

Command What it does
/help List every available command
/clear Wipe the current conversation history (do it before a new topic, it saves tokens)
/compact Compress a long conversation into a summary and continue, keeping the key points
/model Switch models (Opus / Sonnet / Haiku)
/init Scan the project and generate a CLAUDE.md memory file
/review Review the changes on the current branch / a PR
/cost Show the token spend for this session
/memory Edit the long-term memory file
/config Open settings
/mcp View / manage MCP servers
/agents Manage subagents

Three of them cover most of it: /clear for a new task, /compact to keep a long one going, /model to match the model to the difficulty. Opus for hard refactors, Sonnet/Haiku for batches of small edits — faster and cheaper.

Context management is the part that matters

The longer a conversation runs, the easier it is for the model to drift off topic, and the more it costs you. A habit worth building:

  • New task, /clear. Don’t let the last request’s context leak into the next one.
  • Same task running long, answers slowing down or repeating themselves? /compact once, then keep going.

3. Command line / scripting (non-interactive)

-p (--print) is the switch that turns Claude Code into a pipe tool: give it input, take the output, never enter the REPL.

# ask directly, print the result, exit
claude -p "explain RAG in one sentence"

# pipe: feed it a file or another command's output
cat error.log | claude -p "what's the likely root cause in this log? give me a debugging order"
git diff | claude -p "summarize this change, grouped into feat/fix/chore"

A few snippets I run daily

# 1. draft a PR description
gh pr diff | claude -p "based on this diff, draft a PR description: summary + test plan"

# 2. turn a pile of commits into a changelog
git log v1.4.0..HEAD --oneline | \
  claude -p "group into feat/fix/chore, output changelog markdown"

# 3. annotate unfamiliar code
claude -p "annotate each function with what it does and why" < legacy.py

# 4. batch work: emit JSON a script can pick up
claude -p "extract all TODO comments as a JSON array" --output-format json < src/app.js

--output-format json makes the output structured JSON, easy to hand off to CI or another script.

4. Config and going further

CLAUDE.md, the project’s long-term memory

Drop a CLAUDE.md in the project root with the stack, the directory conventions, the startup commands, and the potholes you’ve already hit. Claude Code reads it every time. Use /init for a first draft, then fill in the conventions that matter by hand:

claude
> /init        # generate CLAUDE.md

A well-written CLAUDE.md saves you from re-explaining the background every single time. Highest return per unit of effort of anything here.

Custom slash commands

Save the prompts you reuse as files and they become your own /commands:

# write the prompt in .claude/commands/changelog.md
# then, in the REPL:
> /changelog

MCP: plugging in external tools

claude mcp add        # walks you through adding an MCP server (database, browser, API…)

With MCP connected, Claude Code can query your database, drive a browser, and call your internal APIs directly.

Permissions

By default it asks before every write and every command. For batch work you trust, you can loosen that, but be clear about the risk:

claude --allowedTools "Edit,Bash(npm run *)"   # only allow specific tools
# --dangerously-skip-permissions skips every confirmation — isolated environments only

One rule of thumb

All of it comes down to one line: let the AI do the draft work, keep the decision work for yourself.

-p pipes handle the batch chores, REPL plus /model takes on the hard tasks, CLAUDE.md accumulates project knowledge, /clear and /compact keep context under control. The judgment calls and the sign-off stay with you.

Was this useful?

If this post helped, you can buy me a coffee ☕