Summary
From versions 3.5.0 to before 3.5.2, claude-code-cache-fix's tools/quota-statusline.sh script interpolates Claude Code's hook stdin payload directly into a Python triple-quoted string without escaping.
If any user-controlled field in the payload contains a ''' sequence, the Python string literal is prematurely closed and subsequent bytes are executed as Python code in the user's Claude Code process, enabling local code execution in that context.
Affected context
This issue arises in environments where:
claude-code-cache-fixversions 3.5.0 to before 3.5.2 are installed.- The
tools/quota-statusline.shhelper is used as part of the Claude Code hook workflow. - The hook consumes stdin payloads that include fields influenced by user or external input (for example, project metadata, filenames, or status messages).
The vulnerable behavior occurs when the shell script constructs a Python snippet that embeds the raw payload inside a triple-quoted string, relying on the payload being well-formed and non-malicious.
Exploit preconditions
- Attack surface: The stdin payload consumed by the Claude Code hook and passed through
tools/quota-statusline.shinto an embedded Python fragment. - Required access: Ability to influence or control any field in the hook payload (e.g., via project configuration, file names, generated content, or other processed user input).
- Trigger point: Processing of a payload containing a
'''byte sequence (three single quotes) in a user-controlled field while the vulnerable script is executed. - Why exploitation is possible: The script directly embeds the unescaped payload into a Python triple-quoted string literal. A crafted
'''sequence closes the string early, and the remaining bytes are parsed and executed as Python code within the user's Claude Code process.
Why this happens
The root cause is unsafe construction of executable code by concatenating untrusted data into a Python source fragment, then invoking the Python interpreter on that fragment.
Specifically, the shell script uses a triple-quoted Python string to wrap the hook payload but performs no escaping or validation on the payload content. This enables an attacker-controlled ''' sequence to terminate the string and inject arbitrary Python syntax. This maps to:
- CWE-94: Improper Control of Generation of Code ('Code Injection'), because user-controlled data influences dynamically generated code.
- CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection'), by extension when injected Python code spawns system commands or interacts with the OS.
The insecure pattern is trusting that structured, human-readable data will not contain language delimiters, instead of treating it as untrusted input requiring strict encoding or non-code handling.
Potential impact
- Execution of arbitrary Python code within the user's Claude Code process.
- Reading or modifying local project files accessible to that process.
- Exfiltration of sensitive data (API keys, tokens, configuration files) from the user environment.
- Launching OS-level commands via Python standard library calls (e.g., spawning shells or other processes).
- Persistence within the development environment, such as writing malicious hooks or modifying configuration in the project workspace.
General mitigation guidance
Effective mitigation focuses on breaking the direct link between untrusted payload data and executable code:
- Avoid generating Python (or any language) source code by string concatenation with untrusted input; instead, pass data as data (e.g., via stdin, JSON, environment variables, or arguments).
- If a Python string literal must contain user-controlled content, apply strict escaping/encoding to all string delimiters and special characters before interpolation.
- Prefer structured serialization (JSON, YAML with safe loaders, or other typed formats) and parse the payload as data rather than embedding it in executable code.
- Enforce a clear separation of concerns: keep scripting logic (code) separate from dynamic content (data), and avoid designing scripts that "print code" for another interpreter.
- Run auxiliary tooling with least-privilege and minimal filesystem/system access, so that even if similar issues arise, the blast radius is reduced.
How teams detect issues like this
To detect similar vulnerabilities:
- Static analysis: Define rules to flag:
- Shell scripts or programs that construct interpreter invocations (e.g.,
python -c,node -e) with embedded variables derived from stdin or other untrusted sources. - Use of multi-line string literals or heredocs in combination with unescaped variable substitution that can affect language delimiters.
- Code review signals: Look for patterns where:
- Scripts embed user or environment data directly into code snippets for another interpreter.
- Triple-quoted strings, heredocs, or other string delimiters contain interpolated variables without explicit escaping.
- Policy enforcement: Establish guidelines that:
- Disallow passing arbitrary user input into
python -c,sh -c, or similar command-evaluating interfaces. - Require encoding or structured serialization when cross-language boundaries are involved (e.g., shell → Python).
- Automated review tools (SAST or linters) can be configured to highlight code generation paths, command construction with interpolated variables, and unescaped use of delimiters.

