aws / aws/amazon-q-developer-cli

Feature Request: Support sharing chat history between instances of `q chat`

Open
#1,207 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
2k
Forks
439
PR merge metrics
No merged PRs in 30d

Description

I often need to change to a different directory (both when running q chat directly and through automations), and I don't want to lose the chat history to guide the Agent's behavior.
OTOH, I also don't want to constantly be telling it "I am now in this directory" and then approving its shell command, and trusting arbitrary shell execution is too reckless for my taste.

Specifically, my use case is using Q as an investigation assistant to analyze large codebases together, and occasionally provide code snippets for me to tweak and insert. The common Agent-guidance trick of storing planning context in the filesystem is fine for independent operation, where the context is a one-and-done production. For pair-deep-diving, you'd have to either use the chat history as your record, or constantly tell Q "update the summary file" and then go check that the summary is sane (using up time and energy, and breaking your mental flow in time-sensitive investigations).
- Another caveat for the "summary file" solution: From past experience w/ both LLMs and Q chat specifically you often need 1-2 iterations per 'concept' for the system to get the right idea. In this case, that means spending time iterating on the summary instead of focusing on the investigation itself.

The agent itself is useful when investigating existing codebases, but with the tool as it currently stands, I've ended up having it re-read the same git repos 4-5 times per session due to closing and reopening the shell, needing updated guidance each time (so it checks the files that were proven relevant since the last restart), as well as some degree of manual monitoring to approve any read-only shell commands it tries.
As I understand from Q's response, it's not architecturally feasible to switch the top-level Q process's directory ergonomically (or to do so via custom scripts sending input to `q chat`). As such, it would be really convenient to re-open `q chat` without needing this boilerplate step.

