Skip to content

Conversation

@aspiers
Copy link
Contributor

@aspiers aspiers commented Jan 3, 2026

Summary

This PR improves permission request messages in opencode to provide users with
clear, actionable information about what they're approving. It also fixes a
security gap where write operations to external directories were not being
checked for permission.


Commit 1: 5b988f9a - feat: improve permission request messages with context-aware formatting

Problem

Permission prompts would show full bash commands; however users couldn't see
which specific commands or files were being requested permission. This made it
a lot harder to understand and manage the impact of configured or per-session
allow lists.

Solution

  • Introduce centralized Permission.formatMessage() function that generates
    context-aware messages based on permission type and metadata.
  • Change <TextBody> to <PermissionBody> and include more comprehensive
    details in each prompt.

Changes by File

File Change
packages/opencode/src/permission/index.ts Added centralized formatMessage() function with type-specific formatting
packages/opencode/src/cli/cmd/run.ts Use formatted messages in CLI permission prompts
packages/opencode/src/cli/cmd/tui/routes/session/permission.tsx Updated TUI permission display with PermissionBody component
packages/opencode/src/acp/agent.ts Use formatted messages for Zed extension
packages/opencode/src/tool/bash.ts Add patterns to metadata for bash commands
packages/opencode/src/tool/read.ts Add filepath to metadata for read operations
packages/opencode/src/tool/skill.ts Add skill name to metadata

Message Example

Before:

$ git log --oneline | grep bug | head -n 20

After:

(assuming grep is already allowed)

• git log --oneline
• head -n 20

Commit 2: eeee56a - feat(write): add external directory permission check

Problem

The write tool had a TODO comment for checking external directory permissions
but the implementation was incomplete. Write operations to paths outside the
working directory would proceed without requesting user permission.

This is a security concern since writes outside the project directory could be
sensitive.

Solution

Implemented the external directory permission check using ctx.ask() with the
external_directory permission type, following the same pattern used in read
and bash tools.

Changes

File Change
packages/opencode/src/tool/write.ts Added external directory permission check with parent directory pattern and metadata

Testing

  • Write to external file in /tmp prompts for permission
  • Read from external file prompts for permission
  • Bash commands show matched patterns with bullet points
  • All permission messages display relevant file paths and metadata

@aspiers aspiers force-pushed the permissions-metadata branch from 4c80a7e to d5a655f Compare January 3, 2026 00:44
@aspiers aspiers marked this pull request as draft January 3, 2026 00:48
@aspiers
Copy link
Contributor Author

aspiers commented Jan 3, 2026

Turns out that it's still displaying all commands, even ones which are already allowed. Working on a fix.

Adam Spiers and others added 2 commits January 3, 2026 01:08
Without this patch, permission prompts showed generic messages like
`Permission required` without providing specific details about what
the user is granting permission for.

This is a problem because users need clear, actionable information to
make informed decisions about permission requests, especially for
security-sensitive operations like bash commands and file access.

This patch solves the problem by introducing a centralized
`Permission.formatPermissionMessage()` function that generates
context-aware messages based on permission type and metadata. The
function provides specific details for each permission type (bash
commands, file operations, web requests, etc.) and includes relevant
paths, patterns, or queries in the message.

Key changes:

- Add `Permission.formatPermissionMessage()` with type-specific formatting
- Update ACP agent to use formatted messages for tool call titles
- Update CLI run command to use formatted permission prompts
- Update TUI permission display with improved UI
- Add metadata to bash, read, skill tools for better messages
Without this patch, the write tool had a TODO comment for checking
external directory permissions but the implementation was incomplete.
This meant that write operations to paths outside the working
directory would proceed without requesting user permission.

This is a problem because write operations outside the project
directory could be security-sensitive, and users should be informed
and able to approve or deny such operations.

This patch solves the problem by implementing the external directory
permission check using `ctx.ask()` with the `external_directory`
permission type, following the same pattern used in other tools like
bash. The check includes the parent directory pattern and provides
appropriate metadata for permission message formatting.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@aspiers aspiers force-pushed the permissions-metadata branch from d5a655f to d6f8783 Compare January 3, 2026 01:08
@aspiers aspiers marked this pull request as ready for review January 3, 2026 01:09
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.

1 participant