claude-code - 💡(How to fix) Fix [DOCS] Bash tool docs omit how shell snapshots preserve aliases and user functions

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
RAW_BUFFERClick to expand / collapse

Documentation Type

Missing documentation (feature not documented)

Documentation Location

https://code.claude.com/docs/en/tools-reference

Section/Topic

Bash tool behavior

Current Documentation

The Bash tool docs currently say:

The Bash tool runs each command in a separate process with the following persistence behavior:

  • When Claude runs cd in the main session, the new working directory carries over to later Bash commands as long as it stays inside the project directory or an additional working directory you added with --add-dir, /add-dir, or additionalDirectories in settings.
  • Environment variables do not persist. An export in one command will not be available in the next.

Activate your virtualenv or conda environment before launching Claude Code. To make environment variables persist across Bash commands, set CLAUDE_ENV_FILE to a shell script before launching Claude Code, or use a SessionStart hook to populate it dynamically.

The Claude directory docs also say:

shell-snapshots/ | Captured shell environment used by the Bash tool. Removed on clean exit. The sweep clears any left after a crash.

What's Wrong or Missing?

Changelog v2.1.147 says:

Fixed shell snapshot dropping user functions whose names start with a single underscore, which broke aliases referencing them

The current docs mention shell snapshots and Bash persistence rules, but they never explain that the Bash tool's startup shell snapshot is expected to preserve user-defined shell functions and aliases loaded at startup.

That leaves an important gap:

A. The supported behavior is undocumented

Users cannot tell from tools-reference whether aliases and helper functions from their shell startup files are supposed to be available in Bash tool commands, or whether that behavior is incidental.

B. The troubleshooting model is incomplete

The docs explain cd carry-over, non-persistent export, and CLAUDE_ENV_FILE, but they do not explain how those rules relate to aliases or shell functions captured in the shell snapshot. When an alias depends on a helper function, users have no doc-backed way to reason about whether that should work.

Suggested Improvement

Add a short paragraph to Bash tool behavior that explains:

  • Claude Code captures a startup shell snapshot for Bash tool commands.
  • That snapshot includes shell definitions loaded at startup, including aliases and user-defined shell functions.
  • Aliases that call helper functions are expected to work when those functions are present in the startup shell.
  • Changes made inside one Bash command still do not persist to the next command, so per-session or per-directory updates should use CLAUDE_ENV_FILE or hooks.

Also expand the shell-snapshots/ entry in claude-directory so "captured shell environment" is concrete instead of generic.

Impact

Medium - Makes feature difficult to understand

Additional Context

Affected Pages:

PageLine(s)Context
https://code.claude.com/docs/en/tools-reference108-115Describes Bash persistence rules, but not what shell snapshots preserve
https://code.claude.com/docs/en/claude-directory1508Mentions shell-snapshots/ without defining whether aliases/functions are included
https://code.claude.com/docs/en/env-vars265Explains CLAUDE_ENV_FILE for persistent exports, but not how it relates to startup aliases/functions
https://code.claude.com/docs/en/hooks-guide330-333Explains reloading env changes via hooks, but not the baseline shell snapshot behavior

Total scope: 4 pages affected

Relevant release: v2.1.147

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix [DOCS] Bash tool docs omit how shell snapshots preserve aliases and user functions