Skip to content

agent-guards: harness speed env in the managed settings drop-in - #1161

Merged
scuttletoby merged 3 commits into
mainfrom
fork-kit/harness-speed-env
Nov 28, 2026
Merged

scuttletoby merged 3 commits into
mainfrom
fork-kit/harness-speed-env

Conversation

@scuttletoby

@scuttletoby scuttletoby commented Nov 28, 2026 •

Copy link
Copy Markdown
Owner

Part of #1094 (agent speed). This PR covers the harness speed settings; the rest of #1094 is not touched here.

What

With --settings, the agent-guards managed settings drop-in (/etc/claude-code/managed-settings.d/agent-guards.json) now also has an "env" of Claude Code speed variables. Every session on a fork machine gets them. The defaults are config (agent_guards.config.HARNESS_ENV). A machine can change any of them in its machine file, as rows under "agent-guards"."harnessEnv":

"harnessEnv": [{ "name": "API_TIMEOUT_MS", "value": "240000" }, { "name": "DISABLE_AUTOUPDATER", "value": null }]

A row's value replaces the default. null takes the variable out. Any other variable can be added.

Variable Default Docs check
BASH_MAX_OUTPUT_LENGTH 12000 listed (default 30000, max 150000; the bashOutputMaxChars setting overrides it)
MAX_MCP_OUTPUT_TOKENS 15000 listed (default 25000). A larger answer is saved to a file (one more Read). A t3_thread_read page (at most 30000 bytes, about 7.5k tokens) fits twice
API_TIMEOUT_MS 300000 listed (default 600000). Besides the wait for response headers, it also caps a large request's first-byte watchdog and bounds a whole non-streaming fallback answer, so it is 5 min, not 3
DISABLE_AUTOUPDATER off listed. The kit ships no update path, so it is opt-in per machine ("1")
CLAUDE_CODE_PROMPT_CACHE_TTL, CLAUDE_CODE_SUBAGENT_PROMPT_CACHE_TTL, CLAUDE_CODE_AUTO_COMPACT_WINDOW, FORCE_PROMPT_CACHING_5M refused listed, but T3 sets them for each session. Managed env would silently override T3's value, so a harnessEnv row naming one is left out and named. Set them in T3

Every name was checked against code.claude.com/docs/en/env-vars and settings-reference (docs.claude.com/…/settings now redirects there). No name was dropped as unlisted. The prompt-cache TTL (promptCacheTtl/subagentPromptCacheTtl, and their env forms) and the auto-compact window are not set by the kit, because T3 sets them per session (review round 1).