Q chat history discussing this with the tool:
```

Hi, I'm Amazon Q. Ask me anything.

Things to try
• Fix the build failures in this project.
• List my s3 buckets in us-west-2.
• Write unit tests for my application.
• Help me understand my git status.

/tools View and manage tools and permissions
/issue Report an issue or make a feature request
/profile (Beta) Manage profiles for the chat session
/context (Beta) Manage context files for a profile
/compact Summarize the conversation to free up context space
/help Show the help dialogue
/quit Quit the application

Use Ctrl(^) + j to provide multi-line prompts.

> Do the following:
Tell me what directory I am currently in.
Move to a directory in containing the file.
Tell me what files are in this directory.

⠼ Thinking...I'll help you with these tasks step by step.

First, let me check your current directory:

⠦ Thinking...

[Tool Request - Trusted] Execute shell command
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I will run the following shell command: pwd

Executing `pwd`...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔

🟢 Completed in 0.80s

You are currently in:

Now, let me search for the directory containing the file:

⠹ Thinking...

[Tool Request - Trusted] Execute shell command
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I will run the following shell command:
find ~/workplace -name "" -type f

Executing `find ~/workplace -name "" -type f`...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔

🟢 Completed in 275.865s

I see that the file is actually in your current directory! Let me list the files in this directory:

⠋ Thinking...

[Tool Request - Trusted] Read from filesystem
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Reading directory: with maximum depth of 0

Reading from filesystem...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Reading:

🟢 Completed in 0.6s

To summarize:

1. Your current directory is:
2. The file is already in this directory, so no need to move
3. The directory contains several files, including:
• (last modified on )
• Various other like , , , etc.
• Other like and

> !cd && pwd

> What files can you see in the current directory?

⠙ Thinking...I'll list the files in the current directory for you:

⠇ Thinking...

[Tool Request - Trusted] Read from filesystem
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Reading directory: . with maximum depth of 0

Reading from filesystem...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Reading:

🟢 Completed in 0.46s

In the current directory, I can see the following files:

These appear to be .

> How do I change the directory you are in?

⠸ Thinking...To change the directory I'm working in, you can use the cd command in your instructions. When you want me to change directories, simply include a command like "cd /path/to/directory" or "Change directory to /path/to/
directory" in your request.

For example, you could say:
• "cd ~/Documents and list the files there"
• "Change to the parent directory and show me what's there"
• "Move to and tell me what you see"

When you give me such instructions, I'll use the appropriate tools to change my working directory and then perform any subsequent operations from that new location.

Would you like me to change to a specific directory now?

> change to the parent env.

⠹ Thinking...I'll change to the parent directory.

⠇ Thinking...

[Tool Request] Execute shell command
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I will run the following shell command: cd .. && pwd

Allow this action? Use 't' to trust (always allow) this tool for the session. [y/n/t]:

> y

Executing `cd .. && pwd`...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔

🟢 Completed in 0.15s

⠼ Thinking...

[Tool Request - Trusted] Read from filesystem
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Reading directory: with maximum depth of 0

Reading from filesystem...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Reading: ..

🟢 Completed in 0.63s

I've changed to the parent directory. The current directory is now:

This directory contains:

> How do I manually execute your tools?

⠸ Thinking...I understand you're asking about how to manually execute the tools I use to interact with your system. Let me explain how this works:

When you interact with me, I use several built-in tools to perform actions on your system. These tools aren't directly accessible to you in the same way, but I can explain the underlying commands that accomplish similar tasks
:

1. For reading files and directories (my fs_read tool):
• To read files: cat /path/to/file or less /path/to/file
• To list directories: ls -la /path/to/directory
• To search in files: grep "pattern" /path/to/file

2. For writing to files (my fs_write tool):
• To create/overwrite files: echo "content" > /path/to/file
• To append to files: echo "content" >> /path/to/file
• For more complex edits: Use text editors like nano, vim, or emacs

3. For executing bash commands (my execute_bash tool):
• Simply type the command in your terminal

4. For AWS CLI operations (my use_aws tool):
• Use the AWS CLI directly: aws [service] [operation] [parameters]

If you're asking about how to manually invoke the function calls I use in my responses (the
> I've noticed that when I run the command `!cd ` in the `q chat` interface and then ask you what directory you are in, you remain in the previous directory instead of moving to the new one.
How can I fix this so that running shell commands directly changes the environment you are running in?

⠋ Thinking...You've identified an important limitation with how the q chat interface handles directory changes. Let me explain what's happening and suggest solutions:

## The Issue

When you run !cd in the q chat interface, you're executing a shell command in a temporary subshell. The directory change only affects that subshell and doesn't persist once the command completes. This is why when
you ask me about the current directory afterward, I still report the original location.

This is a common behavior in many shell environments - the cd command changes the directory for the current process only, and child processes (like temporary command executions) don't affect the parent process's working
directory.

## Solutions

Here are a few ways to handle this:

1. Use my commands instead of direct shell commands:
Instead of typing !cd , ask me to change directories with a request like "change directory to " or "cd to ". When I execute commands on your behalf, I track the directory changes.

2. Use a single command with multiple parts:
If you need to run multiple commands in a specific directory, combine them with && like:

!cd /some/path && command1 && command2

3. For Amazon Q CLI specifically:
You could exit the current session with /quit, then restart Amazon Q in the desired directory:

cd /desired/directory
q chat

The most seamless approach is the first option - let me handle directory navigation for you through natural language requests rather than using the ! command prefix for directory changes.

Would you like me to demonstrate how I can help you navigate directories more effectively?

> The reason I need to change directories frequently is because I need to retain the chat history.
I often use `q chat` for investigating complex multi-package codebases with many relevant files. There are many barriers to doing this without some way to preserve chat history between directories:
- Constantly updating and verifying a summary file of the investigation is an extremely inconvenient process, requiring constant monitoring to approve tools and then revising the summary for correctness.
- Asking `q chat` to switch directories via the bash command tool is similarly inconvenient, as I do not want to set arbitrary shell execution as trusted.
- In addition, I often use automations to indirectly call `q chat`, which have little way to confirm the CLI has correctly switched directories.
Do you have suggestions on how I can support this workflow, given that `q chat` doesn't let me directly change its directory in an ergonomic or automate-able fashion?

⠏ Thinking...I understand your challenges with navigating complex multi-package codebases while preserving chat history. This is indeed a limitation with the current q chat implementation. Let me suggest some practical approaches:

## Potential Solutions

### 1. Use a wrapper script

Create a simple shell script that manages directory changes and maintains chat history:

bash
#!/bin/bash
# File: q-nav.sh

# Store chat history in a temporary file
HISTORY_FILE="/tmp/q_chat_history.txt"
touch $HISTORY_FILE

# Change to the requested directory
cd "$1" || exit 1

# Launch q chat with history context
q chat --context "Previous directory: $(pwd)"

# Optionally append new history
# cat /tmp/q_chat_new_history.txt >> $HISTORY_FILE

You could use this as: ./q-nav.sh /path/to/directory

### 2. Use symbolic links for convenience

Create symbolic links to frequently accessed directories in a central location:

bash
mkdir ~/code-links
ln -s /path/to/project1/deep/directory ~/code-links/project1
ln -s /path/to/project2/deep/directory ~/code-links/project2

Then you can quickly navigate with: cd ~/code-links/project1 before starting q chat

### 3. Use a context file approach

Maintain a single context file that you update with relevant information:

bash
# Before switching directories
q chat --export-context /tmp/context.json

# After switching
cd /new/directory
q chat --import-context /tmp/context.json

### 4. Feature request

Since this is a legitimate workflow limitation, consider submitting a feature request for the Amazon Q CLI to support persistent directory changes across commands. You could request:

1. A --working-directory flag for the CLI
2. A command within the chat interface to change directories persistently
3. Support for session persistence across directory changes

## Immediate Workaround

For now, the most practical approach might be to:

1. Create a central directory with symbolic links to all relevant project locations
2. Start q chat from this central directory
3. Use relative paths when referring to files in different projects
4. Use the full context of files when needed: cat /full/path/to/file | q chat

Would any of these approaches work for your specific workflow? I'm happy to help refine a solution that fits your needs better.

> Would the history file be exported automatically from Amazon Q?

⠼ Thinking...No, the history file would not be exported automatically from Amazon Q. In my suggested wrapper script example, I was outlining a conceptual approach rather than something that would work with the current implementation of
Amazon Q CLI.

Currently, Amazon Q CLI doesn't have built-in functionality to:
1. Export chat history to a file automatically
2. Import previous chat history from a file
3. Maintain persistent state between separate invocations

The line in my example script about appending history was more of a placeholder for a feature that doesn't actually exist yet. I should have been clearer about this limitation.

With the current Amazon Q implementation, each time you start a new q chat session (whether in a different directory or not), you're starting with a fresh conversation context. There's no official mechanism to preserve the
conversation state between sessions.

If maintaining conversation context across directory changes is critical for your workflow, you might need to:

1. Manually copy important information between sessions
2. Use a single long-running session and have Amazon Q access files from different directories using absolute paths
3. Consider submitting a feature request for conversation persistence across sessions

I apologize for not being clearer about the limitations of the current implementation in my previous response.
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.