Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

First Use of Claude Code

First Use of Claude Code

After installing Claude Code and configuring the API, we can get started.

Next, we'll complete the first use with the simplest example project.

Create a sample project:

mkdir runoob-claude-demo

cd runoob-claude-demo

Create a simple file:



touch main.py

Write the following content:



def add(a, b):

    return a + b

Have Claude Code Explain Code

Run in the project directory:



claude

Then enter:

解释 main.py 这个文件在做什么,用新手能理解的方式说明

Claude will read the code in the current directory and provide an explanation.

Have Claude Code Help You Modify Code

Continue typing in the Claude session:

给这个函数增加类型注解,并补充基本的错误处理

Claude will offer suggestions for changes, usually including:

You can choose to:


Basic Interaction Modes of Claude Code

Common instruction types

You can divide instructions to Claude Code into three categories:

1. Explanatory

解释这段代码



这个函数为什么这么写

** 2. Modification**

帮我重构这个函数



拆分成多个小函数

3. Generative

补一个测试用例



增加日志输出

A simple but useful instruction template:

在不改变现有行为的前提下,

帮我优化 XXX 文件的可读性,

并说明你做了哪些修改。

FAQ: Fixing Directory Permissions

On Mac or Linux, check whether you have permission to execute. If you see an error like the following, your permissions are insufficient:

Error: EACCES: permission denied, open

Open a terminal and run the following commands:

# 1. 修复 .claude 目录的所有权

sudo chown -R $(whoami) ~/.claude



# 2. Fix directory permissions (grant read, write, execute permissions)

chmod -R 755 ~/.claude



# 3. Ensure the projects directory is writable

chmod -R 755 ~/.claude/projects

Verify the fix:

# 检查权限

ls -la ~/.claude/


Using Claude Code in VS Code

If you do not like using Claude Code's command-line model, you can install Claude Code in the VS Code editor.

Open VS Code, go to the Extensions marketplace, and search for Claude Code Installation:

After installation, click the Claude Code icon in the upper-right corner to enter the Claude Code page:

You can now use it in the dialog box: