网站Logo 网友马大帅的博客

claude code 开发环境配置

ughostx
9
2026-05-14

Claude Code(也称为Claude for Code)是Anthropic公司开发的AI编程助手,基于Claude系列模型优化而来,专门用于代码生成、调试、解释和优化等编程任务。

这一篇主要介绍在日常工作中使用claude code的经验与教程(基于ubuntu的开发环境)~

安装

//TODO

连接ai大模型

此处主要介绍连接基于llama.cpp底座的私有模型API的用法。
claude code会解析根目录下~/.claude/settings.json用于连接模型服务。该json也是配置其它功能的主要用户配置文件。

  "env": {
    "ANTHROPIC_API_KEY": "sk-no-key-required",  ###私有配置一般不需要key
    "ANTHROPIC_BASE_URL": "http://23.23.23.23:12345",  ####模型服务地址,注意最新的llamacpp已默认支持Anthropic协议
    "ANTHROPIC_MODEL": "Qwen3.6-35B-A3B-Claude-4.7-Opus-Reasoning-Distilled.Q8_0.gguf"
  },
  "language": "简体中文"
}

基于上述配置,打开Claude Code后就可以进行基本的使用了。

个性化配置

普通的claude code界面比较简陋如下:

配置底部状态栏

参考:https://code.claude.com/docs/zh-CN/statusline

用户配置文件将 type 添加设置 "command" 并将 command 指向脚本路径或内联 shell 命令

{
  "statusLine": {
    "type": "command",
    "command": "~/.claude/statusline.sh",
    "padding": 2
  }
}

在~/.claude/目录添加statusline.sh,并写入以下内容:

#!/bin/bash
# Read JSON data that Claude Code sends to stdin
input=$(cat)

# Extract fields using jq
MODEL=$(echo "$input" | jq -r '.model.display_name')
DIR=$(echo "$input" | jq -r '.workspace.current_dir')
# The "// 0" provides a fallback if the field is null
PCT=$(echo "$input" | jq -r '.context_window.used_percentage // 0' | cut -d. -f1)

# Output the status line - ${DIR##*/} extracts just the folder name
echo "[$MODEL] 📁 ${DIR##*/} | ${PCT}% context"

之后再打开claude code就会在底部状态栏显示模型名称|工程目录|上下文状态等,如下:

甚至可以在初始状态下在claude code里让它自己创建类似的配置,它会借助ai来完成配置文件的创建并写入用户配置文件中。

/statusline show model name and context percentage with a progress bar

动物装饰