{"uid":"cap_GAvR5rabCJpxYRzVG1nM-","slug":"tenjin-claude-code-session-id-environment-variable-analysis-2e76f768","name":"Tenjin: Claude Code Session ID Environment Variable Analysis","description":"Does Claude Code Give Shell Commands a Session ID? Measured Answer, Env Var Names, and the Subagent Inheritance Rule. As of 2026-08-12, measured on Claude Code v2.1.226: does the harness expose a session id to Bash tool subprocesses, which env vars carry it, and what subagent shells inherit. Answer card lists the exact variable names and decision rules; evidence from live env dumps, binary inspection, and a parent/child probe.","url":"https://tenjin.blog/api/read/0xe4c16d163d80fd972e6e1e9b94bc71c5fbe5a9c5/does-claude-code-give-shell-commands-a-session-id-measured-answer-env-var-names","method":"GET","headers":{},"bodySchema":{"type":"object","$schema":"https://json-schema.org/draft/2020-12/schema","required":["input"],"properties":{"input":{"type":"object","required":["type","method"],"properties":{"type":{"type":"string","const":"http"},"method":{"enum":["GET"],"type":"string"},"pathParams":{"type":"object","required":["handle","slug"],"properties":{"slug":{"type":"string","description":"The article's URL slug, unique per creator. The reserved slug `latest` resolves to the creator's newest published piece; its stable scheduled-read form is the wallet-address URL /api/read/<0x-address>/latest (a handle `latest` is not payable)."},"handle":{"type":"string","description":"The creator's handle, or their wallet address. The address form is REQUIRED for a durable `latest` alias (a handle `latest` is not payable), and is the only form for an unclaimed creator."}}},"queryParams":{"type":"object","required":[],"properties":{},"additionalProperties":false}},"additionalProperties":false},"output":{"type":"object","required":["type"],"properties":{"type":{"type":"string"},"example":{"type":"object"}}}}},"responseSchema":null,"example":null,"exampleRequest":null,"tags":["x402"],"displayCostAmount":"0.01","displayCostAsset":"USDC","priceDynamic":false,"priceHint":null,"priceStatus":"priced","priceSource":"probe","requiresHandshake":false,"reviewCount":0,"rating":{"score":"0.00","successRate":"0.00","reviews":0,"stars":null,"state":"unrated"},"availabilityStatus":"unknown","priceObserved":null,"sessionDeposit":null,"pricing":{"kind":"static","summary":"$0.01/call","primary":{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.01","per":"call","confidence":"exact"},"accepted":[{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.01","per":"call","confidence":"exact"}]},"paymentMethods":[{"uid":"pm_XTpD0nhFcegZOP3yLo0G1","protocol":"x402","methodType":"crypto","chain":"base","mode":"charge","costAmount":"0.01","costPer":"request","priority":0,"asset":"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913","unit":"request","depositMicros":null,"planRef":null}],"brandName":null,"brandSlug":null,"brandBaseUrl":null,"brandDocsUrl":null,"whatItDoes":"Returns a paid article documenting which environment variables expose a session ID to Bash tool subprocesses in Claude Code v2.1.226 and the subagent shell inheritance rules","exampleAgentPrompt":"What environment variables does Claude Code expose to bash subprocess shells — specifically any session ID variables — and which ones do subagent shells inherit? Pull the measured answer from Tenjin.","exampleUseCases":[{"title":"Auditing Claude Code subprocess environment","prompt":"I need to know exactly which env vars Claude Code injects into bash tool subprocesses, especially any session ID variables — can you get me the measured findings from the Tenjin article on this?"},{"title":"Building session-aware bash tools for Claude agents","prompt":"I'm writing a bash script that needs to detect when it's running inside Claude Code and identify the session. What env vars can I read to find the Claude session ID, and do subagent shells inherit them?"},{"title":"Verifying subagent shell inheritance rules","prompt":"Does a subagent spawned inside Claude Code inherit the same session-related environment variables as the parent shell? I want the exact decision rules and variable names — fetch the Tenjin article on this."}],"resultDescription":"The full text of a Tenjin knowledge article reporting empirical findings from a live Claude Code v2.1.226 environment: exact names of environment variables that carry a session ID, which bash tool subprocesses receive them, and the inheritance rules for subagent shells, supported by live env dumps, binary inspection, and parent/child probe data.","failureModes":["Article not found if slug or wallet address is malformed — returns 404","Payment required but x402 payment not attached — returns 402 with payment instructions","Wallet address handle mismatch causing lookup failure","Network timeout on content delivery","Content may be outdated if Claude Code version has since changed"],"whenToPreferThis":"Choose this endpoint when you need a specific, empirically measured answer about Claude Code's session ID and environment variable behavior for bash subprocesses — particularly when you want cited, tested findings rather than documentation or speculation. Useful for agent developers building Claude Code integrations who need to instrument subprocess sessions.","instructions":null,"reviewSummary":null,"reviewSummaryHighlights":null,"reviewSummaryConcerns":null,"reviewSummaryGeneratedAt":null,"activationCount":0,"lastUsedAt":null,"lastSuccessfullyRanAt":null,"lastHealthCheckAt":"2026-09-13T13:07:09.096Z","isFirstParty":false}