Your First 10 Commands in Claude Code: A Beginner’s Tutorial with Examples

Getting Started with Claude Code: Your First 10 Commands

Claude Code is an AI-powered coding assistant that runs in your terminal. It helps you write, edit, debug, and understand code faster. This tutorial covers the 10 essential commands for getting started with Claude Code.

Quick Summary

  • /help – List all commands
  • /init – Initialize a project
  • /add – Add files to context
  • /ask – Ask questions
  • /edit – Edit files
  • /run – Execute shell commands
  • /test – Run tests
  • /commit – Generate commit messages
  • /review – Review code
  • /exit – Exit Claude Code

Prerequisites

Before you begin, ensure Claude Code is installed and authenticated:

# Install via npm
npm install -g @anthropic-ai/claude-code

# Authenticate with your API key
claude login

After installation, run claude in your project directory to start the interactive session.

Command 1: /help — Get Started with Built-in Guidance

Displays a list of all available commands and their descriptions.

/help

Example output:

Available commands:
  /help          Show this help message
  /init          Initialize a new Claude Code project
  /add           Add files to the conversation context
  /ask           Ask a question about your code
  /edit          Edit a file with AI assistance
  /run           Run a shell command
  /test          Run tests
  /commit        Generate a git commit message
  /review        Review code
  /exit          Exit Claude Code

Command 2: /init — Initialize a Project

Sets up Claude Code for your project by creating a claude.config.json file.

/init

Example interaction:

Claude Code: This will create a claude.config.json in your project root. Continue? (Y/n)
> Y
Claude Code: Project initialized. You can now use /add to add files.

Command 3: /add — Add Files to Context

Add one or more files so Claude can read and reference them.

/add src/index.js

Example output:

Added src/index.js (245 lines) to context.

You can also use wildcards:

/add src/**/*.js

Command 4: /ask — Ask Questions About Your Code

Get explanations, suggestions, or answers about your codebase.

/ask What does the parseConfig function do?

Example response:

The `parseConfig` function reads a JSON configuration file, validates required fields, and returns a config object. If validation fails, it throws a ConfigError.

Command 5: /edit — Edit a File with AI

Request changes to a file currently in context.

/edit Refactor parseConfig to use zod for validation

Claude will propose a diff and ask for confirmation before applying changes.

Command 6: /run — Execute Shell Commands

Run shell commands without leaving Claude Code.

/run npm test

Example output:

$ npm test
> [email protected] test
> jest

 PASS  src/__tests__/parseConfig.test.js
  ✓ parses valid config (12 ms)
  ✓ throws on missing field (8 ms)

Tests: 2 passed, 2 total

Command 7: /test — Run Your Tests

Convenience command that runs the project’s test suite.

/test

Equivalent to /run npm test for Node.js projects.

Command 8: /commit — Generate Git Commit Messages

Stage changes and generate a meaningful commit message.

/commit

Example flow:

Claude Code: This is the diff:
... (shows changes)

Proposed commit message:
feat: add input validation to parseConfig

Apply this commit? (Y/n)
> Y
Committed with message: feat: add input validation to parseConfig

Command 9: /review — Get Code Review Feedback

Request a code review on files in context.

/review src/index.js

Example feedback snippet:

Review of src/index.js:
- Good modular structure.
- Consider adding error handling for async operations (line 45).
- The variable name `x` on line 12 could be more descriptive.

Command 10: /exit — Exit Claude Code

Gracefully exit the Claude Code session.

/exit

Next Steps After Learning the Basics

Now that you know the 10 essential commands, explore more advanced features:

  • Multi-file editing with /edit across many files
  • Refactoring entire modules
  • Automation using /run and custom scripts
  • Integration with Git and CI/CD workflows

Check out our Advanced Techniques and Best Practices guides.

Frequently Asked Questions

Q: Can I use Claude Code with any programming language?
A: Yes, Claude Code works with all major languages including JavaScript, Python, TypeScript, Ruby, Go, and more.

Q: Do I need an internet connection?
A: Yes, Claude Code requires an internet connection to communicate with Anthropic’s API.

Q: How do I add multiple files at once?
A: Use wildcards like /add src/**/*.js or list files separated by spaces.

Q: Can I undo an edit?
A: Yes, if you have version control (Git), you can revert changes. Claude Code always shows a diff before applying, so you can review changes first.

Q: Is my code sent to the cloud?
A: Yes, code you add to the context is sent to Anthropic’s API for processing. Review Anthropic’s privacy policy for details.

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注