Repository navigation
Conversation
#117) `tj onboard --claude-code` writes a `claude()` shell function into ~/.zshrc (and ~/.bashrc) via `_install_claude_wrapper()`, but `tj uninstall` had no counterpart removal path — leaving a `claude()` function that calls `tj` on every launch, which errors once the package is uninstalled. Add `_unwire_claude_wrapper()` (marker-delimited removal, mirroring the install path) and call it from `cmd_uninstall`. Also wire in the existing but never-called `_unwire_claude_output_cap_hook()` so an opted-in PostToolUse cap hook is cleaned up too. Co-Authored-By: Claude <[email protected]>
|
| Filename | Overview |
|---|---|
| tokenjam/cli/cmd_onboard.py | Adds _unwire_claude_wrapper() — counterpart to _install_claude_wrapper() — using the same marker-delimited regex strategy; one minor edge case around trailing \n and a cosmetic blank-line residue after removal. |
| tokenjam/cli/cmd_uninstall.py | Wires _unwire_claude_wrapper() and the previously-uncalled _unwire_claude_output_cap_hook() into the uninstall flow; both are guarded with try/except and conditional writes, correct and safe. |
| tests/unit/test_uninstall_wrapper.py | New test file with good coverage: install-then-remove, bashrc cleanup, idempotency, surrounding-content preservation, and an end-to-end CLI test. All assertions are targeted and meaningful. |
Sequence Diagram
%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
participant U as User shell
participant UNC as cmd_uninstall
participant OB as cmd_onboard
participant FS as ~/.zshrc / ~/.bashrc
participant CS as ~/.claude/settings.json
U->>UNC: tj uninstall --yes
UNC->>CS: read global settings.json
UNC->>OB: _unwire_claude_resume_brief_hook(gs)
OB-->>UNC: hook_removed
UNC->>OB: _unwire_claude_output_cap_hook(gs) [NEW]
OB-->>UNC: cap_removed
UNC->>CS: write updated settings.json (if changed)
UNC->>FS: re.sub(OTEL block) on ~/.zshrc
FS-->>UNC: cleaned
UNC->>OB: _unwire_claude_wrapper() [NEW]
OB->>FS: read ~/.zshrc
OB->>FS: re.sub(_WRAPPER_MARKER.._WRAPPER_END_MARKER) on ~/.zshrc
OB->>FS: re.sub(_WRAPPER_MARKER.._WRAPPER_END_MARKER) on ~/.bashrc (if exists)
OB-->>UNC: list of modified rc files
UNC->>U: print removed paths + success message
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
participant U as User shell
participant UNC as cmd_uninstall
participant OB as cmd_onboard
participant FS as ~/.zshrc / ~/.bashrc
participant CS as ~/.claude/settings.json
U->>UNC: tj uninstall --yes
UNC->>CS: read global settings.json
UNC->>OB: _unwire_claude_resume_brief_hook(gs)
OB-->>UNC: hook_removed
UNC->>OB: _unwire_claude_output_cap_hook(gs) [NEW]
OB-->>UNC: cap_removed
UNC->>CS: write updated settings.json (if changed)
UNC->>FS: re.sub(OTEL block) on ~/.zshrc
FS-->>UNC: cleaned
UNC->>OB: _unwire_claude_wrapper() [NEW]
OB->>FS: read ~/.zshrc
OB->>FS: re.sub(_WRAPPER_MARKER.._WRAPPER_END_MARKER) on ~/.zshrc
OB->>FS: re.sub(_WRAPPER_MARKER.._WRAPPER_END_MARKER) on ~/.bashrc (if exists)
OB-->>UNC: list of modified rc files
UNC->>U: print removed paths + success message
Prompt To Fix All With AI
Fix the following 2 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 2
tokenjam/cli/cmd_onboard.py:2318-2323
The regex requires `
` immediately after `_WRAPPER_END_MARKER`, which is correct for every normal install path. However, if the user's rc file ends on that line without a trailing newline (e.g., a manual edit or a tool that strips final newlines), the pattern silently produces no match — `updated == text`, the file is not written, the function returns `[]`, and no error is raised. Adding `$` as a fallback via `(?:
|$)` handles this edge case without changing normal-path behaviour.
```suggestion
updated = _re.sub(
_re.escape(_WRAPPER_MARKER) + r".*?" + _re.escape(_WRAPPER_END_MARKER) + r"(?:\n|$)",
"",
text,
flags=_re.DOTALL,
)
```
### Issue 2 of 2
tokenjam/cli/cmd_onboard.py:2318-2326
**Blank-line residue after unwire**
`_install_claude_wrapper()` prepends `"\n"` (or `"\n\n"`) before the block for readability. The removal regex starts at `_WRAPPER_MARKER` and doesn't reach that preceding blank line, so after uninstall the rc file is left with an extra blank line where the block used to be. Functionally harmless, but the symmetric fix would be to also match an optional preceding newline, e.g. `r"\n?" + _re.escape(_WRAPPER_MARKER) + …`.
Reviews (1): Last reviewed commit: "fix(uninstall): remove claude() shell wr..." | Re-trigger Greptile
| updated = _re.sub( | ||
| _re.escape(_WRAPPER_MARKER) + r".*?" + _re.escape(_WRAPPER_END_MARKER) + r"\n", | ||
| "", | ||
| text, | ||
| flags=_re.DOTALL, | ||
| ) |
There was a problem hiding this comment.
The regex requires
immediately after _WRAPPER_END_MARKER, which is correct for every normal install path. However, if the user's rc file ends on that line without a trailing newline (e.g., a manual edit or a tool that strips final newlines), the pattern silently produces no match — updated == text, the file is not written, the function returns [], and no error is raised. Adding $ as a fallback via (?: |$) handles this edge case without changing normal-path behaviour.
| updated = _re.sub( | |
| _re.escape(_WRAPPER_MARKER) + r".*?" + _re.escape(_WRAPPER_END_MARKER) + r"\n", | |
| "", | |
| text, | |
| flags=_re.DOTALL, | |
| ) | |
| updated = _re.sub( | |
| _re.escape(_WRAPPER_MARKER) + r".*?" + _re.escape(_WRAPPER_END_MARKER) + r"(?:\n|$)", | |
| "", | |
| text, | |
| flags=_re.DOTALL, | |
| ) |
Prompt To Fix With AI
This is a comment left during a code review.
Path: tokenjam/cli/cmd_onboard.py
Line: 2318-2323
Comment:
The regex requires `
` immediately after `_WRAPPER_END_MARKER`, which is correct for every normal install path. However, if the user's rc file ends on that line without a trailing newline (e.g., a manual edit or a tool that strips final newlines), the pattern silently produces no match — `updated == text`, the file is not written, the function returns `[]`, and no error is raised. Adding `$` as a fallback via `(?:
|$)` handles this edge case without changing normal-path behaviour.
```suggestion
updated = _re.sub(
_re.escape(_WRAPPER_MARKER) + r".*?" + _re.escape(_WRAPPER_END_MARKER) + r"(?:\n|$)",
"",
text,
flags=_re.DOTALL,
)
```
How can I resolve this? If you propose a fix, please make it concise.| updated = _re.sub( | ||
| _re.escape(_WRAPPER_MARKER) + r".*?" + _re.escape(_WRAPPER_END_MARKER) + r"\n", | ||
| "", | ||
| text, | ||
| flags=_re.DOTALL, | ||
| ) | ||
| if updated != text: | ||
| rc.write_text(updated) | ||
| removed.append(str(rc)) |
There was a problem hiding this comment.
Blank-line residue after unwire
_install_claude_wrapper() prepends "\n" (or "\n\n") before the block for readability. The removal regex starts at _WRAPPER_MARKER and doesn't reach that preceding blank line, so after uninstall the rc file is left with an extra blank line where the block used to be. Functionally harmless, but the symmetric fix would be to also match an optional preceding newline, e.g. r"\n?" + _re.escape(_WRAPPER_MARKER) + ….
Prompt To Fix With AI
This is a comment left during a code review.
Path: tokenjam/cli/cmd_onboard.py
Line: 2318-2326
Comment:
**Blank-line residue after unwire**
`_install_claude_wrapper()` prepends `"\n"` (or `"\n\n"`) before the block for readability. The removal regex starts at `_WRAPPER_MARKER` and doesn't reach that preceding blank line, so after uninstall the rc file is left with an extra blank line where the block used to be. Functionally harmless, but the symmetric fix would be to also match an optional preceding newline, e.g. `r"\n?" + _re.escape(_WRAPPER_MARKER) + …`.
How can I resolve this? If you propose a fix, please make it concise.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Summary
tj onboard --claude-codewrites TWO things into~/.zshrc: (1) a# tj harness observabilityOTEL export block, and (2) a# tj per-terminal naming…# end tj per-terminal namingblock defining aclaude()shell function that callstj otel-resource-attrsandtj session-end.tj uninstallremoved block (1) but had NO code path removing block (2) — so aftertj uninstall+pip uninstall tokenjam, the leftoverclaude()function errors (tj: command not found) on everyclaudelaunch._unwire_claude_wrapper()incmd_onboard.py— the counterpart to_install_claude_wrapper(). Removes the# tj per-terminal naming…# end tj per-terminal namingblock from~/.zshrc/~/.bashrcvia exact marker-delimited removal (not a fragile regex on the block body), idempotent, preserves everything else._unwire_claude_wrapper()intocmd_uninstall.py._unwire_claude_output_cap_hook()so an opted-in PostToolUse cap hook is cleaned up on uninstall too.Test plan
tests/unit/test_uninstall_wrapper.py:_unwire_claude_wrapper()removes the block written by_install_claude_wrapper(), cleans.bashrcwhen present, is idempotent/no-op when absent, preserves surrounding rc content, and an end-to-endcmd_uninstallCLI test (fixture~/.zshrcwith both onboard-written blocks + a wired cap-output hook) asserting notjreferences orclaude()function remain after uninstall.python3 -m pytest tests/unit/ -k "uninstall or onboard or wrapper" -q→144 passed, 1498 deselectedpython3 -m pytest tests/unit/ -q→1641 passed, 1 skippedpython3 -m pytest tests/integration/test_cli_uninstall.py tests/integration/test_cli.py -q→85 passedruff checkclean on changed filesMerge order: Part of the CC install/remove cluster — merge #117 → #118 → #121; this is #117 (foundation, merge first).
🤖 Generated with Claude Code