固定克劳德代码

今天早些时候我看到了这篇帖子柯蒂斯·坡.

来源::

就在昨天,我也因为类似的原因把我的Claude代码钉到了Opus 4.8。Opus 5似乎并没有明显优于4.8,在某些方面感觉更差。我无法提供基准测试来证明这一点,所以这主要是随便说说,但我感觉我得到的结果更糟,更冗长,范围更广,有时甚至让人摸不着头脑。做基本事情花的时间变长了。只要4.8还能用,我很乐意切换回去。新并不意味着一定更好。如果你曾经发布过自己的软件,你很可能知道这是真的。

Curtis的帖子里有一个快速的变通方法,但我做法不同,所以想展示一下。当我这么说时I做点不一样的,这只是克劳德为我写的剧本。(不过,这篇文章并非克洛德本人。)

几周前,我写过一篇关于被Claude升级彩蛋咬伤的经历:克劳德代码:失踪的剖析.后来我很高兴读到一篇文章毛里西奥·帕蒂尼奥·塞万提斯那是引用了我的文章。我也很高兴看到这篇文章倡导一种类似于我做法的Claude默认管理方式。

关于别针的乐趣

照片:安全别针作者原谷人, 授权下CC BY-SA 3.0.

我得出结论,我更喜欢无聊的Claude Code升级,所以我一直在踩着它默认的YOLO模式。这有不止一种方法,但我想要一种能立刻贯穿所有新会话,不需要我做太多事情的东西,因为我反对做繁琐的工作。事实证明,你可以通过Claude的配置强制设置环境变量。这样我就能让环境变量瞬间传播到新的Claude会话,而不必亲自更新我所有过多的环境环境tmux会谈。

所以,我最终得到的配置大致是这样(截断的)版本:

{
 "env": {
 "DISABLE_AUTOUPDATER": "1",
 "FORCE_AUTOUPDATE_PLUGINS": "1"
 },
 "model": "claude-opus-4-8",
 "availableModels": [
 "claude-opus-4-8",
 "opus",
 "sonnet",
 "haiku"
 ]
}

这里的亮点包括:DISABLE_AUTOUPDATER它阻止了 Claude 在后台愉快地更新自己,但也阻止了插件做同样的事。我对插件的风险容忍度更高,所以我通过以下方式重新启用了这种行为FORCE_AUTOUPDATE_PLUGINS.然后我通过以下方式选择一个默认型号model并列出我通常想选择的模型。你会注意到Fable没在那个列表里,因为我上次跑的时候/model fable我唯一看到的是很多信用点化为灰烬。我觉得我做的事情不够复杂,不需要《Fable》,而且我对那些能随外国政府随意开关的东西也不是特别热衷。

所以这给我找到了追溯到Opus 4.8的针脚,但我不是手动操作。我有太多地方,我的点文件活着,所以我希望它能被脚本化且幂零。我给你们我的配置和(买者自负)今晚娱乐节目中由LLM生成的部分。它目前存放在我的点文件里:configure/claude-settings.sh.

包含非Olaf编写的LLM生成内容

#!/usr/bin/env bash

# Force host-level Claude Code settings that must not live in this repo.
# ~/.claude/settings.json is deliberately untracked (it holds the plugin list
# and marketplace config), so we merge individual keys into whatever is
# already there rather than symlinking or overwriting the file.
#
# bin/nn sets the same env vars for nono-sandboxed sessions. Setting them here
# covers plain `claude` runs, which never go through bin/nn.

set -eu -o pipefail

SETTINGS="$HOME/.claude/settings.json"

mkdir -p "$(dirname "$SETTINGS")"

if [[ ! -f $SETTINGS ]]; then
 echo '{}' >"$SETTINGS"
fi

set_env_key() {
 local key=$1 value=$2

 if jq -e --arg k "$key" --arg v "$value" '.env[$k] == $v' "$SETTINGS" >/dev/null; then
 return
 fi

 jq --arg k "$key" --arg v "$value" '.env[$k] = $v' "$SETTINGS" >"$SETTINGS.tmp"
 mv "$SETTINGS.tmp" "$SETTINGS"
 echo "set env.$key=$value in $SETTINGS"
}

# Like set_env_key, but for a top-level key whose value is raw JSON (bool,
# number, string, object) rather than a string env var.
set_key() {
 local key=$1 value=$2

 if jq -e --arg k "$key" --argjson v "$value" '.[$k] == $v' "$SETTINGS" >/dev/null; then
 return
 fi

 jq --arg k "$key" --argjson v "$value" '.[$k] = $v' "$SETTINGS" >"$SETTINGS.tmp"
 mv "$SETTINGS.tmp" "$SETTINGS"
 echo "set $key=$value in $SETTINGS"
}

# Pin the claude binary; installer/claude.sh owns which version we land on.
set_env_key DISABLE_AUTOUPDATER 1

# ...but keep plugins updating, which DISABLE_AUTOUPDATER would otherwise
# freeze alongside the CLI.
set_env_key FORCE_AUTOUPDATE_PLUGINS 1

# Compact automatically instead of needing a manual /compact. Compaction fires
# at window-33k (20k reserved for output, 13k buffer), and the window itself is
# clamped to the model max -- so on a 200k model anything above 200000 is a
# no-op, and anything below just compacts sooner for no saving. 200000 is the
# max useful value; it also keeps the clamp meaningful if 1M context is ever
# re-enabled above.
set_key autoCompactEnabled true
set_key autoCompactWindow 200000

# Stay on 200k-class context instead of the native 1M window some models (e.g.
# Sonnet 5) offer. Long context is rarely worth the spend here, and a hard
# ceiling keeps sessions focused. This is the setting that actually caps token
# spend -- autoCompactWindow above only moves when compaction fires.
set_env_key CLAUDE_CODE_DISABLE_1M_CONTEXT 1

# Cap concurrently-running subagents so one message can't fan out unbounded
# background agents. Added in claude 2.1.217, where it defaults to 20; inert on
# older versions. DISABLE_AUTOUPDATER above means installer/claude.sh decides
# when we actually land on a version that reads this.
set_env_key CLAUDE_CODE_MAX_CONCURRENT_SUBAGENTS 5

# Allowlist the models offered by /model, --model, ANTHROPIC_MODEL and resume,
# which keeps Fable out of the picker. Experimental: unverified whether this key
# is honored; harmless if ignored since it only narrows an allowlist. The pinned
# opus id below is listed explicitly so it matches the allowlist exactly rather
# than relying on the "opus" family alias, which resolves to the newest Opus.
set_key availableModels '["claude-opus-4-8","opus","sonnet","haiku"]'

# Default new sessions to Opus 4.8 rather than whatever the "opus" alias points
# at today (Opus 5). /model overwrites this in ~/.claude/settings.json for the
# session; --model and ANTHROPIC_MODEL override for a single run.
set_key model '"claude-opus-4-8"'

# Default new sessions to medium reasoning effort to trim thinking-token spend.
# /effort overwrites this in ~/.claude/settings.json; --effort and
# CLAUDE_CODE_EFFORT_LEVEL override for a single session. Accepts
# low/medium/high/xhigh (no "max").
set_key effortLevel '"medium"'

结束LLM生成内容

到目前为止,这个方法对我来说效果不错。现在我可以按自己的计划升级Claude Code,并在各种环境中调整配置设置,只需运行我的点文件安装程序即可。

添加评论
点赞收藏
点踩分享查看原文
评论
?
参与讨论