Skip to content

Commit 0fe1911

Browse files
committed
fix(claude): the hub never passes on the label of the run that started it, and only $1 marks a background session again
1 parent 98f208d commit 0fe1911

3 files changed

Lines changed: 6 additions & 6 deletions

File tree

‎bin/session‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ here=$(pwd -P)
99
# A session started in the background has nobody to accept Claude Code's trust prompt, so hex trusts the folder it starts in.
1010
# Claude Code rewrites this file as it runs, holding the lock directory next to it, so hex takes that lock too, and checks the write until it holds; the copy keeps the file's mode.
1111
config=$(readlink -f "${CLAUDE_CONFIG_DIR:-$HOME}/.claude.json")
12-
bg=
13-
for arg; do case $arg in --) break ;; --bg) bg=--bg; break ;; esac; done
12+
bg=${1:-}
1413
untrusted() { [ "$bg" = --bg ] && ! above && [ -s "$config" ] && ! jq -e --arg here "$here" '.projects[$here].hasTrustDialogAccepted' "$config" >/dev/null 2>&1; }
1514
for try in 1 2 3 4 5; do
1615
untrusted || break
@@ -69,5 +68,5 @@ fi
6968
[ -z "${CLAUDE_SECURESTORAGE_CONFIG_DIR+set}" ] && store=$(tokenmaxxing seat $$ 2>/dev/null) && export CLAUDE_SECURESTORAGE_CONFIG_DIR="$store"
7069
export CLAUDE_CODE_ADDITIONAL_DIRECTORIES_CLAUDE_MD=1
7170
# Anthropic's 5-hour limit charges a run with no terminal, which Claude Code labels sdk-cli, more per token than an interactive one (anthropics/claude-code#97074), and Claude Code reads its label only from the environment, where a labeled parent leaves its own.
72-
if [ -z "$bg" ] && [ ! -t 1 ]; then export CLAUDE_CODE_ENTRYPOINT=hex; else unset CLAUDE_CODE_ENTRYPOINT; fi
71+
if [ "$bg" != --bg ] && [ ! -t 1 ]; then export CLAUDE_CODE_ENTRYPOINT=hex; else unset CLAUDE_CODE_ENTRYPOINT; fi
7372
exec claude --plugin-dir "$hex/plugin" "$@"

‎hub/claude.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ export type Usage = { sent: number; at?: number; short?: boolean }
1313
const home = () => process.env.CLAUDE_CONFIG_DIR ?? join(homedir(), '.claude')
1414
const short = (session: string) => session.slice(0, 8)
1515

16-
// What a Claude process the hub starts never inherits from it: the bots' tokens and hex's own settings.
17-
const PRIVATE = /_BOT_TOKEN$|^HEX_|^BUZZ_/
16+
// What a Claude process the hub starts never inherits from it: the bots' tokens, hex's own settings, and the
17+
// label of whatever run started the hub, which Claude Code would report for every session its daemon starts.
18+
const PRIVATE = /_BOT_TOKEN$|^HEX_|^BUZZ_|^CLAUDE_CODE_ENTRYPOINT$/
1819

1920
export function inherited(): Record<string, string | undefined> {
2021
return Object.fromEntries(Object.entries(process.env).filter(([name]) => !PRIVATE.test(name)))

‎plugin/tests/session.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,5 +163,5 @@ test('a run with no terminal says it is hex, over the label it inherited, and a
163163
expect(launched('build it')).toBe('hex')
164164
expect(launched('-p', '--', '--bg')).toBe('hex')
165165
expect(launched('--bg', 'build it')).toBe('unset')
166-
expect(launched('-n', 'x/deck', '--bg', '-p')).toBe('unset')
166+
expect(launched('--bg', '-p')).toBe('unset')
167167
})

0 commit comments

Comments
 (0)