Getting Started with Claude Code: A Beginner's Complete Guide
This guide walks beginners through installing Claude Code, Anthropic's AI coding assistant, and using it day to day. It covers choosing between the terminal and editor extension, installing and logging in, configuring a network proxy, restricting access to sensitive files, writing effective prompts, using Claude Code for code review and command explanation, previewing deletion commands, integrating with Git, generating and checking unit tests, and troubleshooting common problems.
This article uses Claude Code as an example to explain the full workflow for beginners, from installation to daily use. Claude Code is an AI coding assistant from Anthropic. It can run in the terminal and can also be integrated into common code editors. The commands and configuration in this article are based on the official documentation at the time of writing. Tool updates may change the steps, so check the official Claude Code documentation on Anthropic’s website before you follow them.
1. Choose the Right Way to Use Claude Code
Claude Code has two main modes. The first is the command-line version, which you run directly in a terminal. It suits developers who prefer the command line and want to put AI into scripts or Git workflows. The second is an editor extension, such as the VS Code extension. It suits developers who want to chat with the AI while writing code. Both modes have the same core capabilities. The difference is the interface.
| Option | Best for | Main requirement | Account required |
|---|---|---|---|
| Command-line version | Developers who work in the terminal and want automation | Node.js runtime | Yes |
| Editor extension | Developers who prefer a graphical interface | Compatible code editor | Yes |
If you are new to AI coding tools, start with the editor extension to get used to chatting with the assistant, then learn the command-line version. This article focuses on the command-line version because its steps are easier to reproduce and it is easier to connect to tools such as Git.
2. Installation and First Login
The command-line version depends on Node.js. At the time of writing, the official documentation requires Node.js version 18 or later. Open a terminal and check your environment:
node -vnpm -v
If your version numbers are below the requirement, download and install the LTS version from the Node.js website. Then install Claude Code globally with npm:
npm install -g @anthropic-ai/claude-codeclaude --version
If the installation shows a permission error, do not add sudo directly. A safer approach is to change npm’s global installation directory so that a regular user has write access. Windows users can run the same commands in PowerShell.
Go to your project directory, run claude, and follow the prompts to complete the login authorization. For accounts, plans, and pricing, refer to the official website. After you log in successfully for the first time, you can start chatting about your project.
3. Configure a Network Proxy
On a corporate network or in a restricted network environment, the tool may need a proxy to connect to its servers. Node.js programs usually read three environment variables: HTTP_PROXY, HTTPS_PROXY, and NO_PROXY.
On macOS or Linux, set them in the terminal:
export HTTP_PROXY="http://proxy-address:port"export HTTPS_PROXY="http://proxy-address:port"export NO_PROXY="localhost,127.0.0.1,.internal.example.com"
NO_PROXY lists addresses that should bypass the proxy, such as internal service domains. If you add these commands to ~/.zshrc or ~/.bashrc, they take effect automatically in newly opened terminals.
On Windows, set them in PowerShell:
$env:HTTP_PROXY = "http://proxy-address:port"$env:HTTPS_PROXY = "http://proxy-address:port"$env:NO_PROXY = "localhost,127.0.0.1,.internal.example.com"
Keep two things in mind. First, if your proxy requires a username and password, do not write them into a project repository, CI configuration, or any file that gets committed to Git. Use your system’s credential manager, or set them temporarily in the current terminal only. Second, after you finish the setup, run a simple conversation to confirm that the network works before you start real work.
4. Protect Sensitive Files
The AI assistant needs to read project files to understand context. However, .env files, key files, and certificates should not be read freely. Claude Code lets you set permission rules in the project’s .claude/settings.json file. The example below denies reading environment files and the secrets directory:
{"permissions": {"deny": ["Read(./.env)","Read(./.env.*)","Read(./secrets/**)"]}}
The exact syntax may change between versions, so check the official documentation. After you make the change, ask the assistant to read the .env file and confirm that the request is denied. Also add these sensitive files to .gitignore so they are never committed to the repository.
5. Write Effective Prompts
The prompt determines the quality of the output. A vague request usually produces generic code. A specific request produces code that fits your project.
Weak prompt:
Write a pagination function.
Strong prompt:
Using the framework already in this project, implement an offset-based pagination endpoint. Accept a page number and a page size as parameters, and return the data list, the total record count, and the total page count. If the page number is less than 1 or the page size is outside the allowed range, return a clear error message.
A strong prompt usually includes four types of information: what to build, which technologies to use, what the inputs and outputs are, and which errors to handle. After the code is generated, you still need to read it and modify it so that it matches the project’s naming and structure.
6. Use AI for Code Review and Command Explanation
For legacy code, you can ask the assistant to analyze risks. For example:
claude -p "Analyze the potential risks in the calculateTotal function in src/order.js, such as floating-point precision, null values, and boundary conditions. Provide refactoring suggestions and explain the reason for each change."
The -p flag runs Claude Code in non-interactive mode, and the response prints directly to the terminal. Treat the review findings as leads only. You still need to judge each suggestion yourself.
When you encounter a command you do not understand, you can also ask the assistant to explain it step by step:
claude -p "Explain the meaning of this command step by step: tar -zxvf archive.tar.gz -C /opt"
7. Preview Before Deleting Files
AI-generated commands may not do what you expect. Deletion commands are especially risky, because files removed by -delete usually cannot be recovered. Take the task “delete .log files modified in the last 3 days” as an example. Follow these steps in order.
Step 1: Ask the assistant to generate a search command, but do not delete anything yet:
claude -p "Write a find command that lists .log files in the current directory modified within the last 3 days. Only print the paths. Do not delete anything."
Step 2: Run the search command yourself and check the results:
find . -name "*.log" -mtime -3 -print
-mtime -3 matches files modified less than 3 times 24 hours ago. Review each line of the output and confirm that no important log files are included.
Step 3: Run the deletion only after you confirm the results are correct:
find . -name "*.log" -mtime -3 -delete
Do not run this command directly in a production directory. A safer approach is to test it first in a test directory or on a backup copy.
8. Connect AI to Your Git Workflow
Git commit messages should be concise and follow a consistent format. The command below reads the staged changes and asks the assistant to write a commit message in the Conventional Commits format:
git diff --staged | claude -p "Based on this diff, generate a commit message in Conventional Commits format. Output only the message itself."
After the message is generated, check that the description is accurate, then run git commit yourself. Do not let the tool commit automatically, so that unwanted changes do not end up in your project history.
9. Generate Unit Tests and Review the Results
Writing tests is a step many developers overlook. You can ask the assistant to generate test cases for a function:
claude -p "Write pytest tests for the paginate function in src/utils/pagination.py. Cover edge cases such as page 0, a negative page number, a page size larger than the total count, and an empty list."
Generated tests are not always correct. They may treat incorrect behavior as the expected result, so keep these points in mind:
- Check each assertion’s expected value against the requirements, not against the current output of the code.
- Run the tests and confirm that all cases pass without any skipped cases.
- Temporarily introduce a bug into the function under test and confirm that the tests fail. If they still pass, the tests do not really check the logic.
Passing tests only show that the code matches the tests. They do not show that the code meets the requirements. You need to verify that part yourself.
10. Troubleshoot Common Problems
- If you see
claude: command not found, the npm global command directory is not in your PATH. Runnpm config get prefixto find the path, then add itsbindirectory to your environment variables. - If your Node.js version is too old, upgrade to the LTS version, then reinstall Claude Code.
