Lesson completed!
-

Claude Code CLI Commands: /clear, /compact, /help + 20 More

Essential CLI Commands

Claude Code has dozens of commands. Most of them you'll never use. These are the 10 I use every day.

The Commands That Matter

/help - Your Quick Reference

/help

Shows all available commands. Use it when you can't remember something.

/init - Initialize CLAUDE.md

/init

Creates the CLAUDE.md file by analyzing your project. Always run this when starting with a new project.

/context - View Token Usage

/context

Shows how many tokens you're using in the current session. Crucial for not running out of context.

Pro Tip: If you're above 60%, consider running /clear and starting fresh.

/clear - Clean Context

/clear

Clears conversation history. Use it between features to keep context focused.

/compact - Summarize History

/compact

Summarizes conversation history instead of deleting it. Useful when you want to keep some context but reduce tokens.

/status - Project Status

/status

Shows current project state - git branch, modified files, etc.

/permissions - Configure Permissions

/permissions

Opens the permissions panel. Configure which commands Claude can execute without asking.

/config - Configuration

/config

Shows current Claude Code configuration. Useful for debugging.

/cost - View Costs

/cost

Shows current session usage and estimated costs. Important for controlling expenses.

# - Add Rule to CLAUDE.md

# Always use TypeScript strict mode

Any line you start with # gets added directly to CLAUDE.md. Super useful for adding rules while you work.

Keyboard Shortcuts

These save you clicks:

ShortcutAction
Shift + TabChange mode (Default → Auto → Plan)
EscStop Claude immediately
Ctrl + CCancel current command
TabAutocomplete files/paths
Up ArrowPrevious command

Git Commands

Claude has built-in Git commands:

/git status       # View status
/git diff         # View changes
/git commit       # Create commit

But honestly, I prefer using normal Git commands. Claude understands them just fine.

Lesser-Known But Useful Commands

/doctor - Diagnostics

/doctor

Runs diagnostics to verify everything is configured correctly. Use it if something isn't working.

/mcp - Manage MCPs

/mcp list         # View installed MCPs
/mcp add [name]   # Add MCP

For managing external integrations.

/agents - Create Sub-Agents

/agents

Opens the wizard for creating sub-agents. We cover this in detail in the advanced module.

Mistakes That Cost Me Hours

Mistake 1: Forgetting /clear Between Features

The error: I worked on 3 features in a row in the same chat. Claude started mixing context and broke code from the first feature.

The cost: 1 hour rollback + debugging.

The lesson: One chat = one feature. /clear religiously when you finish something.

Mistake 2: Ignoring /context

The error: I didn't check token usage. Halfway through a big refactor, Claude started "forgetting" important files.

The cost: Had to redo the refactor from scratch because context was saturated.

The lesson: Check /context every 15-20 minutes on long tasks.

Daily Workflow with Commands

My typical workflow:

  1. Start project: /init (if new)
  2. Before each feature: /clear
  3. During work: /context every 15 min
  4. Add rules: # [rule] while working
  5. Finish feature: /clear

Quick Cheatsheet

/help       → View all commands
/init       → Create CLAUDE.md
/clear      → Clean context
/context    → View token usage
/cost       → View session costs
/compact    → Summarize history
Shift+Tab   → Change mode
Esc         → Stop Claude
# text      → Add rule to CLAUDE.md

Challenge: Try This

Before moving to the next lesson:

  • Open Claude Code and run /help
  • Run /context to see your current usage
  • Add a rule with # Always use TypeScript
  • Verify it was added to your CLAUDE.md

Estimated time: 5 minutes

Next Step

Now that you know the basic commands, let's see how to configure security permissions.