Claude Code: Intelligent Development Agents in Terminals
Anthropic Command line tools launched Claude Code
Not just another chat window or IDE plugin, but a development agent natively integrated into the terminal environment. It understands project structure, reads and writes files, executes commands, and even orchestrates multiple Sub-Agents to accomplish complex tasks, designed to deeply integrate AI into a developer's core workflow.
For developers who are used to operating in terminals, theClaude Code
Provides an alternative to the GitHub Copilot
and other tools with different interaction patterns.Copilot
The advantage of IDE is its seamless IDE integration and fast line-level code completion, which is more like a "pair programmer" optimized for the "writing" part of the process. In contrast, the Claude Code
It is more of a "project manager", with its position in Shell, focusing on higher-level task planning and execution, and specializing in complex problems that require cross-document understanding and refactoring.
Core Features
- Native Terminal Integration: Code generation, debugging, and command execution can be done without leaving the terminal. This design philosophy is attractive to developers who rely on scripting and command line automation workflows.
- Customizing the Slash Command: Encapsulate common workflows into one-click commands for a high degree of automation.
- Sub-Agents Collaboration:: Supports the creation of specialized sub-agents with different responsibilities and permissions, which are coordinated by the master agent and are suitable for handling multi-stage tasks such as code review and test generation.
- Strong project control: The model context protocol is implemented through command whitelisting, proxy configuration (Proxy), hooks plug-in mechanism and model context protocol (MCP) extension that provides fine control granularity.
- SDK and System Integration: Provided
TypeScript
cap (a poem)Python
SDK that supports non-interactive calls and deep customization.
Used in domestic environments
start using Claude Code
Before doing so, make sure that the environment has the Node.js
18 or later, followed by the npm
Global Installation:
npm install -g @anthropic-ai/claude-code
After installation, type in the terminal claude
can be launched. The first time it runs, the system prompts the user to pass the /login
command to log in and subscribe.
due to Claude
There are barriers to the registration and payment process in the country, and users can consider the following two alternatives to configure and utilize Claude Code
The
1. Using the Kimi (Dark Side of the Moon) API
The Dark Side of the Moon (Moonshot AI) API Compatibility Claude Code
The input and output formats of the Users can apply on their open platform API Key
and by configuring environment variables to specify API
endpoints and authentication tokens:
export ANTHROPIC_BASE_URL="https://api.moonshot.cn/anthropic" && export ANTHROPIC_AUTH_TOKEN="sk-******"
After the configuration is complete, theClaude Code
Ready for normal use.
2. Setting up local proxy services
claude-code-proxy
is an open source Python
project, which takes anything that has to do with the OpenAI
Compatible APIs are converted to Claude Code
Available interfaces.
Local operation and configuration steps::
- Download the project and install the dependencies:
uv sync
- Create and modify configuration files:
cp .env.example .env
The In.env
Fill in the fileOpenAI
compatibleAPI Key
cap (a poem)Base URL
, and specify the corresponding models for different task complexities.OPENAI_API_KEY="sk-your-openai-key" OPENAI_BASE_URL="https://api.openai.com/v1" BIG_MODEL="gpt-4o" # 对应 'claude-3-opus' MIDDLE_MODEL="gpt-4o" # 对应 'claude-sonnet-4' SMALL_MODEL="gpt-4o-mini" # 对应 'claude-3.5-haiku'
- Start the local service:
uv run claude-code-proxy
The service runs on port 8082 by default. - Configure the environment variables by setting the
Claude Code
requests to the local proxy.AUTH_TOKEN
Can be set to any character to bypass the login prompt.export ANTHROPIC_BASE_URL="http://localhost:8082" export ANTHROPIC_AUTH_TOKEN="anything"
- Run the
claude
Ready to go.
Core Functions Explained
Claude Code
As a Agent
:: Autonomous planning of tasks, mobilizing tools and coordination Sub-Agent
The ability to do this. It will read the relevant files as needed for the task and build the context needed to complete the task after obtaining authorization from the user.
Permission Configuration and Security Considerations
The goal of permission configuration is to balance automation efficiency with system security.Claude Code
Allowing arbitrary shell commands to be executed means that runaway AI can lead to data loss, system corruption, and even data breaches.
A notable risk isPrompt Injection. Attackers can hide malicious instructions in code comments, documents, or even web page content. When Claude Code
When reading this external information, malicious commands can be executed, inducing them to disclose sensitive information or perform dangerous operations.
In order to control risk.Claude Code
A fine-grained permission management mechanism is provided. Users can manually edit item-level .claude/settings.json
or user level ~/.claude.json
file to configure permissions:
{
"skipPermissions": false,
"allowedTools": ["read", "write"],
"allowCommands": ["node ./scripts/setup.js"],
"denyCommands": ["rm -rf /", "curl http://*"]
}
skipPermissions
: Whether to skip the manual confirmation at each step.allowedTools
: AllowedClaude
Whitelisting of tools used.allowCommands
/denyCommands
:: More granular command-level whitelisting and blacklisting.
For restoration lint
Errors such as these are low-risk batch tasks that can be performed using the --dangerously-skip-permissions
flag skips all permission checks. However, it is highly recommended that you skip this check in container environments that do not have network access (such as the Docker Dev Containers
) in this mode to isolate potential risks.
In addition, it is possible to use the /permissions
command dynamically adjusts the permissions for the current session.
Memory management
By means of a file named CLAUDE.md
of the memory file.Claude Code
Memory for information such as project context, coding specifications, personal preferences, etc. can be maintained between sessions. Memory files are categorized into enterprise, user, and project levels and are layered on top of each other to form a complete context when loaded.
In the interactive window, type #
Memory creation can be triggered. Memory creation can be triggered by using the /init
command.Claude Code
Can automatically scan the code base and generate a project overview with a CLAUDE.md
Documentation. This is accomplished through the /memory
commands to edit and view the memory.
CLAUDE.md
Documentation supports the use of @path/to/file
Syntax imports the contents of other files for easy referencing README
or existing information such as configuration files.
Customizing the Slash Command
Slash commands are shortcuts for engineering commonly used prompts (Prompts). Users can write task commands as Markdown files in a specific directory, theClaude Code
will automatically recognize it as a callable command.
- storage location:
- Project level.
.claude/commands/
(Called./project:命令名
) - User Level.
~/.claude/commands/
(Called./user:命令名
)
- Project level.
- parameter input:
- utilization
$ARGUMENTS
The placeholder receives all arguments after the command.
- utilization
A creation Hugo
Sample commands for the article (.claude/commands/posts/new.md
):
---
description: 创建一篇新的 Hugo 文章
argument-hint: [title]
model: haiku
---
创建一篇文章,标题为 $ARGUMENTS:
# 文章要求
1. 生成 kebab-case 格式的文件名 (格式: YYYY-MM-DD-标题.md)。
2. 使用 Hugo 命令创建新文件: `hugo new content`。
3. 更新文件的 Front Matter,包含标题、日期和描述。
4. 告诉我预览网站的命令。
# 偏好设置:
文章风格需风趣幽默、通俗易懂。
Calling the /project:posts:new 介绍 GPT-5
(math.) genus介绍 GPT-5
This part is then replaced $ARGUMENTS
Driver Claude
Execute a defined task flow.
Customizing Sub-Agents
Sub-Agents
are specialized subagents, each with separate system prompts, context windows, and tool permissions for domain-specific tasks. This design allows complex tasks to be decomposed, allowing the main dialog to focus on high-level goals while delegating specific execution details to expert subagents.
Sub-Agents
The configuration file is also in Markdown format and is stored in the .claude/agents/
(project level) or ~/.claude/agents/
(user level) directory. Users can access the /agents
Command-guided creation of subagents, defining their names, descriptions, available tools, and models.
The generated subagent profile (.claude/agents/product-prd-expert.md
) Example:
---
name: product-prd-expert
description: 当需要根据用户规格创建专业的产品需求文档 (PRD) 时使用此代理。
tools: Grep, LS, Edit, Write
model: sonnet
color: red
---
You are a senior product manager with 10+ years of experience...
When the user's needs are different from the description
When the fields match, theClaude Code
will automatically invoke this subagent. The user can also call the subagent via the 使用 product-prd-expert 来生成产品需求
such a directive to explicitly invoke it.
basic command
Claude Code
A series of commands are provided to simplify daily operations:
command | functionality | typical example |
---|---|---|
claude |
Initiate Interactive Mode | claude |
claude "query" |
Running one-time tasks | claude "fix the build error" |
claude -p "query" |
Exit after running a one-time query | claude -p "explain this function" |
claude -c |
Continuing the recent conversation | claude -c |
claude -r |
Resumption of previous conversation | claude -r |
claude commit |
Creating a Git Commit | claude commit |
/clear |
Clearing the dialog history | > /clear |
/help |
Show available commands | > /help |
exit or Ctrl+C |
Withdrawal from Claude Code | > exit |
Custom Hooks
Hooks are user-defined Shell commands that are used in the Claude Code
execution at specific event points in the lifecycle, providing a means of Claude
The way in which behavior is controlled deterministically.
- application scenario:
- notifications: In
Claude
Alerts users via system notifications when waiting for input or requesting permissions. - Auto formatting: Runs automatically after each document edit
Prettier
maybegofmt
The - Logging and auditing: Record all executed commands for compliance checking.
- notifications: In
pass (a bill or inspection etc) /hooks
command can be used for different events (e.g. PreToolUse
,PostToolUse
,Notification
) registration hooks. For example, registering a hook for the Notification
event creates a macOS
Pop-up notification:
- (of a computer) run
/hooks
and selectNotification
Events. - Enter the Shell command.
msg=$(jq -r '.message'); osascript -e "display alert \"Claude Code 通知\" message \"$msg\""
. Here is a good example of the use ofjq
tools fromClaude
transmittedJSON
Extraction from standard inputmessage
Fields. - Select the scope of the hook (e.g.
local
), the configuration is saved in the.claude/settings.local.json
Center. - reopen
Claude Code
Make the hook effective.
Hook MCP Tool
Claude Code
hooks work seamlessly with the Model Context Protocol (MCP) tool, which follows the mcp__<server>__<tool>
The naming pattern of the hook can be passed in the hook through the matcher
field to match.
Configuration example:
{
"hooks": {
"PreToolUse": [
{
"matcher": "mcp__memory__.*",
"hooks": [
{
"type": "command",
"command": "echo 'Memory operation initiated' >> ~/mcp-operations.log"
}
]
},
{
"matcher": "mcp__.*__write.*",
"hooks": [
{
"type": "command",
"command": "/home/user/scripts/validate-mcp-write.py"
}
]
}
]
}
}
Using the MCP Tool
Through the model context protocol (Model Context Protocol, MCP).Claude Code
Can connect to external tools and data sources such as Airtable
,Notion
,GitHub
etc.
Adding a local stdio server
# 基本语法
claude mcp add <name> <command> [args...]
# 实际示例:添加 Airtable 服务器
claude mcp add airtable --env AIRTABLE_API_KEY=YOUR_KEY \
-- npx -y airtable-mcp-server
--
(dash Claude
own flags and commands passed to the MCP server.
Adding a Remote SSE Server
# 基本语法
claude mcp add --transport sse <name> <url>
# 实际示例:连接到 Linear
claude mcp add --transport sse linear https://mcp.linear.app/sse
Adding a Remote HTTP Server
# 基本语法
claude mcp add --transport http <name> <url>
# 实际示例:连接到 Notion
claude mcp add --transport http notion https://mcp.notion.com/mcp
Managing MCP Services
# 列出所有配置的服务器
claude mcp list
# 获取特定服务器的详细信息
claude mcp get github
# 删除服务器
claude mcp remove github
Installation range
utilization --scope
flag can specify where the configuration is stored:local
(default, current project only),project
(through .mcp.json
shared with the team),user
(available across all programs).
Claude Code SDK Integration
For non-interactive scenarios, theClaude Code
offers TypeScript
cap (a poem) Python
SDK. The SDK is essentially a wrapper around its command-line functionality, allowing developers to call the Claude Code
The ability of the
following Python
Basic usage examples of the SDK:
import asyncio
from claude_code_sdk import (
AssistantMessage,
ClaudeCodeOptions,
ClaudeSDKClient,
UserMessage,
)
async def interact_with_claude():
# 配置客户端选项
options = ClaudeCodeOptions(
model="claude-3-5-sonnet-20241022",
system_prompt="你是一个专业的软件开发助手",
allowed_tools=["Bash", "Read", "Edit"],
permission_mode="acceptEdits" # 自动接受文件编辑权限
)
# 创建客户端实例
async with ClaudeSDKClient(options=options) as client:
# 发送消息
await client.query("帮我检查项目中的潜在 bug")
# 接收和处理响应
async for message in client.receive_messages():
if isinstance(message, AssistantMessage):
print(f"Claude: {message.content}")
if __name__ == "__main__":
asyncio.run(interact_with_claude())
consultation
- Claude Code Official Documentation - https://docs.anthropic.com/en/docs/claude-code/
- Siddharth Bharath's Complete Guide to Claude Code - https://www.siddharthbharath.com/claude-code-the-complete-guide/
- Fuszti's Claude Code Setup Guide - https://fuszti.com/claude-code-setup-guide-2025/
- Claude Code Common Workflow - https://docs.anthropic.com/en/docs/claude-code/common-workflows
- Claude Code SDK Documentation - https://docs.anthropic.com/en/docs/claude-code/sdk
- Enterprise Agent Setup - https://docs.anthropic.com/en/docs/claude-code/corporate-proxy