subconscious-cli 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,12 @@
1
1
  {
2
2
  "_generated": "Source of truth: agents/registry.json. Do not edit by hand.",
3
3
  "defaults": {
4
- "model": "subconscious/tim-qwen3.6-27b",
4
+ "model": "subconscious/glm-5.2",
5
+ "models": [
6
+ "subconscious/glm-5.2",
7
+ "subconscious/tim-qwen3.6-27b",
8
+ "subconscious/deepseek-v4-flash-marathon"
9
+ ],
5
10
  "baseUrl": "https://api.subconscious.dev",
6
11
  "baseUrlV1": "https://api.subconscious.dev/v1",
7
12
  "keyPlaceholder": "your_key",
@@ -10,14 +15,15 @@
10
15
  "agents": [
11
16
  {
12
17
  "id": "claude-code",
18
+ "command": "claude",
13
19
  "exampleDir": "claude_code",
14
20
  "name": "Claude Code",
15
21
  "aliases": [
16
- "claude",
22
+ "claude-code",
17
23
  "claudecode"
18
24
  ],
19
25
  "displayName": "Claude Code + Subconscious",
20
- "description": "Run Claude Code on your hosted Subconscious model no code changes, just env vars.",
26
+ "description": "Run Claude Code on your hosted Subconscious model using the ol-runbook environment and telemetry setup.",
21
27
  "framework": "Claude Code",
22
28
  "language": "shell",
23
29
  "category": "coding-agent",
@@ -35,24 +41,86 @@
35
41
  "win32": "powershell -ExecutionPolicy Bypass -Command \"irm https://claude.ai/install.ps1 | iex\"",
36
42
  "fallback": "npm i -g @anthropic-ai/claude-code"
37
43
  },
44
+ "runbook": {
45
+ "mode": "launch",
46
+ "script": "claude-code/run.sh",
47
+ "setupScript": "claude-code/install.sh"
48
+ },
38
49
  "launch": "claude",
39
50
  "env": {
40
51
  "ANTHROPIC_BASE_URL": "{baseUrl}",
41
52
  "ANTHROPIC_AUTH_TOKEN": "{apiKey}",
42
53
  "ANTHROPIC_MODEL": "{model}",
43
54
  "ANTHROPIC_SMALL_FAST_MODEL": "{model}",
44
- "DISABLE_AUTO_COMPACT": "true"
55
+ "ANTHROPIC_DEFAULT_OPUS_MODEL": "subconscious/glm-5.2",
56
+ "ANTHROPIC_DEFAULT_OPUS_MODEL_NAME": "subconscious/glm-5.2",
57
+ "ANTHROPIC_DEFAULT_OPUS_MODEL_DESCRIPTION": "Subconscious default model",
58
+ "ANTHROPIC_DEFAULT_SONNET_MODEL": "subconscious/tim-qwen3.6-27b",
59
+ "ANTHROPIC_DEFAULT_SONNET_MODEL_NAME": "subconscious/tim-qwen3.6-27b",
60
+ "ANTHROPIC_DEFAULT_SONNET_MODEL_DESCRIPTION": "Subconscious TIM Qwen 3.6 27B",
61
+ "ANTHROPIC_DEFAULT_HAIKU_MODEL": "subconscious/deepseek-v4-flash-marathon",
62
+ "ANTHROPIC_DEFAULT_HAIKU_MODEL_NAME": "subconscious/deepseek-v4-flash-marathon",
63
+ "ANTHROPIC_DEFAULT_HAIKU_MODEL_DESCRIPTION": "Subconscious DeepSeek V4 Flash Marathon",
64
+ "CLAUDE_CODE_SUBAGENT_MODEL": "{model}",
65
+ "CLAUDE_CODE_MAX_CONCURRENT_SUBAGENTS": "4",
66
+ "CLAUDE_CODE_MAX_SUBAGENT_SPAWN_DEPTH": "1",
67
+ "CLAUDE_CODE_AUTO_COMPACT_WINDOW": "1000000",
68
+ "CLAUDE_CODE_MAX_CONTEXT_TOKENS": "3000000",
69
+ "CLAUDE_CODE_ENABLE_TELEMETRY": "1",
70
+ "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1",
71
+ "OTEL_LOGS_EXPORTER": "otlp",
72
+ "OTEL_EXPORTER_OTLP_PROTOCOL": "http/json",
73
+ "OTEL_EXPORTER_OTLP_LOGS_ENDPOINT": "{baseUrl}/v1/logs",
74
+ "OTEL_EXPORTER_OTLP_HEADERS": "x-api-key={apiKey}",
75
+ "OTEL_EXPORTER_OTLP_TIMEOUT": "2000",
76
+ "OTEL_LOGS_EXPORT_INTERVAL": "2000"
77
+ }
78
+ },
79
+ {
80
+ "id": "codex",
81
+ "command": "codex",
82
+ "exampleDir": "codex",
83
+ "name": "Codex CLI",
84
+ "aliases": [],
85
+ "displayName": "Codex + Subconscious",
86
+ "description": "Run Codex on your hosted Subconscious model using the ol-runbook provider, model catalog, and compaction hooks.",
87
+ "framework": "Codex",
88
+ "language": "shell",
89
+ "category": "coding-agent",
90
+ "tags": [
91
+ "local",
92
+ "cli",
93
+ "agents"
94
+ ],
95
+ "protocol": "openai",
96
+ "homepage": "https://developers.openai.com/codex",
97
+ "bin": "codex",
98
+ "install": {
99
+ "darwin": "npm i -g @openai/codex",
100
+ "linux": "npm i -g @openai/codex",
101
+ "win32": "npm i -g @openai/codex"
102
+ },
103
+ "runbook": {
104
+ "mode": "launch",
105
+ "script": "codex/run.sh",
106
+ "setupScript": "codex/install.sh"
107
+ },
108
+ "launch": "codex -c model={model} -c model_provider=subconscious -c web_search=disabled -c model_providers.subconscious.name=Subconscious -c model_providers.subconscious.base_url={baseUrlV1} -c model_providers.subconscious.wire_api=responses -c model_providers.subconscious.env_key=SUBCONSCIOUS_API_KEY -c model_providers.subconscious.stream_idle_timeout_ms=300000",
109
+ "env": {
110
+ "SUBCONSCIOUS_API_KEY": "{apiKey}",
111
+ "SUBCONSCIOUS_GATEWAY_URL": "{baseUrl}"
45
112
  }
46
113
  },
47
114
  {
48
115
  "id": "opencode",
116
+ "command": "opencode",
49
117
  "exampleDir": "opencode",
50
118
  "name": "OpenCode",
51
119
  "aliases": [
52
120
  "open-code"
53
121
  ],
54
122
  "displayName": "OpenCode + Subconscious",
55
- "description": "Run OpenCode on your hosted Subconscious model registered as a custom provider, injected non-invasively (nothing written to your OpenCode config).",
123
+ "description": "Run OpenCode on your hosted Subconscious model using the ol-runbook provider and context settings.",
56
124
  "framework": "OpenCode",
57
125
  "language": "shell",
58
126
  "category": "coding-agent",
@@ -69,25 +137,54 @@
69
137
  "linux": "npm i -g opencode-ai",
70
138
  "win32": "npm i -g opencode-ai"
71
139
  },
140
+ "runbook": {
141
+ "mode": "launch",
142
+ "script": "opencode/run.sh",
143
+ "setupScript": "opencode/install.sh"
144
+ },
72
145
  "launch": "opencode",
73
146
  "configEnv": "OPENCODE_CONFIG_CONTENT",
74
147
  "env": {
75
148
  "SUBCONSCIOUS_API_KEY": "{apiKey}",
149
+ "SUBCONSCIOUS_GATEWAY_URL": "{baseUrl}",
76
150
  "OPENCODE_CONFIG_CONTENT": {
77
151
  "$json": {
78
152
  "$schema": "https://opencode.ai/config.json",
79
153
  "provider": {
80
154
  "subconscious": {
81
155
  "npm": "@ai-sdk/openai-compatible",
82
- "name": "Subconscious",
156
+ "name": "Subconscious Gateway",
83
157
  "options": {
84
158
  "baseURL": "{baseUrlV1}",
85
- "apiKey": "{env:SUBCONSCIOUS_API_KEY}"
159
+ "apiKey": "{env:SUBCONSCIOUS_API_KEY}",
160
+ "headers": {
161
+ "x-subconscious-client": "opencode"
162
+ }
86
163
  },
87
164
  "models": {
88
- "{model}": {
89
- "name": "Subconscious",
90
- "tools": true
165
+ "subconscious/glm-5.2": {
166
+ "name": "subconscious/glm-5.2",
167
+ "tools": true,
168
+ "limit": {
169
+ "context": 5000000,
170
+ "output": 65536
171
+ }
172
+ },
173
+ "subconscious/tim-qwen3.6-27b": {
174
+ "name": "subconscious/tim-qwen3.6-27b",
175
+ "tools": true,
176
+ "limit": {
177
+ "context": 5000000,
178
+ "output": 65536
179
+ }
180
+ },
181
+ "subconscious/deepseek-v4-flash-marathon": {
182
+ "name": "subconscious/deepseek-v4-flash-marathon",
183
+ "tools": true,
184
+ "limit": {
185
+ "context": 5000000,
186
+ "output": 65536
187
+ }
91
188
  }
92
189
  }
93
190
  }
@@ -98,42 +195,59 @@
98
195
  }
99
196
  },
100
197
  {
101
- "id": "aider",
102
- "exampleDir": "aider",
103
- "name": "Aider",
198
+ "id": "cursor",
199
+ "command": "cursor",
200
+ "name": "Cursor",
104
201
  "aliases": [],
105
- "displayName": "Aider + Subconscious",
106
- "description": "Run Aider on your hosted Subconscious model — no code changes, just env vars.",
107
- "framework": "Aider",
202
+ "description": "Install the ol-runbook Cursor conversation and compaction hooks, then finish model setup in Cursor Settings.",
203
+ "framework": "Cursor",
108
204
  "language": "shell",
109
205
  "category": "coding-agent",
110
206
  "tags": [
111
207
  "local",
112
- "cli",
208
+ "ide",
113
209
  "agents"
114
210
  ],
115
211
  "protocol": "openai",
116
- "homepage": "https://aider.chat",
117
- "bin": "aider",
118
- "install": {
119
- "darwin": "python3 -m pip install aider-install && aider-install",
120
- "linux": "python3 -m pip install aider-install && aider-install",
121
- "win32": "python -m pip install aider-install && aider-install"
122
- },
123
- "launch": "aider --model openai/{model}",
124
- "env": {
125
- "OPENAI_API_BASE": "{baseUrlV1}",
126
- "OPENAI_API_KEY": "{apiKey}"
212
+ "homepage": "https://cursor.com",
213
+ "runbook": {
214
+ "mode": "setup",
215
+ "script": "cursor/install.sh",
216
+ "setupScript": "cursor/install.sh"
127
217
  }
128
218
  },
129
219
  {
130
- "id": "codex",
131
- "exampleDir": "codex",
132
- "name": "Codex CLI",
220
+ "id": "copilot",
221
+ "command": "copilot",
222
+ "name": "GitHub Copilot (VS Code)",
223
+ "aliases": [
224
+ "vscode",
225
+ "vs-code"
226
+ ],
227
+ "description": "Install the ol-runbook VS Code custom endpoint and Copilot conversation/compaction hooks.",
228
+ "framework": "GitHub Copilot",
229
+ "language": "shell",
230
+ "category": "coding-agent",
231
+ "tags": [
232
+ "local",
233
+ "ide",
234
+ "agents"
235
+ ],
236
+ "protocol": "openai",
237
+ "homepage": "https://code.visualstudio.com/docs/copilot/overview",
238
+ "runbook": {
239
+ "mode": "setup",
240
+ "script": "copilot/install.sh",
241
+ "setupScript": "copilot/install.sh"
242
+ }
243
+ },
244
+ {
245
+ "id": "pi",
246
+ "command": "pi",
247
+ "name": "Pi",
133
248
  "aliases": [],
134
- "displayName": "Codex + Subconscious",
135
- "description": "Run the Codex CLI on your hosted Subconscious model via a custom OpenAI-compatible provider.",
136
- "framework": "Codex",
249
+ "description": "Launch Pi with the Subconscious provider and active profile model configured by subc setup.",
250
+ "framework": "Pi",
137
251
  "language": "shell",
138
252
  "category": "coding-agent",
139
253
  "tags": [
@@ -142,16 +256,12 @@
142
256
  "agents"
143
257
  ],
144
258
  "protocol": "openai",
145
- "homepage": "https://developers.openai.com/codex",
146
- "bin": "codex",
147
- "install": {
148
- "darwin": "npm i -g @openai/codex",
149
- "linux": "npm i -g @openai/codex",
150
- "win32": "npm i -g @openai/codex"
151
- },
152
- "launch": "codex -c model_providers.subconscious.name=Subconscious -c model_providers.subconscious.base_url={baseUrlV1} -c model_providers.subconscious.env_key=SUBCONSCIOUS_API_KEY -c model_provider=subconscious -c model={model}",
153
- "env": {
154
- "SUBCONSCIOUS_API_KEY": "{apiKey}"
259
+ "homepage": "https://pi.dev",
260
+ "bin": "pi",
261
+ "runbook": {
262
+ "mode": "launch",
263
+ "script": "pi/run.sh",
264
+ "setupScript": "pi/install.sh"
155
265
  }
156
266
  }
157
267
  ]
@@ -0,0 +1,25 @@
1
+ # ol-runbook coding-agent integrations
2
+
3
+ These runtime files are vendored from `ol-runbook/coding-agents` so the npm
4
+ package can run without a separate runbook checkout. The snapshot was synced
5
+ from `ol-runbook` commit `2236390` (latest `main` on 2026-08-13), with Claude
6
+ Code model-picker aliases and complete Codex, OpenCode, Pi, and Copilot model
7
+ catalogs added for the CLI's full Subconscious catalog. Namespaced
8
+ `subconscious/...` IDs are supported throughout. Codex app/plugin tools are
9
+ also disabled by default to honor the gateway's 128-tool request limit.
10
+
11
+ Included integrations:
12
+
13
+ - `claude-code/install.sh` and `run.sh`
14
+ - `codex/install.sh`, `run.sh`, `hook.sh`, and `hooks.json`
15
+ - `opencode/install.sh`, `run.sh`, and `subconscious-compaction.ts`
16
+ - `cursor/install.sh`, `hook.sh`, and `hooks.json`
17
+ - `copilot/install.sh`, `hook.sh`, and `hooks.json`
18
+ - `pi/install.sh`, `run.sh`, and `subconscious-compaction.ts`
19
+
20
+ When the upstream setup changes, update this snapshot and the corresponding
21
+ entries in `agents/registry.json` together.
22
+
23
+ At runtime `subc` reads `~/.subconscious/profiles/<name>.env` and injects those values
24
+ into these scripts, so users do not need to create a runbook checkout or source
25
+ an env file manually.
@@ -0,0 +1,316 @@
1
+ #!/usr/bin/env bash
2
+ # ── Subconscious API Gateway — Claude Code setup ──────────────────────────────
3
+ # Point Claude Code at your gateway. Claude reads env vars, so the "install"
4
+ # writes them to ~/.claude/subconscious-gateway.env and `use` launches claude.
5
+ #
6
+ # Quick start:
7
+ # ./install.sh --gateway-url https://your-gateway.example --api-key sk-gw-...
8
+ # ./install.sh use # launches claude with gateway env loaded
9
+ # ./install.sh use -- --continue # pass args through to claude
10
+ #
11
+ # Or source env into your shell:
12
+ # source <(./install.sh env) # load ANTHROPIC_BASE_URL etc.
13
+ # source <(./install.sh unset) # remove ANTHROPIC_BASE_URL etc.
14
+ #
15
+ # ./install.sh status # show current config
16
+ # ./install.sh uninstall # remove env file
17
+ #
18
+ # ── What this does under the hood ────────────────────────────────────────────
19
+ # Equivalent manual setup (no script needed):
20
+ #
21
+ # export ANTHROPIC_BASE_URL=https://your-gateway.example
22
+ # export ANTHROPIC_AUTH_TOKEN=sk-gw-...
23
+ # export ANTHROPIC_MODEL=subconscious/glm-5.2
24
+ # export ANTHROPIC_SMALL_FAST_MODEL=subconscious/glm-5.2
25
+ # export CLAUDE_CODE_SUBAGENT_MODEL=subconscious/glm-5.2
26
+ # export CLAUDE_CODE_MAX_CONCURRENT_SUBAGENTS=4
27
+ # export CLAUDE_CODE_MAX_SUBAGENT_SPAWN_DEPTH=1
28
+ # export CLAUDE_CODE_AUTO_COMPACT_WINDOW=1000000
29
+ # export CLAUDE_CODE_MAX_CONTEXT_TOKENS=3000000
30
+ # # AUTO_COMPACT_WINDOW range 100000–1000000 (leave on; TIMRUN keys rarely hit it):
31
+ # # https://code.claude.com/docs/en/env-vars
32
+ # # https://code.claude.com/docs/en/context-window#set-the-auto-compact-window
33
+ # export CLAUDE_CODE_ENABLE_TELEMETRY=1
34
+ # export CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1
35
+ # export OTEL_LOGS_EXPORTER=otlp
36
+ # export OTEL_EXPORTER_OTLP_PROTOCOL=http/json
37
+ # export OTEL_EXPORTER_OTLP_LOGS_ENDPOINT=https://your-gateway.example/v1/logs
38
+ # export OTEL_EXPORTER_OTLP_HEADERS="x-api-key=sk-gw-..."
39
+ # export OTEL_EXPORTER_OTLP_TIMEOUT=2000
40
+ # export OTEL_LOGS_EXPORT_INTERVAL=2000
41
+ # claude
42
+ #
43
+ # Claude Code sends native x-claude-code-session-id headers, so the gateway
44
+ # correlates requests automatically. OTEL api_request logs → Claude Code-only
45
+ # POST /v1/logs back-fill query_source (not a general logs API):
46
+ # https://code.claude.com/docs/en/monitoring-usage#api-request-event
47
+ # ─────────────────────────────────────────────────────────────────────────────
48
+
49
+ set -euo pipefail
50
+
51
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
52
+
53
+ # Load shared env from coding-agents/.env (gitignored) or env.example.
54
+ SHARED_ENV="${MBTA_ENV_FILE:-${SCRIPT_DIR}/../.env}"
55
+ [[ -f "$SHARED_ENV" ]] || SHARED_ENV="${SCRIPT_DIR}/../env.example"
56
+ if [[ -f "$SHARED_ENV" ]]; then set -a; source "$SHARED_ENV"; set +a; fi
57
+
58
+ CLAUDE_DIR="${HOME}/.claude"
59
+ ENV_FILE="${CLAUDE_DIR}/subconscious-gateway.env"
60
+ DEFAULT_MODEL="subconscious/glm-5.2"
61
+ DEFAULT_COMPACT_WINDOW="1000000"
62
+ DEFAULT_MAX_CONTEXT_TOKENS="3000000"
63
+ DEFAULT_MAX_CONCURRENT_SUBAGENTS="4"
64
+ DEFAULT_MAX_SUBAGENT_SPAWN_DEPTH="1"
65
+ DEFAULT_OPUS_MODEL="subconscious/glm-5.2"
66
+ DEFAULT_SONNET_MODEL="subconscious/tim-qwen3.6-27b"
67
+ DEFAULT_HAIKU_MODEL="subconscious/deepseek-v4-flash-marathon"
68
+
69
+ GATEWAY_URL="${GATEWAY_URL:-}"
70
+ API_KEY="${CLAUDE_CODE_API_KEY:-${API_KEY:-}}"
71
+ MODEL="${MODEL:-$DEFAULT_MODEL}"
72
+ COMPACT_WINDOW="${CLAUDE_CODE_AUTO_COMPACT_WINDOW:-${COMPACT_WINDOW:-$DEFAULT_COMPACT_WINDOW}}"
73
+ MAX_CONTEXT_TOKENS="${CLAUDE_CODE_MAX_CONTEXT_TOKENS:-${MAX_CONTEXT_TOKENS:-$DEFAULT_MAX_CONTEXT_TOKENS}}"
74
+ MAX_CONCURRENT_SUBAGENTS="${MAX_CONCURRENT_SUBAGENTS:-$DEFAULT_MAX_CONCURRENT_SUBAGENTS}"
75
+ MAX_SUBAGENT_SPAWN_DEPTH="${MAX_SUBAGENT_SPAWN_DEPTH:-$DEFAULT_MAX_SUBAGENT_SPAWN_DEPTH}"
76
+ OPUS_MODEL="${ANTHROPIC_DEFAULT_OPUS_MODEL:-$DEFAULT_OPUS_MODEL}"
77
+ OPUS_MODEL_NAME="${ANTHROPIC_DEFAULT_OPUS_MODEL_NAME:-$OPUS_MODEL}"
78
+ OPUS_MODEL_DESCRIPTION="${ANTHROPIC_DEFAULT_OPUS_MODEL_DESCRIPTION:-Subconscious default model}"
79
+ SONNET_MODEL="${ANTHROPIC_DEFAULT_SONNET_MODEL:-$DEFAULT_SONNET_MODEL}"
80
+ SONNET_MODEL_NAME="${ANTHROPIC_DEFAULT_SONNET_MODEL_NAME:-$SONNET_MODEL}"
81
+ SONNET_MODEL_DESCRIPTION="${ANTHROPIC_DEFAULT_SONNET_MODEL_DESCRIPTION:-Subconscious TIM Qwen 3.6 27B}"
82
+ HAIKU_MODEL="${ANTHROPIC_DEFAULT_HAIKU_MODEL:-$DEFAULT_HAIKU_MODEL}"
83
+ HAIKU_MODEL_NAME="${ANTHROPIC_DEFAULT_HAIKU_MODEL_NAME:-$HAIKU_MODEL}"
84
+ HAIKU_MODEL_DESCRIPTION="${ANTHROPIC_DEFAULT_HAIKU_MODEL_DESCRIPTION:-Subconscious DeepSeek V4 Flash Marathon}"
85
+ COMMAND="install"
86
+
87
+ usage() {
88
+ cat <<'EOF'
89
+ Usage:
90
+ install.sh [install] --gateway-url URL --api-key KEY [--model MODEL] [--compact-window N]
91
+ install.sh use [-- CLAUDE_ARGS...]
92
+ install.sh env
93
+ install.sh unset
94
+ install.sh uninstall
95
+ install.sh status
96
+
97
+ `install` is the default subcommand and may be omitted.
98
+
99
+ Commands:
100
+ install Write ~/.claude/subconscious-gateway.env with gateway settings
101
+ use Source the env file and exec claude (pass -- followed by claude args)
102
+ env Print export lines for sourcing: source <(./install.sh env)
103
+ unset Print unset lines for sourcing: source <(./install.sh unset)
104
+ uninstall Remove the env file
105
+ status Show current configuration
106
+
107
+ Options:
108
+ --gateway-url URL Gateway origin (e.g. https://gateway.example)
109
+ --api-key KEY Gateway API key (sk-gw-...)
110
+ --model MODEL Model name (default: subconscious/glm-5.2)
111
+ --compact-window N CLAUDE_CODE_AUTO_COMPACT_WINDOW (default: 1000000; Claude Code clamps to 100000–1000000)
112
+ See https://code.claude.com/docs/en/env-vars and
113
+ https://code.claude.com/docs/en/context-window#set-the-auto-compact-window
114
+ --max-context-tokens N CLAUDE_CODE_MAX_CONTEXT_TOKENS (default: 3000000)
115
+ See https://code.claude.com/docs/en/env-vars
116
+ EOF
117
+ }
118
+
119
+ while [[ $# -gt 0 ]]; do
120
+ case "$1" in
121
+ install|use|env|unset|uninstall|status)
122
+ COMMAND="$1"
123
+ shift
124
+ ;;
125
+ --gateway-url)
126
+ GATEWAY_URL="${2:-}"
127
+ shift 2
128
+ ;;
129
+ --api-key)
130
+ API_KEY="${2:-}"
131
+ shift 2
132
+ ;;
133
+ --model)
134
+ MODEL="${2:-}"
135
+ shift 2
136
+ ;;
137
+ --compact-window)
138
+ COMPACT_WINDOW="${2:-}"
139
+ shift 2
140
+ ;;
141
+ --max-context-tokens)
142
+ MAX_CONTEXT_TOKENS="${2:-}"
143
+ shift 2
144
+ ;;
145
+ -h|--help)
146
+ usage
147
+ exit 0
148
+ ;;
149
+ --)
150
+ shift
151
+ break
152
+ ;;
153
+ *)
154
+ echo "unknown argument: $1" >&2
155
+ usage >&2
156
+ exit 1
157
+ ;;
158
+ esac
159
+ done
160
+
161
+ # Optional CLAUDE_GATEWAY_URL in shared .env overrides GATEWAY_URL for Claude only.
162
+ resolve_claude_gateway_url() {
163
+ printf '%s' "${CLAUDE_GATEWAY_URL:-$GATEWAY_URL}"
164
+ }
165
+
166
+ write_env() {
167
+ local effective_gateway_url
168
+ effective_gateway_url="$(resolve_claude_gateway_url)"
169
+ mkdir -p "$CLAUDE_DIR"
170
+ umask 077
171
+ cat >"$ENV_FILE" <<EOF
172
+ # Generated by ol-runbook/coding-agents/claude-code/install.sh — do not commit secrets.
173
+ export ANTHROPIC_BASE_URL="${effective_gateway_url}"
174
+ export ANTHROPIC_AUTH_TOKEN="${API_KEY}"
175
+ export ANTHROPIC_MODEL="${MODEL}"
176
+ export ANTHROPIC_SMALL_FAST_MODEL="${MODEL}"
177
+ export ANTHROPIC_DEFAULT_OPUS_MODEL="${OPUS_MODEL}"
178
+ export ANTHROPIC_DEFAULT_OPUS_MODEL_NAME="${OPUS_MODEL_NAME}"
179
+ export ANTHROPIC_DEFAULT_OPUS_MODEL_DESCRIPTION="${OPUS_MODEL_DESCRIPTION}"
180
+ export ANTHROPIC_DEFAULT_SONNET_MODEL="${SONNET_MODEL}"
181
+ export ANTHROPIC_DEFAULT_SONNET_MODEL_NAME="${SONNET_MODEL_NAME}"
182
+ export ANTHROPIC_DEFAULT_SONNET_MODEL_DESCRIPTION="${SONNET_MODEL_DESCRIPTION}"
183
+ export ANTHROPIC_DEFAULT_HAIKU_MODEL="${HAIKU_MODEL}"
184
+ export ANTHROPIC_DEFAULT_HAIKU_MODEL_NAME="${HAIKU_MODEL_NAME}"
185
+ export ANTHROPIC_DEFAULT_HAIKU_MODEL_DESCRIPTION="${HAIKU_MODEL_DESCRIPTION}"
186
+ export CLAUDE_CODE_SUBAGENT_MODEL="${MODEL}"
187
+ export CLAUDE_CODE_MAX_CONCURRENT_SUBAGENTS="${MAX_CONCURRENT_SUBAGENTS}"
188
+ export CLAUDE_CODE_MAX_SUBAGENT_SPAWN_DEPTH="${MAX_SUBAGENT_SPAWN_DEPTH}"
189
+ export CLAUDE_CODE_AUTO_COMPACT_WINDOW="${COMPACT_WINDOW}"
190
+ export CLAUDE_CODE_MAX_CONTEXT_TOKENS="${MAX_CONTEXT_TOKENS}"
191
+ export CLAUDE_CODE_ENABLE_TELEMETRY=1
192
+ export CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1
193
+ # Claude Code purpose attribution only (api_request → /v1/logs):
194
+ # https://code.claude.com/docs/en/monitoring-usage#api-request-event
195
+ export OTEL_LOGS_EXPORTER=otlp
196
+ export OTEL_EXPORTER_OTLP_PROTOCOL=http/json
197
+ export OTEL_EXPORTER_OTLP_LOGS_ENDPOINT="${effective_gateway_url%/}/v1/logs"
198
+ export OTEL_EXPORTER_OTLP_HEADERS="x-api-key=${API_KEY}"
199
+ export OTEL_EXPORTER_OTLP_TIMEOUT=2000
200
+ export OTEL_LOGS_EXPORT_INTERVAL=2000
201
+ EOF
202
+ chmod 600 "$ENV_FILE"
203
+ }
204
+
205
+ print_env_exports() {
206
+ if [[ ! -f "$ENV_FILE" ]]; then
207
+ echo "env file not found: $ENV_FILE" >&2
208
+ echo "run: ./install.sh --gateway-url URL --api-key KEY" >&2
209
+ return 1
210
+ fi
211
+ cat "$ENV_FILE"
212
+ }
213
+
214
+ print_env_unsets() {
215
+ cat <<'EOF'
216
+ unset ANTHROPIC_BASE_URL
217
+ unset ANTHROPIC_AUTH_TOKEN
218
+ unset ANTHROPIC_MODEL
219
+ unset ANTHROPIC_SMALL_FAST_MODEL
220
+ unset ANTHROPIC_DEFAULT_OPUS_MODEL
221
+ unset ANTHROPIC_DEFAULT_OPUS_MODEL_NAME
222
+ unset ANTHROPIC_DEFAULT_OPUS_MODEL_DESCRIPTION
223
+ unset ANTHROPIC_DEFAULT_SONNET_MODEL
224
+ unset ANTHROPIC_DEFAULT_SONNET_MODEL_NAME
225
+ unset ANTHROPIC_DEFAULT_SONNET_MODEL_DESCRIPTION
226
+ unset ANTHROPIC_DEFAULT_HAIKU_MODEL
227
+ unset ANTHROPIC_DEFAULT_HAIKU_MODEL_NAME
228
+ unset ANTHROPIC_DEFAULT_HAIKU_MODEL_DESCRIPTION
229
+ unset CLAUDE_CODE_SUBAGENT_MODEL
230
+ unset CLAUDE_CODE_MAX_CONCURRENT_SUBAGENTS
231
+ unset CLAUDE_CODE_MAX_SUBAGENT_SPAWN_DEPTH
232
+ unset CLAUDE_CODE_AUTO_COMPACT_WINDOW
233
+ unset CLAUDE_CODE_MAX_CONTEXT_TOKENS
234
+ unset CLAUDE_CODE_ENABLE_TELEMETRY
235
+ unset CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC
236
+ unset OTEL_LOGS_EXPORTER
237
+ unset OTEL_EXPORTER_OTLP_PROTOCOL
238
+ unset OTEL_EXPORTER_OTLP_LOGS_ENDPOINT
239
+ unset OTEL_EXPORTER_OTLP_HEADERS
240
+ unset OTEL_EXPORTER_OTLP_TIMEOUT
241
+ unset OTEL_LOGS_EXPORT_INTERVAL
242
+ EOF
243
+ }
244
+
245
+ status() {
246
+ echo "scope: user"
247
+ echo "claude dir: $CLAUDE_DIR"
248
+ echo "env file: $ENV_FILE"
249
+ if [[ -f "$ENV_FILE" ]]; then
250
+ # shellcheck disable=SC1090
251
+ source "$ENV_FILE"
252
+ echo "gateway: ${ANTHROPIC_BASE_URL:-unset}"
253
+ if [[ -n "${ANTHROPIC_AUTH_TOKEN:-}" ]]; then
254
+ echo "api key: set (${#ANTHROPIC_AUTH_TOKEN} chars)"
255
+ else
256
+ echo "api key: unset"
257
+ fi
258
+ echo "model: ${ANTHROPIC_MODEL:-unset}"
259
+ echo "model picker: ${ANTHROPIC_DEFAULT_OPUS_MODEL_NAME:-unset}, ${ANTHROPIC_DEFAULT_SONNET_MODEL_NAME:-unset}, ${ANTHROPIC_DEFAULT_HAIKU_MODEL_NAME:-unset}"
260
+ echo "max concurrent subagents: ${CLAUDE_CODE_MAX_CONCURRENT_SUBAGENTS:-unset}"
261
+ echo "max subagent spawn depth: ${CLAUDE_CODE_MAX_SUBAGENT_SPAWN_DEPTH:-unset}"
262
+ echo "compact window: ${CLAUDE_CODE_AUTO_COMPACT_WINDOW:-unset}"
263
+ echo "max context tokens: ${CLAUDE_CODE_MAX_CONTEXT_TOKENS:-unset}"
264
+ else
265
+ echo "env file: missing"
266
+ echo "run: ./install.sh --gateway-url URL --api-key KEY"
267
+ fi
268
+ }
269
+
270
+ case "$COMMAND" in
271
+ install)
272
+ if [[ -z "$GATEWAY_URL" || -z "$API_KEY" ]]; then
273
+ echo "--gateway-url and --api-key are required for install" >&2
274
+ exit 1
275
+ fi
276
+ write_env
277
+ echo "Wrote $ENV_FILE"
278
+ echo " gateway: $GATEWAY_URL"
279
+ echo " model: $MODEL"
280
+ echo ""
281
+ echo "Launch claude:"
282
+ echo " ./install.sh use"
283
+ echo " ./install.sh use -- --continue"
284
+ echo ""
285
+ echo "Or source env into your current shell:"
286
+ echo " source <(./install.sh env)"
287
+ ;;
288
+ use)
289
+ if [[ ! -f "$ENV_FILE" ]]; then
290
+ echo "env file not found: $ENV_FILE" >&2
291
+ echo "run: ./install.sh --gateway-url URL --api-key KEY" >&2
292
+ exit 1
293
+ fi
294
+ # shellcheck disable=SC1090
295
+ source "$ENV_FILE"
296
+ if ! command -v claude >/dev/null 2>&1; then
297
+ echo "claude CLI not found in PATH" >&2
298
+ exit 1
299
+ fi
300
+ exec claude "$@"
301
+ ;;
302
+ env)
303
+ print_env_exports
304
+ ;;
305
+ unset)
306
+ print_env_unsets
307
+ ;;
308
+ uninstall)
309
+ rm -f "$ENV_FILE"
310
+ echo "Removed $ENV_FILE"
311
+ echo "To unset env in your current shell: source <(./install.sh unset)"
312
+ ;;
313
+ status)
314
+ status
315
+ ;;
316
+ esac