MCPcopy
hub / github.com/codeaashu/claude-code / getClaudeCodeSnapshotContent

Function getClaudeCodeSnapshotContent

src/utils/bash/ShellSnapshot.ts:269–340  ·  view source on GitHub ↗

* Generates Claude Code specific snapshot content * This content is always included regardless of user configuration

()

Source from the content-addressed store, hash-verified

267 * This content is always included regardless of user configuration
268 */
269async function getClaudeCodeSnapshotContent(): Promise<string> {
270 // Get the appropriate PATH based on platform
271 let pathValue = process.env.PATH
272 if (getPlatform() === 'windows') {
273 // On Windows with git-bash, read the Cygwin PATH
274 const cygwinResult = await execa('echo $PATH', {
275 shell: true,
276 reject: false,
277 })
278 if (cygwinResult.exitCode === 0 && cygwinResult.stdout) {
279 pathValue = cygwinResult.stdout.trim()
280 }
281 // Fall back to process.env.PATH if we can't get Cygwin PATH
282 }
283
284 const rgIntegration = createRipgrepShellIntegration()
285
286 let content = ''
287
288 // Check if rg is available, if not create an alias/function to bundled ripgrep
289 // We use a subshell to unalias rg before checking, so that user aliases like
290 // `alias rg='rg --smart-case'` don't shadow the real binary check. The subshell
291 // ensures we don't modify the user's aliases in the parent shell.
292 content += `
293 # Check for rg availability
294 echo "# Check for rg availability" >> "$SNAPSHOT_FILE"
295 echo "if ! (unalias rg 2>/dev/null; command -v rg) >/dev/null 2>&1; then" >> "$SNAPSHOT_FILE"
296 `
297
298 if (rgIntegration.type === 'function') {
299 // For embedded ripgrep, write the function definition using heredoc
300 content += `
301 cat >> "$SNAPSHOT_FILE" << 'RIPGREP_FUNC_END'
302 ${rgIntegration.snippet}
303RIPGREP_FUNC_END
304 `
305 } else {
306 // For regular ripgrep, write a simple alias
307 const escapedSnippet = rgIntegration.snippet.replace(/'/g, "'\\''")
308 content += `
309 echo ' alias rg='"'${escapedSnippet}'" >> "$SNAPSHOT_FILE"
310 `
311 }
312
313 content += `
314 echo "fi" >> "$SNAPSHOT_FILE"
315 `
316
317 // For ant-native builds, shadow find/grep with bfs/ugrep embedded in the bun
318 // binary. Unlike rg (which only activates if system rg is absent), we always
319 // shadow find/grep since bfs/ugrep are drop-in replacements and we want
320 // consistent fast behavior in Claude's shell.
321 const findGrepIntegration = createFindGrepShellIntegration()
322 if (findGrepIntegration !== null) {
323 content += `
324 # Shadow find/grep with embedded bfs/ugrep (ant-native only)
325 echo "# Shadow find/grep with embedded bfs/ugrep" >> "$SNAPSHOT_FILE"
326 cat >> "$SNAPSHOT_FILE" << 'FIND_GREP_FUNC_END'

Callers 1

getSnapshotScriptFunction · 0.85

Calls 4

getPlatformFunction · 0.85
quoteFunction · 0.85

Tested by

no test coverage detected