feat(v3.2.31): Watch-ClaudeLog 起動時セッション検出 + cron-launcher tmux -e 修正 (Issue #185 + #186) - #187
Conversation
…(Issue #185 + #186) - Watch-ClaudeLog.ps1: 起動時に15分以内のログを新規扱いにして即監視開始(待機中のまま残る問題解消) - cron-launcher.sh: tmux new-session -e で env var を明示渡し(サーバーグローバル環境依存バグ解消) - cron-launcher.sh: PROMPT_ARG をサイドカーファイル (.prompt) に書き出し(大容量引数 + 継承問題を回避) - サーバー /home/kensan/.claudeos/cron-launcher.sh に反映済み(12:00 cron 発火から有効) - ClaudeOS v3.2.31 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 0 minutes and 24 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughClaudeOS のバージョンを v3.2.31 に更新し、プロンプト処理の仕組みをシェル変数から外部ファイルベースに変更。Tmux 環境変数の伝播方式を、エクスポート変数から明示的な Changes
Sequence Diagram(s)sequenceDiagram
participant Parent as Parent Script
participant Filesystem as File System
participant Tmux as Tmux Session
participant Wrapper as Wrapper Script
participant Claude as Claude CLI
Parent->>Filesystem: Write START_PROMPT.md to<br/>.prompt file
Parent->>Tmux: new-session -e<br/>_CLAUDEOS_PROMPT_FILE=path<br/>_CLAUDEOS_DURATION_SEC=<br/>_CLAUDEOS_EXIT_FILE=<br/>_CLAUDEOS_TMUX_DONE=
Tmux->>Wrapper: Execute wrapper with env
Wrapper->>Filesystem: Read _CLAUDEOS_PROMPT_FILE
Filesystem-->>Wrapper: Prompt content
Wrapper->>Claude: claude --dangerously-skip-permissions<br/>(with loaded prompt)
Claude-->>Wrapper: Response
Wrapper->>Tmux: wait-for _TMUX_DONE
Parent->>Filesystem: Delete .prompt file<br/>(finalize)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Pull request overview
This PR updates ClaudeOS v3.2.31 tooling to improve (1) Windows-side log watcher behavior when a cron session is already running at startup and (2) Linux cron launcher reliability when invoked from inside an existing tmux server (env inheritance issue), plus a TASKS.md entry update.
Changes:
Watch-ClaudeLog.ps1: Treats a “recent” (≤15 min) cron log as “new” on startup so monitoring begins immediately.cron-launcher.sh: WritesPROMPT_ARGto a sidecar.promptfile and passes required runtime variables into tmux vianew-session -e ...; cleans up the prompt file on exit.TASKS.md: Adds a v3.2.31 DONE entry (and additional blank lines).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| scripts/tools/Watch-ClaudeLog.ps1 | Adds startup logic to immediately detect and follow an already-running cron session log. |
| Claude/templates/linux/cron-launcher.sh | Fixes tmux env inheritance by explicitly passing env vars and moving prompt content to a sidecar file. |
| TASKS.md | Records completion of Issues #185/#186 work (plus whitespace changes). |
| # 起動時に15分以内のログがある場合は実行中と見なして即監視 | ||
| if ($knownLog -match 'cron-(\d{8}-\d{6})\.log$') { | ||
| $logTime = [datetime]::MinValue | ||
| $parsed = [datetime]::TryParseExact($Matches[1], 'yyyyMMdd-HHmmss', $null, |
| tmux new-session -d -s "$TMUX_SESSION" -x 220 -y 50 \ | ||
| -e "_CLAUDEOS_DURATION_SEC=$DURATION_SEC" \ | ||
| -e "_CLAUDEOS_EXIT_FILE=$CLAUDE_EXIT_FILE" \ | ||
| -e "_CLAUDEOS_TMUX_DONE=$_TMUX_DONE" \ | ||
| -e "_CLAUDEOS_PROMPT_FILE=$PROMPT_FILE" \ | ||
| "$CLAUDE_WRAPPER" |
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@Claude/templates/linux/cron-launcher.sh`:
- Around line 153-157: The current code reads the whole prompt into
_prompt_content and passes it as a single argv to claude (variables:
_prompt_file, _prompt_content, the timeout --foreground ... claude invocation),
which still hits system ARG_MAX; change the invocation to stream the prompt via
stdin instead of building _prompt_content: read/verify _prompt_file exists and
is non-empty, then pipe its contents into timeout --foreground
"${_CLAUDEOS_DURATION_SEC}s" claude -p --dangerously-skip-permissions (capture
exit status into claude_exit as before) and remove the direct use of
_prompt_content so large prompt files bypass argv length limits.
In `@scripts/tools/Watch-ClaudeLog.ps1`:
- Around line 185-193: The current 15-minute check compares the parsed timestamp
from the log filename (via $Matches) against the local Get-Date which can be
wrong across timezones; instead retrieve the file's modification time (e.g.,
using Get-Item/Get-ChildItem and LastWriteTimeUtc or LastWriteTime converted to
UTC) and compare epoch/UTC times to Get-Date.ToUniversalTime() so the logic in
the block that inspects $knownLog (the regex match 'cron-(\d{8}-\d{6})\.log$'
and variables $Matches, $logTime, $parsed) becomes timezone-independent: locate
the code that sets $logTime/$parsed and replace the filename-based local-time
comparison with a file-based UTC mtime comparison and keep the original behavior
of clearing $knownLog when the file mtime is within 15 minutes.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: c0cb0ec8-5a87-4896-b09e-beda909f61bd
📒 Files selected for processing (3)
Claude/templates/linux/cron-launcher.shTASKS.mdscripts/tools/Watch-ClaudeLog.ps1
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: Agent
- GitHub Check: test-and-validate
- GitHub Check: PSScriptAnalyzer
🧰 Additional context used
📓 Path-based instructions (1)
{**/.github/workflows/*.{yml,yaml},**/ci.{yml,yaml},**/*.sh,**/.gitlab-ci.yml,.circleci/**/*.yml}
📄 CodeRabbit inference engine (AGENTS.md)
CI failures must always be treated as failures; success faking (e.g.,
|| true) is prohibited
Files:
Claude/templates/linux/cron-launcher.sh
🔇 Additional comments (1)
Claude/templates/linux/cron-launcher.sh (1)
172-177:tmux new-session -eでの明示 env 渡しは良い変更です。tmux サーバーのグローバル環境依存を減らせており、再現性・可搬性の改善に寄与しています。
| _prompt_file="${_CLAUDEOS_PROMPT_FILE:-}" | ||
| if [[ -f "$_prompt_file" ]] && [[ -s "$_prompt_file" ]]; then | ||
| _prompt_content="$(cat "$_prompt_file")" | ||
| timeout --foreground "${_CLAUDEOS_DURATION_SEC}s" claude --dangerously-skip-permissions "$_prompt_content" || claude_exit=$? | ||
| else |
There was a problem hiding this comment.
🧩 Analysis chain
🌐 Web query:
Claude Code CLI の最新公式ドキュメントで、claude --dangerously-skip-permissionsに対してプロンプトを argv ではなく「標準入力」または「ファイル」から渡す方法(例: --prompt-file,@file, stdin)がサポートされているか確認してください。
💡 Result:
Claude Code CLIの最新公式ドキュメント(https://code.claude.com/docs/en/cli-referenceなど)では、claude --dangerously-skip-permissionsに対して、プロンプトをargv(コマンドライン引数)ではなく標準入力(stdin)やファイル(--prompt-file, @fileなど)から渡す専用のオプション(例: --prompt-fileや@file)は明示的にリストされていません。 ただし、-p(printモード、非インタラクティブ)を使用する場合、stdinからの入力がサポートされており、例としてcat file | claude -p "query"が公式ドキュメントで示されています。この場合、--dangerously-skip-permissionsを組み合わせることが可能で、cat prompt.txt | claude -p --dangerously-skip-permissions "追加のクエリ"のようにstdinでプロンプト部分を渡せます。argvの"query"がstdinの内容に置き換わるかは文脈からstdinがコンテキストとして追加される形です。 @fileのようなファイル指定オプションや--prompt-fileはflagsリストに存在せず、サポートされていないと判断されます。システムプロンプト用には--system-prompt-fileがありますが、ユーザープロンプト用ではありません。
Citations:
- 1: https://code.claude.com/docs/en/cli-reference
- 2: https://docs.claude.com/en/docs/claude-code/cli-usage
- 3: https://code.claude.com/docs/en/cli-reference.md
- 4: https://code.claude.com/docs/en/cli-reference?_rsc=1pr9w
- 5: http://code.claude.com/docs/en/cli-reference
- 6: https://docs.claude.com/en/docs/claude-code/cli-reference
- 7: https://www.godofprompt.ai
- 8: https://www.nimbalyst.com
- 9: https://www.tribecode.ai
- 10: https://www.lyfx.ai
大容量プロンプト対策が未完了です(argv へ直接渡すことによる引数長上限の制約が残ります)。
Line 155-157 で .prompt ファイルの内容全体を _prompt_content に読み込み、その後 claude --dangerously-skip-permissions "$_prompt_content" として単一の引数に渡しているため、システムの引数長上限に依存する制約が残ります。
公式ドキュメント確認により、--prompt-file や @file のような専用オプションは現在サポートされていませんが、標準入力(stdin)を経由する方法が利用可能です。以下の形式でプロンプトをファイルから読み込むことで、引数長の制限を回避できます:
cat "$_prompt_file" | timeout --foreground "${_CLAUDEOS_DURATION_SEC}s" claude -p --dangerously-skip-permissions現在の実装を stdin ベースに変更することで、Issue #186 の「大容量引数対策」に対応してください。
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@Claude/templates/linux/cron-launcher.sh` around lines 153 - 157, The current
code reads the whole prompt into _prompt_content and passes it as a single argv
to claude (variables: _prompt_file, _prompt_content, the timeout --foreground
... claude invocation), which still hits system ARG_MAX; change the invocation
to stream the prompt via stdin instead of building _prompt_content: read/verify
_prompt_file exists and is non-empty, then pipe its contents into timeout
--foreground "${_CLAUDEOS_DURATION_SEC}s" claude -p
--dangerously-skip-permissions (capture exit status into claude_exit as before)
and remove the direct use of _prompt_content so large prompt files bypass argv
length limits.
| # 起動時に15分以内のログがある場合は実行中と見なして即監視 | ||
| if ($knownLog -match 'cron-(\d{8}-\d{6})\.log$') { | ||
| $logTime = [datetime]::MinValue | ||
| $parsed = [datetime]::TryParseExact($Matches[1], 'yyyyMMdd-HHmmss', $null, | ||
| [System.Globalization.DateTimeStyles]::None, [ref]$logTime) | ||
| if ($parsed -and ((Get-Date) - $logTime -lt [timespan]::FromMinutes(15))) { | ||
| $knownLog = '' # 新規扱いにして直後のループで検出させる | ||
| } | ||
| } |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
# First, let's examine the PowerShell script to see the actual code at lines 185-193
cat -n scripts/tools/Watch-ClaudeLog.ps1 | sed -n '180,200p'Repository: Kensan196948G/ClaudeCode-StartUpTools-New
Length of output: 873
🏁 Script executed:
# Let's also check the Linux side to see how timestamps are generated
cat -n Claude/templates/linux/cron-launcher.sh | head -60Repository: Kensan196948G/ClaudeCode-StartUpTools-New
Length of output: 2299
🏁 Script executed:
# Look for SSH-related variables and usage patterns in the PowerShell script
rg -n 'SshTarget|SshUser|ssh ' scripts/tools/Watch-ClaudeLog.ps1 | head -40Repository: Kensan196948G/ClaudeCode-StartUpTools-New
Length of output: 454
🏁 Script executed:
# Check the beginning of the file to understand SSH setup
head -100 scripts/tools/Watch-ClaudeLog.ps1 | tail -80Repository: Kensan196948G/ClaudeCode-StartUpTools-New
Length of output: 3218
タイムゾーン差で起動時の「15分以内」判定が誤る可能性があります。
Line 188-190 は監視端末側時刻 (Get-Date) で比較していますが、ログ名タイムスタンプは Linux 側で生成されています(cron-launcher.sh 44行目の date +'%Y%m%d-%H%M%S')。端末とサーバーのタイムゾーンが異なると、起動直後検出の取りこぼし/誤検出が起きます。比較はログのファイルmtimeをepoch秒で取得して行う方が安全です。
🔧 例: タイムゾーン非依存の比較に寄せる差分案
-$knownLog = Get-LatestLog
-# 起動時に15分以内のログがある場合は実行中と見なして即監視
-if ($knownLog -match 'cron-(\d{8}-\d{6})\.log$') {
- $logTime = [datetime]::MinValue
- $parsed = [datetime]::TryParseExact($Matches[1], 'yyyyMMdd-HHmmss', $null,
- [System.Globalization.DateTimeStyles]::None, [ref]$logTime)
- if ($parsed -and ((Get-Date) - $logTime -lt [timespan]::FromMinutes(15))) {
- $knownLog = '' # 新規扱いにして直後のループで検出させる
- }
-}
+$knownLog = Get-LatestLog
+# 起動時に15分以内のログがある場合は実行中と見なして即監視(タイムゾーン非依存)
+if ($knownLog) {
+ $latestEpochRaw = ssh $SshTarget "stat -c %Y '$knownLog' 2>/dev/null" 2>$null
+ if ($latestEpochRaw -match '^\d+$') {
+ $ageSec = [DateTimeOffset]::UtcNow.ToUnixTimeSeconds() - [int64]$latestEpochRaw
+ if ($ageSec -ge 0 -and $ageSec -lt 900) {
+ $knownLog = '' # 新規扱いにして直後のループで検出させる
+ }
+ }
+}🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@scripts/tools/Watch-ClaudeLog.ps1` around lines 185 - 193, The current
15-minute check compares the parsed timestamp from the log filename (via
$Matches) against the local Get-Date which can be wrong across timezones;
instead retrieve the file's modification time (e.g., using
Get-Item/Get-ChildItem and LastWriteTimeUtc or LastWriteTime converted to UTC)
and compare epoch/UTC times to Get-Date.ToUniversalTime() so the logic in the
block that inspects $knownLog (the regex match 'cron-(\d{8}-\d{6})\.log$' and
variables $Matches, $logTime, $parsed) becomes timezone-independent: locate the
code that sets $logTime/$parsed and replace the filename-based local-time
comparison with a file-based UTC mtime comparison and keep the original behavior
of clearing $knownLog when the file mtime is within 15 minutes.
- CHANGELOG に v3.2.31 (Watch-ClaudeLog 起動時検出修正 + tmux -e 修正) を追加 - README バージョンを v3.2.27 → v3.2.31、テスト数を 477 → 569 に更新 - CI check-doc-versions PASSED Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
変更内容
Issue #185: Watch-ClaudeLog.ps1 — 起動時セッション検出漏れ修正
$knownLog = ''にリセットtry/catchの代わりに[datetime]::TryParseExactを使用(PSAvoidUsingEmptyCatchBlock警告を回避)Issue #186: cron-launcher.sh — tmux env var 継承バグ修正
tmux new-session -e KEY=VALUEで env var を明示渡し(tmux サーバーのグローバル環境に依存しない)PROMPT_ARGをサイドカーファイル (.prompt) に書き出し(大容量引数 + tmux 環境サイズ制限を回避)_prompt_contentを読み込むように変更finalize()トラップで.promptファイルも削除/home/kensan/.claudeos/cron-launcher.shに反映済み(12:00 cron 発火から有効)テスト結果
scpで反映済み、構文確認済みServiceHub-Construction-Platformcron 発火で動作を最終確認予定影響範囲
scripts/tools/Watch-ClaudeLog.ps1— 起動時の検出ロジック変更Claude/templates/linux/cron-launcher.sh— tmux 起動方法変更(env var 渡し方式)/home/kensan/.claudeos/cron-launcher.sh) も更新済み残課題
なし
Summary by CodeRabbit
バージョン v3.2.31 リリースノート
バグ修正
改善