Skip to content

fix: validate completions output before writing; document two-mount requirement#8

Merged
PKramek merged 7 commits intodevelopfrom
fix/completions-validation-and-mount-docs
Apr 7, 2026
Merged

fix: validate completions output before writing; document two-mount requirement#8
PKramek merged 7 commits intodevelopfrom
fix/completions-validation-and-mount-docs

Conversation

@PKramek
Copy link
Copy Markdown
Owner

@PKramek PKramek commented Apr 7, 2026

Closes #7

Bug 1 — Fish (and bash/zsh) completions corrupted at build time

claude completions <shell> runs at image build time when Claude Code is unauthenticated. The CLI exits 0 but writes an error message to stdout (e.g. Not logged in · Please run /login). The previous direct redirect saved that error verbatim into the completions file, causing fish to print parse errors on every shell start.

Fix: capture output into a variable and validate the prefix before writing:

Shell Valid prefix
fish complete
bash _ or #
zsh #compdef

Invalid or empty output is skipped with a warning; no file is written.

Bug 2 — Onboarding re-triggers when only ~/.claude is mounted

Claude Code stores preferences and onboarding state in ~/.claude.json — a sibling of ~/.claude/, not inside it. The previous README guidance mounted only the directory, so ~/.claude.json was never persisted and the onboarding wizard re-ran on every container start.

Fix: update README.md, src/claude-code/README.md, and the mountHostConfig logged snippet to document that two mounts are required and warn that ~/.claude.json must exist on the host before the container starts (Docker creates it as a directory if absent).

Test plan

  • CI passes (ShellCheck, shfmt, all scenario tests)
  • Build a container with fish installed — confirm no parse errors on shell start
  • Build with mountHostConfig: true — confirm logged snippet shows both mounts

…equirement

Fixes #7

**Bug 1 — fish/bash/zsh completions corrupted at build time:**
Capture `claude completions <shell>` output into a variable and validate
the prefix before writing to disk. At build time the CLI is unauthenticated
and may exit 0 while writing an error to stdout; the previous direct redirect
saved that error verbatim into the completions file, causing fish to print
parse errors on every shell start. Validation rules:
- fish:  must start with `complete`
- bash:  must start with `_` or `#`
- zsh:   must start with `#compdef`
Invalid or empty output is skipped with a warning; no file is written.

**Bug 2 — onboarding re-triggers when only ~/.claude is mounted:**
Claude Code stores preferences/onboarding state in ~/.claude.json (a sibling
of ~/.claude/, not inside it). Update README.md, src/claude-code/README.md,
and the mountHostConfig logged snippet to document the two-mount requirement
and warn that ~/.claude.json must exist on the host before the container
starts (Docker creates it as a directory if absent).
@PKramek PKramek self-assigned this Apr 7, 2026
PKramek added 6 commits April 7, 2026 20:30
- Add check_completion_file_contents helper to test.sh (accepts one or
  more valid prefix arguments, reads first line of file)
- Replace coarse FOUND_COMPLETIONS OR-check in default_options.sh with
  per-shell blocks; each shell asserts both existence and content prefix
- Add fish coverage: conditionally install fish via apt-get, re-source
  setup_completions, assert claude.fish starts with 'complete'
- Add log_debug for empty completion output paths in install.sh
- Fix misleading "Shell completions installed." log message

Addresses test gaps identified in code review of fix #7.
Reject completion output whose first line does not start with a
known-valid prefix (_,#,if,function for bash/zsh; complete,# for fish),
so auth error messages like "Not logged in" can no longer be written
into system completion files.
@PKramek PKramek merged commit 23abf35 into develop Apr 7, 2026
31 checks passed
@PKramek PKramek deleted the fix/completions-validation-and-mount-docs branch April 9, 2026 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: fish completions corrupted at build time; onboarding re-triggers when only ~/.claude is mounted

1 participant