基本用法
Quick Reference
Keyboard Shortcuts
| Shortcut | Action |
|---|---|
!command | Execute bash immediately |
Esc Esc | Rewind conversation/code |
Ctrl+R | Reverse search history |
Ctrl+S | Stash current prompt |
Shift+Tab(×2) | Toggle plan mode |
Alt+P/ Option+P | Switch model |
Ctrl+O | Toggle verbose mode |
Tab/ Enter | Accept prompt suggestion |
Essential Commands
| Command | Purpose |
|---|---|
/init | Generate CLAUDE.md for your project |
/context | View token consumption |
/stats | View your usage statistics |
/usage | Check rate limits |
/vim | Enable vim mode |
/config | Open configuration |
/hooks | Configure lifecycle hooks |
/sandbox | Set permission boundaries |
/export | Export conversation to markdown |
/resume | Resume a past session |
/rename | Name current session |
/theme | Open theme picker |
/terminal-setup | Configure terminal integration |
CLI Flags
| Flag | Purpose |
|---|---|
-p "prompt" | Headless/print mode |
--continue | Resume last session |
--resume | Pick a session to resume |
--resume name | Resume session by name |
--teleport id | Resume a web session |
--dangerously-skip-permissions | YOLO mode |
SKILLS
quick-feature
/quick-feature 迭代分支名 需求描述
analyze-component
专门用来分析1000行以上大组件的
core pattern
THE AGENT PATTERN
=================
User --> messages[] --> LLM --> response
|
stop_reason == "tool_use"?
/ \
yes no
| |
execute tools return text
append results
loop back -----------------> messages[]
That's the minimal loop. Every AI coding agent needs this loop.
Production agents add policy, permissions, and lifecycle layers.
用户输入 → 消息数组 → LLM 处理 → 生成响应
↓
stop_reason == "tool_use"?
/ \
是 否
| |
执行工具 返回文本结果
将结果追加到消息
循环回去 ───────────────→ 消息数组
def agent_loop(messages):
while True: # ① 持续循环直到不需要工具
response = client.messages.create( # ② 调用 Claude API
model=MODEL, # 如: "claude-sonnet-4-6"
system=SYSTEM, # 系统提示词
messages=messages, # 完整对话历史
tools=TOOLS, # 可用工具定义
)
# ③ 将 LLM 的响应添加到历史
messages.append({
"role": "assistant",
"content": response.content
})
# ④ 检查是否需要调用工具
if response.stop_reason != "tool_use":
return # 如果不需要工具,直接返回结果
# ⑤ 执行所有工具调用
results = []
for block in response.content:
if block.type == "tool_use":
output = TOOL_HANDLERS[block.name](**block.input)
results.append({
"type": "tool_result",
"tool_use_id": block.id,
"content": output,
})
# ⑥ 将工具结果追加到历史,循环继续
messages.append({
"role": "user",
"content": results
})
Unix 哲学:一切皆文件
Unix的“一切皆文件”是其核心设计哲学之一,由肯·汤普森和丹尼斯·里奇在20世纪70年代提出。它的基本思想是:将系统中的各种资源(如硬件设备、进程、网络连接、管道等)都抽象为文件,并提供统一的接口(open、read、write、close等)进行操作。
具体体现
- 普通文件:存储在磁盘上的数据。
- 设备文件:如
/dev/sda表示硬盘,/dev/tty表示终端,通过读写这些文件与硬件交互。 - 管道和套接字:进程间通信也被抽象为文件描述符。
- 虚拟文件系统:如
/proc目录下的文件动态反映进程和内核信息,操作它们如同操作普通文件。
优点
- 统一接口:程序员只需学习一套I/O API,简化了开发。
- 灵活性:可以用简单的工具组合完成复杂任务(如用
cat读取设备内容)。 - 扩展性:新资源只需实现文件操作接口即可融入系统。
局限
- 并非所有操作都能完美映射为文件读写(如某些设备控制需用
ioctl)。 - 现代Unix/Linux系统仍保留此哲学,但也增加了其他抽象(如网络套接字API)。
这一哲学让Unix系统变得简洁、优雅,成为其经久不衰的基石之一。
补充推荐
playwright MCP: www.xiaohongshu.com/explore/68e…
obsidian
参考资料
playwright MCP: www.xiaohongshu.com/explore/68e…
claude code 结合 obsidian 使用