Merge, never clobber

  • Claude Code merges managed-settings.json first and then managed-settings.d/*.json alphabetically. env merges key by key and the later file wins. So the installer leaves out of the drop-in any variable that managed-settings.json or another drop-in already sets, and names it (managed settings env left to <file>: …). It never writes those files.
  • Managed env wins over user and project env and over a shell export. That is how managed settings work. A machine that needs another value sets it in harnessEnv.
  • The rows are not an object keyed by variable name because the machine file refuses keys that look like a secret, and MAX_MCP_OUTPUT_TOKENS matches token. A name that looks like a secret is still refused here (the drop-in is world-readable), unless it is one of the kit's own known names. Bad rows and repeated names are left out and named by the installer and agent-guards self-check.

State

  • Runs again: unchanged input gives byte-identical files (write_file skips the write; covered by a snapshot test with an override and a foreign managed env).
  • Stops half-way: the env is computed in plan and written only in the existing settings step, together with the hooks, in one atomic write. The existing every-step stop tests pass with env on. A stop before settings leaves the old drop-in (with or without env) whole, and the next run writes the new one.
  • Old or empty state: a drop-in from an earlier release (hooks only) still counts as the kit's (wiring.ours now accepts an optional env of strings) and is rewritten with env. No machine file, no section, no harnessEnv or [] gives the defaults. A machine file that cannot be read gives the defaults with a warning, and the install goes on (this is speed, not safety). --no-settings removes the env along with the hooks.

Tests (written first, red on main, then green)

  • install.test.py (32 OK): defaults in the drop-in for no machine file / no section / no key / empty list; a machine value wins and null removes the key (all off → no env key); a foreign managed env is not clobbered; a broken machine file or bad/secret rows keep the defaults and are named; an old hooks-only drop-in upgrades and rollback removes it; idempotent re-run.
  • config.test.py (18 OK): row parsing and problems; load_all accepts harnessEnv and names its problems; the example file.
  • wiring.test.py (24 OK): drop_in_text(env=…), ours with env. agent-guards self-check compares the drop-in's env with what the machine file gives now (less what other managed files set) and names each difference, e.g. a harnessEnv edit without a reinstall, or an old drop-in without env.
  • Round 1 (config.test.py, 20 OK): DISABLE_AUTOUPDATER off by default, API_TIMEOUT_MS ≥ 300000, MAX_MCP_OUTPUT_TOKENS ≥ two t3_thread_read pages, and T3-set variables refused.
  • Also run, all OK: agent-guards fast, read-size, facts, poll-loop, batch-nudge; common kit_install (189), machine_file, alert; fork-checks schema/upstream-files/seam scripts and their tests (197).

Note

An older release's installer does not know about env, so it treats the new drop-in as not its own: installing an older sha with --settings refuses until the drop-in is removed by hand. Rollback with install --no-settings on the current release works as before.

🤖 Generated with Claude Code

With --settings the drop-in now carries an "env" of Claude Code speed
variables (BASH_MAX_OUTPUT_LENGTH 12000, MAX_MCP_OUTPUT_TOKENS 8000,
API_TIMEOUT_MS 180000, DISABLE_AUTOUPDATER 1; auto-compact window and
prompt-cache TTLs known but off). The machine file's
"agent-guards"."harnessEnv" rows override a value or take it out (null).
A variable another managed settings file sets is left to it. A drop-in
of an earlier release (hooks only) is still the kit's and upgrades.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@scuttletoby

Copy link
Copy Markdown
Owner Author

lens: code · reviewer: Claude Opus 5.5 · read at: 7f01791

blocker: none
major: DISABLE_AUTOUPDATER=1 is now on by default for every session on every fleet machine, and config.HARNESS_ENV says "updates come with the kit". README says the same. No kit, timer or CI step updates Claude Code: fork-kit has no claude update or install step, and T3's provider Update button is manual. So every machine stays on the Claude Code version it has now, security fixes included, until someone updates it by hand. The name is real: in Claude Code 2.1.325 it turns off only the background updater, and claude update still works. The premise is what's wrong. Fix: default it to None (opt-in per machine), or ship the update path in this PR. Either way, correct the comment and the README.
minor: API_TIMEOUT_MS=180000 does more than "time to the response headers". In 2.1.325 it is also the cap on the stream first-byte watchdog: min(first-byte window + 1 s per 32 KB of request, API_TIMEOUT_MS - 1 s). A large-context request gets 179 s instead of a window that grows with the request. One other timeout also uses it in place of its own 300000 default. A non-streaming fallback request is bounded by it for the whole answer. Reword the README row, or consider 300000.
minor: MAX_MCP_OUTPUT_TOKENS=8000 does not break anything: over the cap, 2.1.325 saves the result to a file and the agent needs an extra Read. But T3's own t3_thread_read pages go up to 30000 bytes, which is about 7.5k tokens at Claude Code's length/4 estimate. That margin is thin, and T3 tools with no size cap will go over it. Measure before calling this a speed win.
minor: managed env wins over T3's own per-launch env. T3 sets CLAUDE_CODE_PROMPT_CACHE_TTL for sub-agents (claudeQueryEnvironment) and CLAUDE_CODE_AUTO_COMPACT_WINDOW in its launch settings. Its resolveClaudeEnv reads only user, project and local settings, never managed ones. If a machine turns either variable on in harnessEnv, T3's per-thread value is silently overridden and T3 shows the wrong window. Both are off by default, so this has no effect today. The README should say not to set these here while T3 sets them per session.
minor: agent-guards self-check checks only that the drop-in's env is text. It does not compare it with what the machine file now gives, so a harnessEnv edit without a reinstall passes silently. The README does say "next install"; a note in self-check would make this visible.

Checked and fine. All four default names are real: each is read in the 2.1.325 binary, and none is ignored. BASH_MAX_OUTPUT_LENGTH gives way to bashOutputMaxChars and is clamped to 150000. No default touches permissions, hooks, telemetry or privacy. Secret-looking names are refused (ANTHROPIC_API_KEY repro'd) and MAX_MCP_OUTPUT_TOKENS is let through. API_TIMEOUT_MS: 0 means no timeout in Claude Code, not an instant one. A foreign managed-settings.json or another managed-settings.d/*.json that sets a key is left alone and named. A JSON list or a parse error in a foreign file is skipped. Paths are Linux only (/etc/claude-code), unchanged from before. WSL is Linux. This PR adds no macOS path.

State (runs again / stops half-way / old or empty state).

  • Runs again: the drop-in is rebuilt whole from defaults plus rows, so a variable dropped from HARNESS_ENV disappears on the next install. write_file skips unchanged text.
  • Stops half-way: the env is computed in plan and written only in the settings step, together with the hooks. The write is atomic: mkstemp in the same folder, then os.replace. A leftover temp file is named .agent-guards.json.*.tmp, which is a dotfile and not *.json, so Claude Code does not load it.
  • Old state: an old drop-in with hooks only is still accepted by ours() and upgraded. A hand edit to the kit's own drop-in env is overwritten, which is acceptable for a kit-owned file.
  • Empty state: an old machine.json with no section or no harnessEnv gives the defaults. A machine file that cannot be read gives the defaults with a warning.
  • An older release's installer refuses the new drop-in. The PR body says so.

🤖 Generated with Claude Code

- DISABLE_AUTOUPDATER is off by default: the kit ships no update path,
  so it would freeze each machine's Claude Code version. Opt-in per
  machine.
- API_TIMEOUT_MS 300000: it also caps a large request's first-byte
  watchdog and a whole non-streaming fallback answer.
- MAX_MCP_OUTPUT_TOKENS 15000: a t3_thread_read page fits twice.
- Variables T3 sets per session (prompt-cache TTLs, auto-compact
  window, FORCE_PROMPT_CACHING_5M) are refused in harnessEnv: managed
  env would silently override T3's value.
- agent-guards self-check names each variable where the drop-in and
  the machine file differ (an edit without a reinstall).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@scuttletoby

Copy link
Copy Markdown
Owner Author

Fix round 1, head 284143a. Each point now has a test written first: it failed on the previous head and passes now.

  • major (DISABLE_AUTOUPDATER): now None (off) by default and opt-in per machine with "1". The "updates come with the kit" claim is gone from config.py, the installer doc and the README. They now say the kit ships no update path and that turning the updater off would freeze the version, security fixes included.
  • API_TIMEOUT_MS: raised to 300000. The README row and the config comment now say it also caps a large request's first-byte watchdog and bounds a whole non-streaming fallback answer.
  • MAX_MCP_OUTPUT_TOKENS: raised to 15000, which is twice a t3_thread_read page (THREAD_READ_RESULT_MAX_BYTES 30000 is about 7.5k tokens). A test pins that it stays at least two pages. It is still below Claude Code's 25000.
  • T3-set variables: CLAUDE_CODE_PROMPT_CACHE_TTL, CLAUDE_CODE_SUBAGENT_PROMPT_CACHE_TTL, CLAUDE_CODE_AUTO_COMPACT_WINDOW and FORCE_PROMPT_CACHING_5M (which overrides both TTLs) are now refused in harnessEnv. The row is left out and named by the installer and self-check, so a machine cannot override T3's per-session value. They are no longer in HARNESS_ENV.
  • self-check: agent-guards self-check now compares the drop-in's env with what the machine file gives now, minus what other managed files set. It reports each difference as a problem ("X is A in the drop-in, the machine file gives B: run the installer again"). This covers a harnessEnv edit without a reinstall and an old drop-in with no env.

Tests: agent-guards install 32, config 20, wiring 24, fast 45; common machine_file 27; the fork-checks scripts pass.

🤖 Generated with Claude Code

@scuttletoby

Copy link
Copy Markdown
Owner Author

lens: code · reviewer: Claude Opus 5.5 · read at: 284143a

blocker: none
major: none
minor: T3_SETS is a hand-picked list, but T3 reads more variables from its own view of the session env, and that view leaves out managed settings. harness_env accepts CLAUDE_CODE_TMPDIR and CLAUDE_CODE_TASK_LIST_ID with no problem (repro'd). T3 then tails task output under its own CLAUDE_CODE_TMPDIR (ClaudeTaskOutputTail.ts:33) and reads plan steps from tasks/<CLAUDE_CODE_TASK_LIST_ID or thread id> (ClaudeAdapterV2.ts:6145). If a machine set one of these in harnessEnv and Claude Code applied it, T3 would look in the wrong place. Not verified in the binary that managed env reaches these two. No default sets them, so this has no effect today. Add them to T3_SETS, or have the README say that any variable T3 sets or reads per session does not belong here.
minor: a null row for a refused name, for example {"name": "CLAUDE_CODE_PROMPT_CACHE_TTL", "value": null}, asks for nothing, but it is still a warning, and agent-guards self-check reports it as a PROBLEM (repro'd with harness_env). The round-0 machine.example.json had exactly this row. No machine has it, because harnessEnv is not on main yet. Taking null for a refused name quietly would be kinder. Leaving it as it is also works.

round 1, fixed: DISABLE_AUTOUPDATER is now None (opt-in with "1"). config.py, the installer doc, the README and machine.example.json no longer say "updates come with the kit". A test pins the default.
round 1, fixed: API_TIMEOUT_MS is now 300000. The README row and the comment name the first-byte watchdog and the non-streaming fallback. A test pins ≥ 300000.
round 1, fixed: MAX_MCP_OUTPUT_TOKENS is now 15000, at least two t3_thread_read pages. A test pins it.
round 1, fixed: the two prompt-cache TTLs, CLAUDE_CODE_AUTO_COMPACT_WINDOW and FORCE_PROMPT_CACHING_5M are refused. A row naming one is left out and named, before the secret check, so the refusal message is the right one. They are gone from HARNESS_ENV.
round 1, fixed: self-check compares the drop-in's env with defaults + machine rows − other managed files. It uses the same wiring.env_for as the installer, which this PR refactors out of the installer, so the two cannot drift. Tests cover: the defaults (OK), non-text (problem), an old drop-in without env (problem), a machine edit without a reinstall (problem, with both values named), after a reinstall (OK), and a variable a sibling file sets (OK).

Checked and fine. Self-check reads the same machine file as the installer: the same default path, and both owner uids are 0. A broken file gives the defaults in both, so the comparison matches what the installer would write. Values are compared as text on both sides (str() of whole numbers). The comparison runs only when the hooks match this release, so a foreign drop-in still gets the "not the kit's drop-in" problem first. other_env skips the drop-in itself, and the installer's managed path resolves to the same /etc/claude-code/managed-settings.json as before. The show() path in the "left to" line is covered by the install test. A lowercase variable name is not refused, which is right: Claude Code does not read it.

State (runs again / stops half-way / old or empty state).

  • Runs again: the env is rebuilt whole each time, and write_file skips identical text. A drop-in from the round-0 head with DISABLE_AUTOUPDATER=1 loses it on the next install. Until then, self-check names it.
  • Stops half-way: no change from round 1. The env is computed in plan and written atomically with the hooks in the settings step. Self-check only reads.
  • Old or empty state: a hooks-only drop-in is now a self-check PROBLEM ("not set in the drop-in") until the next install. That is the intended signal, and nothing outside tests calls the agent-guards self-check on a timer. A missing machine file, a missing section or [] gives the defaults on both sides. A machine file that cannot be read gives the defaults, plus a "machine file:" problem.

🤖 Generated with Claude Code

@scuttletoby scuttletoby added the fork:merge-ready Merge conveyor: lenses done, merge when green (PRs) label Nov 28, 2026
@scuttletoby
scuttletoby merged commit d3d19ed into main Nov 28, 2026
27 checks passed
scuttletoby added a commit that referenced this pull request Nov 28, 2026
* agent-guards: harness speed env in the managed settings drop-in

With --settings the drop-in now carries an "env" of Claude Code speed
variables (BASH_MAX_OUTPUT_LENGTH 12000, MAX_MCP_OUTPUT_TOKENS 8000,
API_TIMEOUT_MS 180000, DISABLE_AUTOUPDATER 1; auto-compact window and
prompt-cache TTLs known but off). The machine file's
"agent-guards"."harnessEnv" rows override a value or take it out (null).
A variable another managed settings file sets is left to it. A drop-in
of an earlier release (hooks only) is still the kit's and upgrades.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* agent-guards: harnessEnv review round 1

- DISABLE_AUTOUPDATER is off by default: the kit ships no update path,
  so it would freeze each machine's Claude Code version. Opt-in per
  machine.
- API_TIMEOUT_MS 300000: it also caps a large request's first-byte
  watchdog and a whole non-streaming fallback answer.
- MAX_MCP_OUTPUT_TOKENS 15000: a t3_thread_read page fits twice.
- Variables T3 sets per session (prompt-cache TTLs, auto-compact
  window, FORCE_PROMPT_CACHING_5M) are refused in harnessEnv: managed
  env would silently override T3's value.
- agent-guards self-check names each variable where the drop-in and
  the machine file differ (an edit without a reinstall).

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
@scuttletoby
scuttletoby deleted the fork-kit/harness-speed-env branch November 29, 2026 20:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork:merge-ready Merge conveyor: lenses done, merge when green (PRs)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant