Repository navigation
core: tell the model about its scratch directory - #459
Merged
Merged
Conversation
Every session already creates a private SessionTempDir, writable by every tool (write_file/edit/apply_patch and sandboxed shell commands alike) alongside the workspace root. Its path was never surfaced to the model, so throwaway files it created — scratch scripts, notes, intermediate output — had nowhere to go but the project tree. assemble_system_prompt now takes the session's scratch directory and substitutes it into the system prompt, with guidance to prefer it over the workspace for anything that isn't part of the deliverable. SessionTempDir creation is reordered ahead of prompt assembly across all four session-construction paths (fresh, resume, subagent create, subagent resume) so the real path is always available to embed.
mohitranka
added a commit
that referenced
this pull request
Sep 11, 2026
Every session already creates a private SessionTempDir, writable by every tool (write_file/edit/apply_patch and sandboxed shell commands alike) alongside the workspace root. Its path was never surfaced to the model, so throwaway files it created — scratch scripts, notes, intermediate output — had nowhere to go but the project tree. assemble_system_prompt now takes the session's scratch directory and substitutes it into the system prompt, with guidance to prefer it over the workspace for anything that isn't part of the deliverable. SessionTempDir creation is reordered ahead of prompt assembly across all four session-construction paths (fresh, resume, subagent create, subagent resume) so the real path is always available to embed.
mohitranka
added a commit
that referenced
this pull request
Sep 11, 2026
Every session already creates a private SessionTempDir, writable by every tool (write_file/edit/apply_patch and sandboxed shell commands alike) alongside the workspace root. Its path was never surfaced to the model, so throwaway files it created — scratch scripts, notes, intermediate output — had nowhere to go but the project tree. assemble_system_prompt now takes the session's scratch directory and substitutes it into the system prompt, with guidance to prefer it over the workspace for anything that isn't part of the deliverable. SessionTempDir creation is reordered ahead of prompt assembly across all four session-construction paths (fresh, resume, subagent create, subagent resume) so the real path is always available to embed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The model had no designated place for throwaway files (scratch scripts, notes, intermediate output), so it wrote them directly into the workspace, dirtying the project tree.
Forge already creates a private
SessionTempDirper session — writable bywrite_file/edit/apply_patchand by sandboxed shell commands alike (bothresolve_write_pathand the OS sandbox profile already treat it as a second writable root alongside the workspace). It just was never surfaced to the model, and the system prompt actively told the model to "stay inside the workspace" for writes.assemble_system_promptnow takes the session's scratch directory path and substitutes it into a{{SCRATCH_DIR}}placeholder insystem_prompt.md.SessionTempDir::create()is reordered ahead of prompt assembly in all four session-construction paths (fresh session, resume, subagent create, subagent resume) so the real path is always available to embed, and the previous double-creation is removed in favor of reusing one instance.A workspace-local alternative (e.g.
.forge/scratch/) was considered and rejected:.forgeis currently masked entirely read-only in the OS sandbox for spawned shell commands, with no per-subpath carve-out, so making a workspace-local scratch dir usable by shell commands too would require new, more security-sensitive sandbox-profile work for comparatively little benefit over the existing session-temp mechanism.Test plan
cargo fmt --allcargo clippy --all-targets --workspacecargo test --workspace --no-fail-fast— green aside from 3 pre-existing failures unrelated to this change (confirmed one against a cleanHEADsnapshot; the other two are inforge-tools/sandbox_enforcement.rs, a crate untouched by this PR, and fail due to this dev machine missing Xcode CLI tools / a macOS Seatbelt permission quirk)system_prompt_embeds_the_scratch_directory_pathasserting the placeholder is substituted and doesn't leak into the prompt verbatim