Skip to content

Commit dae5662

Browse files
committed
Shell: Disable history and improve agent detection
Expand is_ai_agent() to detect Claude Code, Codex, and the emerging AGENT env var convention (Goose, Amp). Disable shell history and hishtory in agent shells to prevent pollution from auto-generated commands. Also clean up zsh starship config to always use the full prompt, with a sentinel to clear bash's ASCII override when launching zsh from bash.
1 parent a345965 commit dae5662

File tree

6 files changed

+59
-41
lines changed

6 files changed

+59
-41
lines changed

home/dot_config/zsh/exact_private_zsh.d/private_010_functions_ai.zsh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ function is_cursor_agent() {
55

66
# @tags: canbescript
77
function is_ai_agent() {
8-
is_cursor_agent
8+
is_cursor_agent \
9+
|| [[ -n ${CLAUDECODE:-} ]] \
10+
|| [[ -n ${CODEX_THREAD_ID:-} ]] \
11+
|| [[ -n ${AGENT:-} ]]
912
}
1013

1114
# @tags: command

home/dot_config/zsh/exact_private_zsh.d/private_050_misc_config.zsh

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -167,29 +167,16 @@ export LESS_TERMCAP_us=$'\E[04;38;5;146m' # begin underline
167167

168168
if has_command starship
169169
then
170-
# Use ASCII-safe prompt config for terminals with Unicode rendering issues
171-
# See: https://github.com/starship/starship/issues/6923
172-
if [[ "$TERM_PROGRAM" == "ghostty" ]]; then
173-
export STARSHIP_CONFIG="$HOME/.config/starship-ascii-prompt.toml"
170+
# When zsh is launched from within bash (e.g. during a shell migration),
171+
# it inherits STARSHIP_CONFIG which bash may have set to an ASCII-only
172+
# prompt for terminals with Unicode issues (see starship/starship#6923).
173+
# This is a bash-specific workaround that doesn't apply to zsh, so we
174+
# detect it via a sentinel variable and clear it to use the default config.
175+
if [[ -n "$_STARSHIP_CONFIG_SET_BY_BASH" && "$STARSHIP_CONFIG" == "$_STARSHIP_CONFIG_SET_BY_BASH" ]]; then
176+
unset STARSHIP_CONFIG
177+
unset _STARSHIP_CONFIG_SET_BY_BASH
174178
fi
175179
eval -- "$(starship init zsh)"
176-
# For ASCII prompt: capture and format exit status for starship custom modules
177-
# Must be set up AFTER starship init (which sets its own precmd hooks)
178-
if [[ "$TERM_PROGRAM" == "ghostty" ]]; then
179-
__starship_exit_status_hook() {
180-
local exit_status=$?
181-
if [[ $exit_status -eq 0 ]]; then
182-
export __STARSHIP_EXIT_OK=1
183-
export __STARSHIP_EXIT_FMT=""
184-
else
185-
export __STARSHIP_EXIT_OK=""
186-
export __STARSHIP_EXIT_FMT=$(printf "[%3d]" "$exit_status")
187-
fi
188-
return $exit_status
189-
}
190-
# Use ZSH's native precmd hook array
191-
precmd_functions=(__starship_exit_status_hook $precmd_functions)
192-
fi
193180
else
194181
echo "No starship, this is the path: $PATH"
195182
fi
@@ -201,31 +188,39 @@ fi
201188
# Section: History {{{
202189
#############################################################################
203190

204-
# ZSH history configuration
205-
HISTFILE=${HISTFILE:-$HOME/.zsh_history}
206-
HISTSIZE=5000
207-
SAVEHIST=20000
191+
# Disable history recording in AI agent shells to avoid polluting history
192+
# with massive auto-generated commands from coding agents.
193+
if is_ai_agent; then
194+
HISTFILE=/dev/null
195+
HISTSIZE=0
196+
SAVEHIST=0
197+
else
198+
# ZSH history configuration
199+
HISTFILE=${HISTFILE:-$HOME/.zsh_history}
200+
HISTSIZE=5000
201+
SAVEHIST=20000
208202

209-
# Append history instead of overwriting
210-
setopt APPEND_HISTORY
203+
# Append history instead of overwriting
204+
setopt APPEND_HISTORY
211205

212-
# Share history between all sessions
213-
setopt SHARE_HISTORY
206+
# Share history between all sessions
207+
setopt SHARE_HISTORY
214208

215-
# Don't record commands starting with a space
216-
setopt HIST_IGNORE_SPACE
209+
# Don't record commands starting with a space
210+
setopt HIST_IGNORE_SPACE
217211

218-
# Remove duplicates from history when it fills up
219-
setopt HIST_EXPIRE_DUPS_FIRST
212+
# Remove duplicates from history when it fills up
213+
setopt HIST_EXPIRE_DUPS_FIRST
220214

221-
# Don't record duplicate consecutive commands
222-
setopt HIST_IGNORE_DUPS
215+
# Don't record duplicate consecutive commands
216+
setopt HIST_IGNORE_DUPS
223217

224-
# Add timestamps to history
225-
setopt EXTENDED_HISTORY
218+
# Add timestamps to history
219+
setopt EXTENDED_HISTORY
226220

227-
# Write to history immediately, not when shell exits
228-
setopt INC_APPEND_HISTORY
221+
# Write to history immediately, not when shell exits
222+
setopt INC_APPEND_HISTORY
223+
fi
229224

230225
#############################################################################
231226

home/dot_config/zsh/exact_private_zsh.d/private_190_tool_hishtory.zsh.tmpl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
# Initialize hishtory - better shell history
44
# https://github.com/ddworken/hishtory
55

6+
# Skip in AI agent shells to avoid recording auto-generated commands
7+
is_ai_agent && return
8+
69
export HISHTORY_SERVER={{ .hishtory_server | quote }}
710

811
[[ -f ~/.hishtory/config.zsh ]] && source ~/.hishtory/config.zsh

home/exact_private_dot_bash.d/private_010_functions_ai.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ function is_cursor_agent() {
55

66
# @tags: canbescript
77
function is_ai_agent() {
8-
is_cursor_agent
8+
is_cursor_agent \
9+
|| [[ -n ${CLAUDECODE:-} ]] \
10+
|| [[ -n ${CODEX_THREAD_ID:-} ]] \
11+
|| [[ -n ${AGENT:-} ]]
912
}
1013

1114
# @tags: command

home/exact_private_dot_bash.d/private_050_misc_config.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ then
171171
# See: https://github.com/starship/starship/issues/6923
172172
if [[ "$TERM_PROGRAM" == "ghostty" ]]; then
173173
export STARSHIP_CONFIG="$HOME/.config/starship-ascii-prompt.toml"
174+
# Sentinel: lets child shells (e.g. zsh launched from bash) detect that
175+
# STARSHIP_CONFIG was set by bash and clear it to use their own default.
176+
export _STARSHIP_CONFIG_SET_BY_BASH="$STARSHIP_CONFIG"
174177
fi
175178
eval -- "$(starship init bash --print-full-init)"
176179
# For ASCII prompt: capture and format exit status for starship custom modules
@@ -200,6 +203,14 @@ fi
200203
# Section: History {{{
201204
#############################################################################
202205

206+
# Disable history recording in AI agent shells to avoid polluting history
207+
# with massive auto-generated commands from coding agents.
208+
if is_ai_agent; then
209+
unset HISTFILE
210+
HISTSIZE=0
211+
HISTFILESIZE=0
212+
fi
213+
203214
# HISTCONTROL {{{
204215
# ===========
205216
# A colon-separated list of values controlling how commands are saved on the

home/exact_private_dot_bash.d/private_190_tool_hishtory.sh.tmpl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
# Initialize hishtory - better shell history
44
# https://github.com/ddworken/hishtory
55

6+
# Skip in AI agent shells to avoid recording auto-generated commands
7+
is_ai_agent && return
8+
69
export HISHTORY_SERVER={{ .hishtory_server | quote }}
710

811
[[ -f ~/.hishtory/config.sh ]] && source ~/.hishtory/config.sh

0 commit comments

Comments
 (0)