diff --git a/scripts/claude-profile b/scripts/claude-profile index 12c954f..120a6f5 100755 --- a/scripts/claude-profile +++ b/scripts/claude-profile @@ -378,6 +378,11 @@ combined_context="${context} ${body}" +ctx_kb=$(( ${#combined_context} / 1024 )) +if (( ${#combined_context} > 150000 )); then + echo "Warning: context is ${ctx_kb}KB — large projects may benefit from trimming CONTEXT.md or MEMORY.md" >&2 +fi + if (( DRYRUN )); then dryrun_log "Profile: $PROFILE ($target)" dryrun_log "Mode: $MODE" @@ -396,11 +401,11 @@ if (( DRYRUN )); then dryrun_log "Would write: $target/active-mode.env" dryrun_log "Would write: $target/last-mode" if (( ${#CLAUDE_ARGS[@]} > 0 )); then - dryrun_log "Would execute: claude --model $MODEL_ID --append-system-prompt ${CLAUDE_ARGS[*]}" + dryrun_log "Would execute: claude --model $MODEL_ID --append-system-prompt-file ${CLAUDE_ARGS[*]}" else - dryrun_log "Would execute: claude --model $MODEL_ID --append-system-prompt " + dryrun_log "Would execute: claude --model $MODEL_ID --append-system-prompt-file " fi - dryrun_log "Context length: ${#combined_context} chars (${#context} from context-load + ${#body} from mode body)" + dryrun_log "Context length: ${#combined_context} chars (~${ctx_kb}KB; ${#context} from context-load + ${#body} from mode body)" dryrun_log "No changes made." exit 0 fi @@ -433,5 +438,13 @@ done printf '%s\n' "$active_env" > "$target/active-mode.env" printf '%s\n' "$MODE" > "$target/last-mode" -echo "Launching: $PROFILE / $MODE${PROJECT:+ / $PROJECT}" -exec claude --model "$MODEL_ID" --append-system-prompt "$combined_context" "${CLAUDE_ARGS[@]}" +# Write context to a temp file — passing it inline as an argument hits ARG_MAX +# on large projects (context-load output can exceed 2 MB). +# Dropping exec (→ subprocess) means the EXIT trap fires after claude exits, +# which properly resets the WezTerm theme and cleans up the temp file. +context_file=$(mktemp /tmp/claude-profile-ctx-XXXXXX.md) +printf '%s\n' "$combined_context" > "$context_file" +trap 'rm -f "${context_file:-}"; reset_wezterm_profile' EXIT + +echo "Launching: $PROFILE / $MODE${PROJECT:+ / $PROJECT} (context: ${ctx_kb}KB)" +claude --model "$MODEL_ID" --append-system-prompt-file "$context_file" "${CLAUDE_ARGS[@]}"